Skip to content

Commit

Permalink
Merge pull request #64 from IDEA-CAMPUS/fix/create-post
Browse files Browse the repository at this point in the history
Fix: create 코드 수정
  • Loading branch information
jisujeong0 authored Jan 8, 2024
2 parents 7dfad00 + dc8a503 commit 2697254
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import java.io.IOException;
import java.net.URI;
import java.util.List;

@Tag(name = "ClubPost API", description = "동아리/학회 관련 API입니다.")
Expand Down Expand Up @@ -72,11 +74,11 @@ public ResponseEntity<?> createClubPost(@CurrentUser UserPrincipal userPrincipal
@Valid @RequestPart ClubPostReq clubPostReq,
@RequestPart("images") List<MultipartFile> images) throws IOException {
Long clubPostId = clubPostService.createClubPost(userPrincipal.getId(), clubPostReq, images);
ApiResponse apiResponse = ApiResponse.builder()
.check(true)
.information(clubPostId)
.build();
return ResponseEntity.ok(apiResponse);
URI location = ServletUriComponentsBuilder.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(clubPostId)
.toUri();
return ResponseEntity.created(location).build();
}

// 글 수정하기
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class IdeaPostService {
private final RedisTemplate<String, String> redisTemplate;

@Transactional
public ResponseEntity<?> resisterIdea(UserPrincipal userPrincipal, ResisterIdeaReq resisterIdeaReq){
public Long resisterIdea(UserPrincipal userPrincipal, ResisterIdeaReq resisterIdeaReq){
User user = userRepository.findById(userPrincipal.getId()).get();
IdeaPost ideapost = IdeaPost.builder()
.title(resisterIdeaReq.getTitle())
Expand All @@ -54,13 +54,7 @@ public ResponseEntity<?> resisterIdea(UserPrincipal userPrincipal, ResisterIdeaR

ideaPostRepository.save(ideapost);

ApiResponse apiResponse = ApiResponse.builder()
.check(true)
.information(ideapost.getId())
.message("아이디어를 만들었어요!")
.build();

return ResponseEntity.ok(apiResponse);
return ideapost.getId();
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import java.net.URI;

@RequiredArgsConstructor
@RestController
Expand All @@ -38,7 +41,13 @@ public class IdeaPostController {
ResponseEntity<?> resisterIdea(@Parameter(description = "Access Token을 입력해주세요.", required = true)
@CurrentUser UserPrincipal userPrincipal,
@Valid @RequestBody ResisterIdeaReq resisterIdeaReq){
return ideaPostService.resisterIdea(userPrincipal, resisterIdeaReq);

Long id = ideaPostService.resisterIdea(userPrincipal, resisterIdeaReq);
URI location = ServletUriComponentsBuilder.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(id)
.toUri();
return ResponseEntity.created(location).build();
}

@Operation(summary = "글 전체 조회", description = "아이디어의 글을 정렬하여 조회한다.")
Expand Down

0 comments on commit 2697254

Please sign in to comment.