Skip to content

Commit

Permalink
refactor: comment @Setter 제거, 댓글 수정 로직 래팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
haroya01 committed Sep 29, 2023
1 parent b7a30e7 commit a67e3d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import megabrain.gyeongnamgyeongmae.global.BaseTimeEntity;

@Getter
@Setter
@Entity
@Table(name = "comment")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down Expand Up @@ -86,4 +85,12 @@ public void setParent(Comment parent) {
this.parent = parent;
}

public void setContent(String content) {
this.content = content;
}

public void deleteComment() {
this.removed = true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ private Comment findCommentById(Long id) {
@Transactional(readOnly = true)
public List<AuctionItemCommentParentDto> findAuctionItemCommentById(Long id) {
auctionItemService.findAuctionItemById(id);
List<Comment> commentEntityList = auctionItemCommentRepository.findByAuctionItemCommentByAuctionId(id);
List<Comment> commentEntityList =
auctionItemCommentRepository.findByAuctionItemCommentByAuctionId(id);
return commentEntityList.stream()
.map(AuctionItemCommentParentDto::of)
.collect(Collectors.toList());
Expand All @@ -71,20 +72,10 @@ public List<AuctionItemCommentParentDto> findAuctionItemCommentById(Long id) {
@Transactional
public void updateAuctionItemComment(
AuctionItemCommentUpdateRequest auctionItemCommentUpdateRequest) {
Comment comment =
(Comment)
this.auctionItemCommentRepository
.findById(auctionItemCommentUpdateRequest.getCommentId())
.orElseThrow(
() -> {
return new RuntimeException("댓글을 찾을수 없습니다");
});
if (!Objects.equals(comment.getUser().getId(), auctionItemCommentUpdateRequest.getUserId())) {
throw new RuntimeException("댓글 작성자가 아닙니다");
} else {
comment.setContent(auctionItemCommentUpdateRequest.getContent());
this.auctionItemCommentRepository.save(comment);
}
Comment comment = findCommentById(auctionItemCommentUpdateRequest.getCommentId());
userService.findUserById(auctionItemCommentUpdateRequest.getUserId());
comment.setContent(auctionItemCommentUpdateRequest.getContent());
auctionItemCommentRepository.save(comment);
}

@Transactional
Expand All @@ -101,7 +92,7 @@ public void deleteAuctionItemComment(
if (!Objects.equals(comment.getUser().getId(), auctionItemCommentDeleteRequest.getUserId())) {
throw new RuntimeException("댓글 작성자가 아닙니다");
} else {
comment.setRemoved(true);
comment.deleteComment();
this.auctionItemCommentRepository.save(comment);
}
}
Expand Down

0 comments on commit a67e3d6

Please sign in to comment.