diff --git a/src/main/java/com/example/prdoit/controller/CommentController.java b/src/main/java/com/example/prdoit/controller/CommentController.java index 66547e3..dc2ff38 100644 --- a/src/main/java/com/example/prdoit/controller/CommentController.java +++ b/src/main/java/com/example/prdoit/controller/CommentController.java @@ -1,51 +1,143 @@ package com.example.prdoit.controller; import com.example.prdoit.dto.comment.*; +import com.example.prdoit.exception.CustomException; import com.example.prdoit.service.comment.CommentService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.parameters.P; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController @RequiredArgsConstructor -@RequestMapping("/api/comments") +@RequestMapping("/comments") +@CrossOrigin(origins = "*", allowedHeaders = "*") public class CommentController { private final CommentService commentService; // 1. 댓글 조회 @GetMapping("/content/{contentId}") - public ResponseEntity> getComments(@PathVariable String contentId) { - return ResponseEntity.ok(commentService.getCommentList(contentId)); + public ResponseEntity getComments(@PathVariable String contentId) { + try { + return ResponseEntity.ok(commentService.getCommentList(contentId)); + } catch (CustomException e){ + return ResponseEntity.badRequest().body("댓글 조회에 실패했습니다."); + } catch (Exception e) { + return ResponseEntity.internalServerError().body("댓글 조회에 실패했습니다."); + } } // 2. 댓글 작성 @PostMapping() - public ResponseEntity createComment(@RequestBody CommentRequestDto commentRequestDto) { - commentService.postComment(commentRequestDto); - return ResponseEntity.ok("댓글이 성공적으로 작성되었습니다!"); + public ResponseEntity createComment(@RequestBody CommentRequestDto commentRequestDto) { + try { + commentService.postComment(commentRequestDto); + return ResponseEntity.ok("댓글이 성공적으로 작성되었습니다!"); + } catch (CustomException e) { + return ResponseEntity.badRequest().body("댓글 작성에 실패했습니다."); + } catch (Exception e) { + return ResponseEntity.internalServerError().body("댓글 작성에 실패했습니다."); + } } // 3. 대댓글 작성 @PostMapping("/reply") - public ResponseEntity createReply(@RequestBody CommentReplyRequestDto commentReplyRequestDto) { - commentService.postCommentReply(commentReplyRequestDto); - return ResponseEntity.ok("대댓글이 성공적으로 작성되었습니다!"); + public ResponseEntity createReply(@RequestBody CommentReplyRequestDto commentReplyRequestDto) { + try { + commentService.postCommentReply(commentReplyRequestDto); + return ResponseEntity.ok("대댓글이 성공적으로 작성되었습니다!"); + } catch (CustomException e) { + return ResponseEntity.badRequest().body("대댓글 작성에 실패했습니다."); + } catch (Exception e) { + return ResponseEntity.internalServerError().body("대댓글 작성에 실패했습니다."); + } } // 4. 댓글 수정 @PatchMapping public ResponseEntity updateComment(@RequestBody CommentPatchDto commentPatchDto) { - commentService.patchComment(commentPatchDto); - return ResponseEntity.ok("댓글이 성공적으로 수정되었습니다!"); + try { + commentService.patchComment(commentPatchDto); + return ResponseEntity.ok("댓글이 성공적으로 수정되었습니다!"); + } catch (CustomException e) { + return ResponseEntity.badRequest().body("댓글 수정에 실패했습니다."); + } catch (Exception e) { + return ResponseEntity.internalServerError().body("댓글 수정에 실패했습니다."); + } } // 5.대댓글 수정 @PatchMapping("/reply") public ResponseEntity updateReply(@RequestBody CommentReplyPatchDto commentReplyPatchDto) { - commentService.patchCommentReply(commentReplyPatchDto); - return ResponseEntity.ok("대댓글이 성공적으로 수정되었습니다!"); + try { + commentService.patchCommentReply(commentReplyPatchDto); + return ResponseEntity.ok("대댓글이 성공적으로 수정되었습니다!"); + } catch (CustomException e) { + return ResponseEntity.badRequest().body("대댓글 수정에 실패했습니다."); + } catch (Exception e) { + return ResponseEntity.internalServerError().body("대댓글 수정에 실패했습니다."); + } + } + + @GetMapping("/community/{communityId}") + public ResponseEntity getCommunityComments(@PathVariable String communityId) { + try { + return ResponseEntity.ok(commentService.getCommunityCommentList(communityId)); + } catch (CustomException e){ + return ResponseEntity.badRequest().body("댓글 조회에 실패했습니다."); + } catch (Exception e) { + return ResponseEntity.internalServerError().body("댓글 조회에 실패했습니다."); + } + } + + @PostMapping("/community") + public ResponseEntity createCommunityComment(@RequestBody CommunityCommentPostDto communityCommentPostDto) { + try { + commentService.postCommunityComment(communityCommentPostDto); + return ResponseEntity.ok("댓글이 성공적으로 작성되었습니다!"); + } catch (CustomException e) { + return ResponseEntity.badRequest().body("댓글 작성에 실패했습니다."); + } catch (Exception e) { + return ResponseEntity.internalServerError().body("댓글 작성에 실패했습니다."); + } + } + + @PostMapping("/community/reply") + public ResponseEntity createCommunityReply(@RequestBody CommunityCommentReplyPostDto communityCommentReplyPostDto) { + try { + commentService.postCommunityCommentReply(communityCommentReplyPostDto); + return ResponseEntity.ok("대댓글이 성공적으로 작성되었습니다!"); + } catch (CustomException e) { + return ResponseEntity.badRequest().body("대댓글 작성에 실패했습니다."); + } catch (Exception e) { + return ResponseEntity.internalServerError().body("대댓글 작성에 실패했습니다."); + } + } + + @PatchMapping("/community") + public ResponseEntity updateCommunityComment(@RequestBody CommunityCommentPatchDto communityCommentPatchDto) { + try { + commentService.patchCommunityComment(communityCommentPatchDto); + return ResponseEntity.ok("댓글이 성공적으로 수정되었습니다!"); + } catch (CustomException e) { + return ResponseEntity.badRequest().body("댓글 수정에 실패했습니다."); + } catch (Exception e) { + return ResponseEntity.internalServerError().body("댓글 수정에 실패했습니다."); + } + } + + @PatchMapping("/community/reply") + public ResponseEntity updateCommunityReply(@RequestBody CommunityCommentReplyPatchDto communityCommentReplyPatchDto) { + try { + commentService.patchCommunityCommentReply(communityCommentReplyPatchDto); + return ResponseEntity.ok("대댓글이 성공적으로 수정되었습니다!"); + } catch (CustomException e) { + return ResponseEntity.badRequest().body("대댓글 수정에 실패했습니다."); + } catch (Exception e) { + return ResponseEntity.internalServerError().body("대댓글 수정에 실패했습니다."); + } } } diff --git a/src/main/java/com/example/prdoit/controller/ContentController.java b/src/main/java/com/example/prdoit/controller/ContentController.java index 140fa45..53e0e0a 100644 --- a/src/main/java/com/example/prdoit/controller/ContentController.java +++ b/src/main/java/com/example/prdoit/controller/ContentController.java @@ -97,4 +97,18 @@ public ResponseEntity getTotalContent(@PathVariable String userId, } } + @PostMapping("/like/{contentId}") + public ResponseEntity likeContent(@PathVariable String contentId) { + try { + contentService.likeContent(contentId); + return ResponseEntity.ok("좋아요 성공"); + } catch (CustomException e) { + log.error("[likeContent] 좋아요 실패", e); + return ResponseEntity.badRequest().body(e.getMessage()); + } catch (Exception e) { + log.error("[likeContent] 좋아요 실패", e); + return ResponseEntity.internalServerError().body("좋아요에 실패했습니다."); + } + } + } diff --git a/src/main/java/com/example/prdoit/controller/UserController.java b/src/main/java/com/example/prdoit/controller/UserController.java index ecbf8f2..95d43b1 100644 --- a/src/main/java/com/example/prdoit/controller/UserController.java +++ b/src/main/java/com/example/prdoit/controller/UserController.java @@ -155,4 +155,15 @@ public ResponseEntity getNotificationList(@PathVariable String userId) { } } + @GetMapping("/Information/{userId}") + public ResponseEntity getInformation(@PathVariable String userId) { + log.info("[getInformation] 회원 정보 조회 시작 - User ID: {}", userId); + + try { + return ResponseEntity.ok(userService.getInformation(userId)); + } catch (CustomException e) { + log.error("[getInformation] 회원 정보 조회 실패 - 이유: {}", e.getMessage()); + return ResponseEntity.badRequest().body(e.getMessage()); + } + } } diff --git a/src/main/java/com/example/prdoit/dto/comment/CommentReplyRequestDto.java b/src/main/java/com/example/prdoit/dto/comment/CommentReplyRequestDto.java index 53e4532..036fa8b 100644 --- a/src/main/java/com/example/prdoit/dto/comment/CommentReplyRequestDto.java +++ b/src/main/java/com/example/prdoit/dto/comment/CommentReplyRequestDto.java @@ -13,6 +13,6 @@ public class CommentReplyRequestDto { private int commentId; // 대댓글이 달릴 원본 댓글 ID private String commentReplyContent; // 대댓글 내용 - private String commentReplyNickname; // 대댓글 작성자 닉네임 + private String userId; private LocalDateTime commentReplyDate; // 대댓글 작성 날짜 } diff --git a/src/main/java/com/example/prdoit/dto/comment/CommentReplyResponseDto.java b/src/main/java/com/example/prdoit/dto/comment/CommentReplyResponseDto.java index ff2649d..70e3f9f 100644 --- a/src/main/java/com/example/prdoit/dto/comment/CommentReplyResponseDto.java +++ b/src/main/java/com/example/prdoit/dto/comment/CommentReplyResponseDto.java @@ -15,4 +15,5 @@ public class CommentReplyResponseDto { private String commentReplyContent; // 대댓글 내용 private String commentReplyNickname; // 작성자 닉네임 private LocalDateTime commentReplyDate; // 대댓글 작성 날짜 + private String userId; } diff --git a/src/main/java/com/example/prdoit/dto/comment/CommentRequestDto.java b/src/main/java/com/example/prdoit/dto/comment/CommentRequestDto.java index f74a319..ccf8c85 100644 --- a/src/main/java/com/example/prdoit/dto/comment/CommentRequestDto.java +++ b/src/main/java/com/example/prdoit/dto/comment/CommentRequestDto.java @@ -13,6 +13,6 @@ public class CommentRequestDto { private String contentId; // 댓글 달릴 게시글 ID private String commentContent; // 댓글 내용 - private String commentNickname; // 댓글 작성자 닉네임 + private String userId; // 댓글 작성자 닉네임 private LocalDateTime commentDate; // 댓글 작성 날짜 } diff --git a/src/main/java/com/example/prdoit/dto/comment/CommentResponseDto.java b/src/main/java/com/example/prdoit/dto/comment/CommentResponseDto.java index 8068c06..5367fa8 100644 --- a/src/main/java/com/example/prdoit/dto/comment/CommentResponseDto.java +++ b/src/main/java/com/example/prdoit/dto/comment/CommentResponseDto.java @@ -16,5 +16,6 @@ public class CommentResponseDto { private String commentContent; // 댓글 내용 private String commentNickname; // 작성자 닉네임 private LocalDateTime commentDate; // 댓글 작성 날짜 - private List commentReplyResponseDtoList; // 대댓글 리스트 + private List commentReplyResponseDtoList; + private String userId;// 대댓글 리스트 } diff --git a/src/main/java/com/example/prdoit/dto/comment/CommunityCommentPatchDto.java b/src/main/java/com/example/prdoit/dto/comment/CommunityCommentPatchDto.java new file mode 100644 index 0000000..9b12fa0 --- /dev/null +++ b/src/main/java/com/example/prdoit/dto/comment/CommunityCommentPatchDto.java @@ -0,0 +1,18 @@ +package com.example.prdoit.dto.comment; + +import lombok.*; + +import java.time.LocalDateTime; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class CommunityCommentPatchDto { + + private int commentId; + private String commentContent; + private LocalDateTime commentDate; + +} diff --git a/src/main/java/com/example/prdoit/dto/comment/CommunityCommentPostDto.java b/src/main/java/com/example/prdoit/dto/comment/CommunityCommentPostDto.java new file mode 100644 index 0000000..ac8dba0 --- /dev/null +++ b/src/main/java/com/example/prdoit/dto/comment/CommunityCommentPostDto.java @@ -0,0 +1,19 @@ +package com.example.prdoit.dto.comment; + +import lombok.*; + +import java.time.LocalDateTime; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class CommunityCommentPostDto { + + private String communityId; + private String commentContent; + private String userId; + private LocalDateTime commentDate; + +} diff --git a/src/main/java/com/example/prdoit/dto/comment/CommunityCommentReplyPatchDto.java b/src/main/java/com/example/prdoit/dto/comment/CommunityCommentReplyPatchDto.java new file mode 100644 index 0000000..195880c --- /dev/null +++ b/src/main/java/com/example/prdoit/dto/comment/CommunityCommentReplyPatchDto.java @@ -0,0 +1,17 @@ +package com.example.prdoit.dto.comment; + +import lombok.*; + +import java.time.LocalDateTime; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class CommunityCommentReplyPatchDto { + + private int commentReplyId; + private String commentReplyContent; + private LocalDateTime commentReplyDate; +} diff --git a/src/main/java/com/example/prdoit/dto/comment/CommunityCommentReplyPostDto.java b/src/main/java/com/example/prdoit/dto/comment/CommunityCommentReplyPostDto.java new file mode 100644 index 0000000..8b2b628 --- /dev/null +++ b/src/main/java/com/example/prdoit/dto/comment/CommunityCommentReplyPostDto.java @@ -0,0 +1,19 @@ +package com.example.prdoit.dto.comment; + +import lombok.*; + +import java.time.LocalDateTime; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class CommunityCommentReplyPostDto { + + private int commentId; + private String commentReplyContent; + private String userId; + private LocalDateTime commentReplyDate; + +} diff --git a/src/main/java/com/example/prdoit/dto/comment/CommunityCommentReplyResponseDto.java b/src/main/java/com/example/prdoit/dto/comment/CommunityCommentReplyResponseDto.java new file mode 100644 index 0000000..665bb65 --- /dev/null +++ b/src/main/java/com/example/prdoit/dto/comment/CommunityCommentReplyResponseDto.java @@ -0,0 +1,20 @@ +package com.example.prdoit.dto.comment; + + +import lombok.*; + +import java.time.LocalDateTime; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class CommunityCommentReplyResponseDto { + + private int commentReplyId; + private String commentReplyContent; + private String commentReplyNickname; + private String userId; + private LocalDateTime commentReplyDate; +} diff --git a/src/main/java/com/example/prdoit/dto/comment/CommunityCommentResponseDto.java b/src/main/java/com/example/prdoit/dto/comment/CommunityCommentResponseDto.java new file mode 100644 index 0000000..387d70d --- /dev/null +++ b/src/main/java/com/example/prdoit/dto/comment/CommunityCommentResponseDto.java @@ -0,0 +1,22 @@ +package com.example.prdoit.dto.comment; + +import lombok.*; + +import java.time.LocalDateTime; +import java.util.List; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class CommunityCommentResponseDto { + + private int commentId; + private String commentContent; + private String userId; + private String commentNickname; + private LocalDateTime commentDate; + private List communityCommentReplyResponseDtoList; + +} diff --git a/src/main/java/com/example/prdoit/dto/notification/NotificationResponseDto.java b/src/main/java/com/example/prdoit/dto/notification/NotificationResponseDto.java index f4ac2db..d335d13 100644 --- a/src/main/java/com/example/prdoit/dto/notification/NotificationResponseDto.java +++ b/src/main/java/com/example/prdoit/dto/notification/NotificationResponseDto.java @@ -14,4 +14,5 @@ public class NotificationResponseDto { private String userId; private int isRead; private int isContent; + private String contentTitle; } diff --git a/src/main/java/com/example/prdoit/dto/user/InformationDto.java b/src/main/java/com/example/prdoit/dto/user/InformationDto.java new file mode 100644 index 0000000..a9f9903 --- /dev/null +++ b/src/main/java/com/example/prdoit/dto/user/InformationDto.java @@ -0,0 +1,16 @@ +package com.example.prdoit.dto.user; + +import lombok.*; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class InformationDto { + + private String id; + private String name; + private String email; + private String nickname; +} diff --git a/src/main/java/com/example/prdoit/model/NotificationTable.java b/src/main/java/com/example/prdoit/model/NotificationTable.java index f2e9eb3..70bb10e 100644 --- a/src/main/java/com/example/prdoit/model/NotificationTable.java +++ b/src/main/java/com/example/prdoit/model/NotificationTable.java @@ -25,6 +25,8 @@ public class NotificationTable { private int isContent; + private String contentTitle; + @ManyToOne @JoinColumn(name = "userId") private IdTable userId; diff --git a/src/main/java/com/example/prdoit/service/comment/CommentService.java b/src/main/java/com/example/prdoit/service/comment/CommentService.java index ab6a0ef..35baba1 100644 --- a/src/main/java/com/example/prdoit/service/comment/CommentService.java +++ b/src/main/java/com/example/prdoit/service/comment/CommentService.java @@ -15,4 +15,15 @@ public interface CommentService { void patchComment(CommentPatchDto commentPatchDto); void patchCommentReply(CommentReplyPatchDto commentReplyPatchDto); + + List getCommunityCommentList(String communityId); + + void postCommunityComment(CommunityCommentPostDto communityCommentPostDto); + + void postCommunityCommentReply(CommunityCommentReplyPostDto communityCommentReplyPostDto); + + void patchCommunityComment(CommunityCommentPatchDto communityCommentPatchDto); + + void patchCommunityCommentReply(CommunityCommentReplyPatchDto communityCommentReplyPatchDto); + } diff --git a/src/main/java/com/example/prdoit/service/comment/CommentServiceImpl.java b/src/main/java/com/example/prdoit/service/comment/CommentServiceImpl.java index 87f5b5e..c4cd184 100644 --- a/src/main/java/com/example/prdoit/service/comment/CommentServiceImpl.java +++ b/src/main/java/com/example/prdoit/service/comment/CommentServiceImpl.java @@ -2,10 +2,7 @@ import com.example.prdoit.dto.comment.*; import com.example.prdoit.exception.CustomException; -import com.example.prdoit.model.CommentCommentTable; -import com.example.prdoit.model.CommentTable; -import com.example.prdoit.model.ContentTable; -import com.example.prdoit.model.NotificationTable; +import com.example.prdoit.model.*; import com.example.prdoit.repository.*; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -26,6 +23,7 @@ public class CommentServiceImpl implements CommentService { private final ContentTableRepository contentTableRepository; private final NotificationTableRepository notificationTableRepository; private final IdTableRepository idTableRepository; + private final CommunityTableRepository communityTableRepository; // 1. 댓글 목록 조회 (GET) @Override @@ -41,12 +39,14 @@ public List getCommentList(String contentId) { .commentContent(comment.getCommentContent()) .commentNickname(comment.getCommentNickname()) .commentDate(comment.getCommentDate()) + .userId(comment.getContentId().getUserId().getId()) .commentReplyResponseDtoList(comment.getCommentCommentTable().stream() .map(reply -> CommentReplyResponseDto.builder() .commentReplyId(reply.getCommentCommentId()) .commentReplyContent(reply.getCommentCommentContent()) .commentReplyNickname(reply.getUserNickname()) .commentReplyDate(reply.getCommentCommentDate()) + .userId(reply.getCommentId().getContentId().getUserId().getId()) .build()) .collect(Collectors.toList())) .build()) @@ -61,22 +61,29 @@ public void postComment(CommentRequestDto commentRequestDto) { ContentTable contentTable = contentTableRepository.findById(commentRequestDto.getContentId()) .orElseThrow(() -> new CustomException("해당 게시글이 없습니다.")); - commentTableRepository.save(CommentTable.builder() - .commentContent(commentRequestDto.getCommentContent()) - .commentNickname(commentRequestDto.getCommentNickname()) - .commentDate(commentRequestDto.getCommentDate()) - .contentId(contentTable) - .build()); - - notificationTableRepository.save(NotificationTable.builder() - .notificationContent("댓글이 작성되었습니다.") - .contentId(contentTable.getContentId()) - .userId(contentTable.getUserId()) - .isRead(0) - .isContent(1) - .build()); - - log.info("[postComment] 댓글 등록을 완료했습니다."); + IdTable idTable = idTableRepository.findById(commentRequestDto.getUserId()).orElseThrow(()-> new CustomException("해당 아이디가 존재하지 않습니다.")); + + try { + commentTableRepository.save(CommentTable.builder() + .commentContent(commentRequestDto.getCommentContent()) + .commentNickname(idTable.getNickname()) + .commentDate(commentRequestDto.getCommentDate()) + .contentId(contentTable) + .build()); + + notificationTableRepository.save(NotificationTable.builder() + .notificationContent("댓글이 작성되었습니다.") + .contentId(contentTable.getContentId()) + .userId(contentTable.getUserId()) + .isRead(0) + .isContent(1) + .build()); + + log.info("[postComment] 댓글 등록을 완료했습니다."); + } catch (Exception e){ + log.error("[postComment] 댓글 등록 중 오류 발생 - {}", e.getMessage()); + throw new CustomException("댓글 등록 중 오류가 발생했습니다."); + } } // 3. 대댓글 작성 (POST) @@ -87,22 +94,28 @@ public void postCommentReply(CommentReplyRequestDto commentReplyRequestDto) { CommentTable parentComment = commentTableRepository.findById(commentReplyRequestDto.getCommentId()) .orElseThrow(() -> new CustomException("해당 댓글이 없습니다.")); - commentCommentTableRepository.save(CommentCommentTable.builder() - .commentCommentContent(commentReplyRequestDto.getCommentReplyContent()) - .userNickname(commentReplyRequestDto.getCommentReplyNickname()) - .commentCommentDate(commentReplyRequestDto.getCommentReplyDate()) - .commentId(parentComment) - .build()); - - notificationTableRepository.save(NotificationTable.builder() - .notificationContent("대댓글이 작성되었습니다.") - .contentId(parentComment.getContentId().getContentId()) - .userId(idTableRepository.findByNickname(parentComment.getCommentNickname())) - .isRead(0) - .isContent(1) - .build()); - - log.info("[postCommentReply] 대댓글 등록을 완료했습니다."); + IdTable idTable = idTableRepository.findById(commentReplyRequestDto.getUserId()).orElseThrow(()->new CustomException("해당아이디가 존재하지 않습니다.")); + try { + commentCommentTableRepository.save(CommentCommentTable.builder() + .commentCommentContent(commentReplyRequestDto.getCommentReplyContent()) + .userNickname(idTable.getNickname()) + .commentCommentDate(commentReplyRequestDto.getCommentReplyDate()) + .commentId(parentComment) + .build()); + + notificationTableRepository.save(NotificationTable.builder() + .notificationContent("대댓글이 작성되었습니다.") + .contentId(parentComment.getContentId().getContentId()) + .userId(idTableRepository.findByNickname(parentComment.getCommentNickname())) + .isRead(0) + .isContent(1) + .build()); + + log.info("[postCommentReply] 대댓글 등록을 완료했습니다."); + } catch (Exception e){ + log.error("[postCommentReply] 대댓글 등록 중 오류 발생 - {}", e.getMessage()); + throw new CustomException("대댓글 등록 중 오류가 발생했습니다."); + } } // 4. 댓글 수정 (PATCH) @@ -113,11 +126,16 @@ public void patchComment(CommentPatchDto commentPatchDto) { CommentTable comment = commentTableRepository.findById(commentPatchDto.getCommentId()) .orElseThrow(() -> new CustomException("해당 댓글이 없습니다.")); - comment.setCommentContent(commentPatchDto.getCommentContent()); - comment.setCommentDate(commentPatchDto.getCommentDate()); - commentTableRepository.save(comment); + try{ + comment.setCommentContent(commentPatchDto.getCommentContent()); + comment.setCommentDate(commentPatchDto.getCommentDate()); + commentTableRepository.save(comment); - log.info("[patchComment] 댓글 수정이 완료되었습니다."); + log.info("[patchComment] 댓글 수정이 완료되었습니다."); + } catch (Exception e){ + log.error("[patchComment] 댓글 수정 중 오류 발생 - {}", e.getMessage()); + throw new CustomException("댓글 수정 중 오류가 발생했습니다."); + } } // 5. 대댓글 수정 (PATCH) @@ -128,10 +146,146 @@ public void patchCommentReply(CommentReplyPatchDto commentReplyPatchDto) { CommentCommentTable reply = commentCommentTableRepository.findById(commentReplyPatchDto.getCommentReplyId()) .orElseThrow(() -> new CustomException("해당 대댓글이 없습니다.")); - reply.setCommentCommentContent(commentReplyPatchDto.getCommentReplyContent()); - reply.setCommentCommentDate(commentReplyPatchDto.getCommentReplyDate()); - commentCommentTableRepository.save(reply); + try{ + reply.setCommentCommentContent(commentReplyPatchDto.getCommentReplyContent()); + reply.setCommentCommentDate(commentReplyPatchDto.getCommentReplyDate()); + commentCommentTableRepository.save(reply); + + log.info("[patchCommentReply] 대댓글 수정이 완료되었습니다."); + } catch (Exception e){ + log.error("[patchCommentReply] 대댓글 수정 중 오류 발생 - {}", e.getMessage()); + throw new CustomException("대댓글 수정 중 오류가 발생했습니다."); + } + } + + @Override + public List getCommunityCommentList(String communityId) { + log.info("[getCommunityCommentList] 커뮤니티 댓글 목록 조회 시작 - Community ID: {}", communityId); + + CommunityTable communityTable = communityTableRepository.findById(communityId) + .orElseThrow(() -> new CustomException("해당 커뮤니티가 없습니다. ID = " + communityId)); + + try{ + return communityTable.getCommentTable().stream().map(comment -> CommunityCommentResponseDto.builder() + .commentId(comment.getCommentId()) + .commentContent(comment.getCommentContent()) + .userId(comment.getCommunityId().getId().getId()) + .commentNickname(comment.getCommentNickname()) + .commentDate(comment.getCommentDate()) + .communityCommentReplyResponseDtoList(comment.getCommentCommentTable().stream() + .map(reply -> CommunityCommentReplyResponseDto.builder() + .commentReplyId(reply.getCommentCommentId()) + .commentReplyContent(reply.getCommentCommentContent()) + .commentReplyNickname(reply.getUserNickname()) + .commentReplyDate(reply.getCommentCommentDate()) + .userId(reply.getCommentId().getCommunityId().getId().getId()) + .build()) + .collect(Collectors.toList())) + .build()).collect(Collectors.toList()); + } catch (Exception e){ + log.error("[getCommunityCommentList] 커뮤니티 댓글 목록 조회 중 오류 발생 - {}", e.getMessage()); + throw new CustomException("커뮤니티 댓글 목록 조회 중 오류가 발생했습니다."); + } + } + + @Override + public void postCommunityComment(CommunityCommentPostDto communityCommentPostDto) { + log.info("[postCommunityComment] 커뮤니티 댓글 등록 시작 - Community ID: {}", communityCommentPostDto.getCommunityId()); + + CommunityTable communityTable = communityTableRepository.findById(communityCommentPostDto.getCommunityId()) + .orElseThrow(() -> new CustomException("해당 커뮤니티가 없습니다.")); + + IdTable idTable = idTableRepository.findById(communityCommentPostDto.getUserId()).orElseThrow(()-> new CustomException("해당 아이디가 존재하지 않습니다.")); + + try { + commentTableRepository.save(CommentTable.builder() + .commentContent(communityCommentPostDto.getCommentContent()) + .commentNickname(idTable.getNickname()) + .commentDate(communityCommentPostDto.getCommentDate()) + .communityId(communityTable) + .build()); + + notificationTableRepository.save(NotificationTable.builder() + .notificationContent("커뮤니티 댓글이 작성되었습니다.") + .contentId(communityTable.getCommunityId()) + .userId(communityTable.getId()) + .isRead(0) + .isContent(1) + .build()); + + log.info("[postCommunityComment] 커뮤니티 댓글 등록을 완료했습니다."); + } catch (Exception e){ + log.error("[postCommunityComment] 커뮤니티 댓글 등록 중 오류 발생 - {}", e.getMessage()); + throw new CustomException("커뮤니티 댓글 등록 중 오류가 발생했습니다."); + } + } + + @Override + public void postCommunityCommentReply(CommunityCommentReplyPostDto communityCommentReplyPostDto) { + log.info("[postCommunityCommentReply] 커뮤니티 대댓글 등록 시작"); + + CommentTable parentComment = commentTableRepository.findById(communityCommentReplyPostDto.getCommentId()) + .orElseThrow(() -> new CustomException("해당 댓글이 없습니다.")); + + IdTable idTable = idTableRepository.findById(communityCommentReplyPostDto.getUserId()).orElseThrow(()->new CustomException("해당아이디가 존재하지 않습니다.")); + try { + commentCommentTableRepository.save(CommentCommentTable.builder() + .commentCommentContent(communityCommentReplyPostDto.getCommentReplyContent()) + .userNickname(idTable.getNickname()) + .commentCommentDate(communityCommentReplyPostDto.getCommentReplyDate()) + .commentId(parentComment) + .build()); + + notificationTableRepository.save(NotificationTable.builder() + .notificationContent("커뮤니티 대댓글이 작성되었습니다.") + .contentId(parentComment.getCommunityId().getCommunityId()) + .userId(idTableRepository.findByNickname(parentComment.getCommentNickname())) + .isRead(0) + .isContent(1) + .build()); + + log.info("[postCommunityCommentReply] 커뮤니티 대댓글 등록을 완료했습니다."); + } catch (Exception e){ + log.error("[postCommunityCommentReply] 커뮤니티 대댓글 등록 중 오류 발생 - {}", e.getMessage()); + throw new CustomException("커뮤니티 대댓글 등록 중 오류가 발생했습니다."); + } + } + + @Override + public void patchCommunityComment(CommunityCommentPatchDto communityCommentPatchDto) { + log.info("[patchCommunityComment] 커뮤니티 댓글 수정 시작 - Comment ID: {}", communityCommentPatchDto.getCommentId()); + + CommentTable comment = commentTableRepository.findById(communityCommentPatchDto.getCommentId()) + .orElseThrow(() -> new CustomException("해당 댓글이 없습니다.")); + + try{ + comment.setCommentContent(communityCommentPatchDto.getCommentContent()); + comment.setCommentDate(communityCommentPatchDto.getCommentDate()); + commentTableRepository.save(comment); + + log.info("[patchCommunityComment] 커뮤니티 댓글 수정이 완료되었습니다."); + } catch (Exception e){ + log.error("[patchCommunityComment] 커뮤니티 댓글 수정 중 오류 발생 - {}", e.getMessage()); + throw new CustomException("커뮤니티 댓글 수정 중 오류가 발생했습니다."); + } + } + + @Override + public void patchCommunityCommentReply(CommunityCommentReplyPatchDto communityCommentReplyPatchDto) { + log.info("[patchCommunityCommentReply] 커뮤니티 대댓글 수정 시작 - CommentReply ID: {}", communityCommentReplyPatchDto.getCommentReplyId()); + + CommentCommentTable reply = commentCommentTableRepository.findById(communityCommentReplyPatchDto.getCommentReplyId()) + .orElseThrow(() -> new CustomException("해당 대댓글이 없습니다.")); + + try{ + reply.setCommentCommentContent(communityCommentReplyPatchDto.getCommentReplyContent()); + reply.setCommentCommentDate(communityCommentReplyPatchDto.getCommentReplyDate()); + commentCommentTableRepository.save(reply); - log.info("[patchCommentReply] 대댓글 수정이 완료되었습니다."); + log.info("[patchCommunityCommentReply] 커뮤니티 대댓글 수정이 완료되었습니다."); + } catch (Exception e){ + log.error("[patchCommunityCommentReply] 커뮤니티 대댓글 수정 중 오류 발생 - {}", e.getMessage()); + throw new CustomException("커뮤니티 대댓글 수정 중 오류가 발생했습니다."); + } } } diff --git a/src/main/java/com/example/prdoit/service/content/ContentService.java b/src/main/java/com/example/prdoit/service/content/ContentService.java index 02b60cc..380b0d1 100644 --- a/src/main/java/com/example/prdoit/service/content/ContentService.java +++ b/src/main/java/com/example/prdoit/service/content/ContentService.java @@ -20,4 +20,6 @@ public interface ContentService { TotalContentDto getTotalContent(String userId, int size, int page); + void likeContent(String contentId); + } diff --git a/src/main/java/com/example/prdoit/service/content/ContentServiceImpl.java b/src/main/java/com/example/prdoit/service/content/ContentServiceImpl.java index 409455f..df0f9aa 100644 --- a/src/main/java/com/example/prdoit/service/content/ContentServiceImpl.java +++ b/src/main/java/com/example/prdoit/service/content/ContentServiceImpl.java @@ -248,4 +248,18 @@ public TotalContentDto getTotalContent(String userId, int size, int page){ } } + @Override + public void likeContent(String contentId){ + log.info("[likeContent] 컨텐츠 좋아요 로직 시작"); + try { + ContentTable contentTable = contentRepository.findById(contentId).orElseThrow + (() -> new RuntimeException("존재하지 않는 컨텐츠입니다.")); + contentTable.setContentLike(contentTable.getContentLike() + 1); + contentRepository.save(contentTable); + } catch (Exception e) { + log.error(e.getMessage()); + throw new RuntimeException(e.getMessage()); + } + } + } diff --git a/src/main/java/com/example/prdoit/service/user/UserService.java b/src/main/java/com/example/prdoit/service/user/UserService.java index 39c3793..aba6636 100644 --- a/src/main/java/com/example/prdoit/service/user/UserService.java +++ b/src/main/java/com/example/prdoit/service/user/UserService.java @@ -1,5 +1,6 @@ package com.example.prdoit.service.user; +import com.example.prdoit.dto.user.InformationDto; import com.example.prdoit.dto.user.UserDto; public interface UserService { @@ -22,4 +23,5 @@ public interface UserService { void checkPassword(String userId, String password); + InformationDto getInformation(String userId); } diff --git a/src/main/java/com/example/prdoit/service/user/UserServiceImpl.java b/src/main/java/com/example/prdoit/service/user/UserServiceImpl.java index 6efdd20..a3ba180 100644 --- a/src/main/java/com/example/prdoit/service/user/UserServiceImpl.java +++ b/src/main/java/com/example/prdoit/service/user/UserServiceImpl.java @@ -1,5 +1,6 @@ package com.example.prdoit.service.user; +import com.example.prdoit.dto.user.InformationDto; import com.example.prdoit.dto.user.UserDto; import com.example.prdoit.exception.CustomException; import com.example.prdoit.model.IdTable; @@ -167,4 +168,18 @@ public void checkPassword(String userId, String password){ throw new CustomException(e.getMessage()); } } + + @Override + public InformationDto getInformation(String userId) { + log.info("[getInformation] 정보 조회 로직 시작"); + + IdTable idTable = idTableRepository.findById(userId).orElseThrow(() -> new CustomException("해당 아이디로 가입된 정보가 없습니다.")); + + return InformationDto.builder() + .id(idTable.getId()) + .email(idTable.getEmail()) + .name(idTable.getName()) + .nickname(idTable.getNickname()) + .build(); + } }