Skip to content

Commit

Permalink
feat: 상품 삭제 기능 구현(#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
acceptor-gyu committed Jun 14, 2023
1 parent 12ad1bf commit 8f5fa7e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
10 changes: 7 additions & 3 deletions be/src/main/java/com/secondhand/post/PostController.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ public ResponseEntity<CustomResponse<PostDetailDto>> getPostDetail() {
public ResponseEntity<CustomResponse> updatePost(@PathVariable Long postId, @ModelAttribute PostUpdateDto updatePostDto, @RequestHeader("Authorization") String token) {

LoggedInUser loggedInUser = jwtUtil.extractedUserFromToken(token);
postService.editPost(postId, updatePostDto, loggedInUser);


postService.editPost(postId, updatePostDto, loggedInUser);

return ResponseEntity
.ok()
Expand All @@ -102,7 +101,12 @@ public ResponseEntity<CustomResponse> updatePost(@PathVariable Long postId, @Mod
}

@DeleteMapping("/{postId}")
public ResponseEntity<CustomResponse> deletePost(@PathVariable Long postId) {
public ResponseEntity<CustomResponse> deletePost(@PathVariable Long postId, @RequestHeader("Authorization") String token) {

LoggedInUser loggedInUser = jwtUtil.extractedUserFromToken(token);

postService.deletePost(postId, loggedInUser);

return ResponseEntity
.ok()
.body(new CustomResponse(
Expand Down
9 changes: 8 additions & 1 deletion be/src/main/java/com/secondhand/post/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,19 @@ public void editPost(long postId, PostUpdateDto updatePostDto, LoggedInUser logg

String thumbnail = photoUrls.get(0);

postMeta.update(updatePostDto, thumbnail, region, category);
postMeta.updatePost(updatePostDto, thumbnail, region, category);
postDetail.updateContent(updatePostDto.getContent());
postPhotoRepository.deleteAllByPostMetaId(postId);
savePhotos(photoUrls, postId);
}

@Transactional
public void deletePost(long postId, LoggedInUser loggedInUser) {
PostMeta postMeta = postMetaRepository.findById(postId).orElseThrow();

postMeta.deletePost();
}

private void savePostDetail(PostSaveDto postSaveDto, long createdPostId) {

PostDetail postDetail = new PostDetail(createdPostId, postSaveDto.getContent());
Expand Down
6 changes: 5 additions & 1 deletion be/src/main/java/com/secondhand/post/entity/PostMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ public static PostMeta ofCreated(User seller, Region region, Category category,
.build();
}

public void update(PostUpdateDto updateDto, String photoUrl, Region region, Category category) {
public void updatePost(PostUpdateDto updateDto, String photoUrl, Region region, Category category) {
this.title = updateDto.getTitle();
this.price = updateDto.getPrice();
this.photoUrl = photoUrl;
this.category = category;
this.region = region;
}

public void deletePost() {
this.deleted = true;
}
}

0 comments on commit 8f5fa7e

Please sign in to comment.