Skip to content

Commit

Permalink
feat : comment ์‚ญ์ œ
Browse files Browse the repository at this point in the history
  • Loading branch information
moonyaeyoon committed Jul 26, 2024
1 parent af207a5 commit e137628
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import meltingpot.server.comment.dto.CommentsListResponse;
import meltingpot.server.comment.service.CommentService;
import meltingpot.server.domain.entity.Account;
import meltingpot.server.domain.entity.comment.Comment;
import meltingpot.server.util.CurrentUser;
import meltingpot.server.util.ResponseCode;
import meltingpot.server.util.ResponseData;
Expand Down Expand Up @@ -57,7 +56,7 @@ public ResponseEntity<ResponseData<CommentsListResponse>> getCommentsList (@Curr
@RequestParam(required = false) Long cursor,
@RequestParam(defaultValue = "10") int pageSize){
try{
return ResponseData.toResponseEntity(ResponseCode.READ_COMMENTS_LIST_SUCCESS, commentService.getCommentsList(account,postId,cursor,pageSize));
return ResponseData.toResponseEntity(ResponseCode.READ_COMMENTS_LIST_SUCCESS, commentService.getCommentsList(postId,cursor,pageSize));
}catch (NoSuchElementException e) {
return ResponseData.toResponseEntity(ResponseCode.READ_COMMENT_FAIL, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.server.ResponseStatusException;
import java.util.*;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -133,7 +133,7 @@ public ResponseCode updateComment(CommentCreateRequest updateCommentDTO, Account
// }
/* ๋Œ“๊ธ€ ๋ชฉ๋ก ๋ถˆ๋Ÿฌ์˜ค๊ธฐ */
@Transactional(readOnly = true)
public CommentsListResponse getCommentsList(Account account, Long postId, Long cursor, int pageSize) {
public CommentsListResponse getCommentsList(Long postId, Long cursor, int pageSize) {
Post post = findPostById(postId);
List<CommentsListResponse.CommentDetail> commentDetailDTOs = new ArrayList<>();
int count = 0;
Expand Down Expand Up @@ -196,6 +196,28 @@ public CommentsListResponse getCommentsList(Account account, Long postId, Long c

/* ๋Œ“๊ธ€ ์‚ญ์ œํ•˜๊ธฐ */

public ResponseCode deleteComment(Long commentId, Account account) {
Comment comment = findCommentById(commentId);

if (!comment.getAccount().getId().equals(account.getId())) {
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "์‚ญ์ œ๋œ ๋Œ“๊ธ€์ž…๋‹ˆ๋‹ค.");
}
if (comment.getParent() == null) {
comment.setContent("์‚ญ์ œ๋œ ๋Œ“๊ธ€์ž…๋‹ˆ๋‹ค.");
comment.setAccount(null);
comment.setIsAnonymous(true);

if (comment.getCommentImage() != null) {
comment.setCommentImage(null); // ๊ด€๊ณ„ ์ œ๊ฑฐ
commentImageRepository.delete(comment.getCommentImage()); // ์ด๋ฏธ์ง€ ์—”ํ‹ฐํ‹ฐ ์‚ญ์ œ
}

} else {
commentRepository.delete(comment);
}
return ResponseCode.COMMENT_DELETE_SUCCESS;
}


private Comment findCommentById(Long commentId) {
return commentRepository.findById(commentId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public void setContent(String content) {
this.content = content;
}

public void setIsAnonymous (Boolean isAnonymous) {
this.isAnonymous = isAnonymous;
}

public Comment getParent() { return parent;}


Expand Down
1 change: 1 addition & 0 deletions src/main/java/meltingpot/server/util/ResponseCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public enum ResponseCode {
UPDATE_POST_SUCCESS(OK,"๊ฒŒ์‹œ๋ฌผ ์ˆ˜์ • ์„ฑ๊ณต"),
UPDATE_COMMENT_SUCCESS(OK, "๋Œ“๊ธ€ ์ˆ˜์ • ์„ฑ๊ณต"),
READ_COMMENTS_LIST_SUCCESS(OK,"๋Œ“๊ธ€ ๋ชฉ๋ก ๋ถˆ๋Ÿฌ์˜ค๊ธฐ ์„ฑ๊ณต"),
COMMENT_DELETE_SUCCESS(OK, "๋Œ“๊ธ€ ์‚ญ์ œํ•˜๊ธฐ ์„ฑ๊ณต"),



Expand Down

0 comments on commit e137628

Please sign in to comment.