diff --git a/be/src/main/java/com/secondhand/post/PostController.java b/be/src/main/java/com/secondhand/post/PostController.java index 2a15dc029..39d5cf86d 100644 --- a/be/src/main/java/com/secondhand/post/PostController.java +++ b/be/src/main/java/com/secondhand/post/PostController.java @@ -126,7 +126,12 @@ public ResponseEntity changeInterestPost(@PathVariable Long post } @PatchMapping("/{postId}") - public ResponseEntity changePostStatus(@PathVariable Long postId, @RequestBody UpdatePostStatusDto statusDto) { + public ResponseEntity changePostStatus(@PathVariable Long postId, @RequestBody UpdatePostStateDto stateDto, @RequestHeader("Authorization") String token) { + + LoggedInUser loggedInUser = jwtUtil.extractedUserFromToken(token); + + postService.updateBadge(postId, stateDto, loggedInUser); + return ResponseEntity .ok() .body(new CustomResponse( diff --git a/be/src/main/java/com/secondhand/post/PostService.java b/be/src/main/java/com/secondhand/post/PostService.java index c281305f2..d7ff20ca6 100644 --- a/be/src/main/java/com/secondhand/post/PostService.java +++ b/be/src/main/java/com/secondhand/post/PostService.java @@ -25,6 +25,8 @@ @RequiredArgsConstructor public class PostService { + // TODO: 로그인한 유저가 상품을 수정하는지 예외처리 로직 추가 + private final UserRepository userRepository; private final PostMetaRepository postMetaRepository; private final PostDetailRepository postDetailRepository; @@ -98,6 +100,14 @@ public void deletePost(long postId, LoggedInUser loggedInUser) { postMeta.deletePost(); } + @Transactional + public void updateBadge(long postId, UpdatePostStateDto postStateDto, LoggedInUser loggedInUser) { + PostMeta postMeta = postMetaRepository.findById(postId).orElseThrow(); + Badge badge = badgeRepository.findById(postStateDto.getState()).orElseThrow(); + + postMeta.updateBadge(badge); + } + private void savePostDetail(PostSaveDto postSaveDto, long createdPostId) { PostDetail postDetail = new PostDetail(createdPostId, postSaveDto.getContent()); diff --git a/be/src/main/java/com/secondhand/post/dto/UpdatePostStatusDto.java b/be/src/main/java/com/secondhand/post/dto/UpdatePostStateDto.java similarity index 51% rename from be/src/main/java/com/secondhand/post/dto/UpdatePostStatusDto.java rename to be/src/main/java/com/secondhand/post/dto/UpdatePostStateDto.java index e98b8bae0..e5506718b 100644 --- a/be/src/main/java/com/secondhand/post/dto/UpdatePostStatusDto.java +++ b/be/src/main/java/com/secondhand/post/dto/UpdatePostStateDto.java @@ -3,6 +3,6 @@ import lombok.Getter; @Getter -public class UpdatePostStatusDto { - private String status; +public class UpdatePostStateDto { + private int state; } diff --git a/be/src/main/java/com/secondhand/post/entity/PostMeta.java b/be/src/main/java/com/secondhand/post/entity/PostMeta.java index cd3336a85..363b50c44 100644 --- a/be/src/main/java/com/secondhand/post/entity/PostMeta.java +++ b/be/src/main/java/com/secondhand/post/entity/PostMeta.java @@ -73,4 +73,8 @@ public void updatePost(PostUpdateDto updateDto, String photoUrl, Region region, public void deletePost() { this.deleted = true; } + + public void updateBadge(Badge badge) { + this.badge = badge; + } }