Skip to content

Commit

Permalink
Merge pull request #68 from second-hand-team06/be-feat/#35-edit-post-…
Browse files Browse the repository at this point in the history
…state

[BE] feat: 상품 상태 수정 기능 구현(#35)
  • Loading branch information
acceptor-gyu authored Jun 14, 2023
2 parents b9e5ab6 + f8be696 commit 8c491ad
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
7 changes: 6 additions & 1 deletion be/src/main/java/com/secondhand/post/PostController.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ public ResponseEntity<CustomResponse> changeInterestPost(@PathVariable Long post
}

@PatchMapping("/{postId}")
public ResponseEntity<CustomResponse> changePostStatus(@PathVariable Long postId, @RequestBody UpdatePostStatusDto statusDto) {
public ResponseEntity<CustomResponse> 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(
Expand Down
10 changes: 10 additions & 0 deletions be/src/main/java/com/secondhand/post/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
@RequiredArgsConstructor
public class PostService {

// TODO: 로그인한 유저가 상품을 수정하는지 예외처리 로직 추가

private final UserRepository userRepository;
private final PostMetaRepository postMetaRepository;
private final PostDetailRepository postDetailRepository;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import lombok.Getter;

@Getter
public class UpdatePostStatusDto {
private String status;
public class UpdatePostStateDto {
private int state;
}
4 changes: 4 additions & 0 deletions be/src/main/java/com/secondhand/post/entity/PostMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 8c491ad

Please sign in to comment.