diff --git a/src/main/java/bst/bobsoolting/comment/command/application/controller/CommentCommandController.java b/src/main/java/bst/bobsoolting/comment/command/application/controller/CommentCommandController.java index 33267ae..34721c5 100644 --- a/src/main/java/bst/bobsoolting/comment/command/application/controller/CommentCommandController.java +++ b/src/main/java/bst/bobsoolting/comment/command/application/controller/CommentCommandController.java @@ -46,7 +46,6 @@ public ResponseEntity createComment(@RequestBody RequestCreateCommentVO reque } } - @PatchMapping("/{commentId}") public ResponseEntity updateComment(@PathVariable Long commentId, @RequestBody RequestUpdateCommentVO request, @RequestHeader(HttpHeaders.AUTHORIZATION) String token) { log.info("수정 요청된 commentId: {}, 데이터: {}", commentId, request); diff --git a/src/main/java/bst/bobsoolting/comment/command/domain/vo/request/RequestCreateCommentVO.java b/src/main/java/bst/bobsoolting/comment/command/domain/vo/request/RequestCreateCommentVO.java index 416a6b1..04a0828 100644 --- a/src/main/java/bst/bobsoolting/comment/command/domain/vo/request/RequestCreateCommentVO.java +++ b/src/main/java/bst/bobsoolting/comment/command/domain/vo/request/RequestCreateCommentVO.java @@ -12,6 +12,10 @@ @Schema(name = "RequestCreateCommentVO", description = "댓글 생성 요청 객체") public class RequestCreateCommentVO { + @Schema(description = "게시글 ID", example = "1L") + @JsonProperty("post_id") + private Long postId; + @Schema(description = "댓글 내용", example = "이거 정말 좋은 글이네요!") @JsonProperty("comment_content") private String commentContent; diff --git a/src/main/java/bst/bobsoolting/comment/command/domain/vo/response/ResponseCommentVO.java b/src/main/java/bst/bobsoolting/comment/command/domain/vo/response/ResponseCommentVO.java index f0b6aaf..981edb5 100644 --- a/src/main/java/bst/bobsoolting/comment/command/domain/vo/response/ResponseCommentVO.java +++ b/src/main/java/bst/bobsoolting/comment/command/domain/vo/response/ResponseCommentVO.java @@ -14,7 +14,7 @@ @Schema(name = "ResponseCommentVO", description = "댓글 응답 객체") public class ResponseCommentVO { - @Schema(description = "댓글 ID", example = "1001") + @Schema(description = "댓글 ID", example = "1L") @JsonProperty("comment_id") private Long commentId; @@ -26,6 +26,10 @@ public class ResponseCommentVO { @JsonProperty("created_at") private LocalDateTime createdAt; + @Schema(description = "게시글 ID", example = "1L") + @JsonProperty("post_id") + private Long postId; + @Schema(description = "작성자 ID", example = "user1234") @JsonProperty("member_id") private String memberId; diff --git a/src/main/java/bst/bobsoolting/comment/command/domain/vo/response/ResponseCreateCommentVO.java b/src/main/java/bst/bobsoolting/comment/command/domain/vo/response/ResponseCreateCommentVO.java index 371e135..97c3178 100644 --- a/src/main/java/bst/bobsoolting/comment/command/domain/vo/response/ResponseCreateCommentVO.java +++ b/src/main/java/bst/bobsoolting/comment/command/domain/vo/response/ResponseCreateCommentVO.java @@ -13,6 +13,14 @@ @Schema(name = "ResponseCreateCommentVO", description = "댓글 생성 응답 객체") public class ResponseCreateCommentVO { + @Schema(description = "게시글 ID", example = "1L") + @JsonProperty("post_id") + private Long postId; + + @Schema(description = "댓글 ID", example = "1L") + @JsonProperty("comment_id") + private Long commentId; + @Schema(description = "등록된 댓글 내용", example = "이거 정말 좋은 글이네요!") @JsonProperty("comment_content") private String commentContent; diff --git a/src/main/java/bst/bobsoolting/comment/command/domain/vo/response/ResponseUpdateCommentVO.java b/src/main/java/bst/bobsoolting/comment/command/domain/vo/response/ResponseUpdateCommentVO.java index 0ed6789..0069929 100644 --- a/src/main/java/bst/bobsoolting/comment/command/domain/vo/response/ResponseUpdateCommentVO.java +++ b/src/main/java/bst/bobsoolting/comment/command/domain/vo/response/ResponseUpdateCommentVO.java @@ -13,6 +13,10 @@ @Schema(name = "ResponseUpdateCommentVO", description = "댓글 수정 응답 객체") public class ResponseUpdateCommentVO { + @Schema(description = "댓글 ID", example = "1L") + @JsonProperty("comment_id") + private Long commentId; + @Schema(description = "수정된 댓글 내용", example = "이 부분이 정말 공감됩니다.") @JsonProperty("comment_content") private String commentContent; diff --git a/src/main/java/bst/bobsoolting/like/command/application/controller/PostLikeCommandController.java b/src/main/java/bst/bobsoolting/like/command/application/controller/PostLikeCommandController.java index 732cf17..121af8b 100644 --- a/src/main/java/bst/bobsoolting/like/command/application/controller/PostLikeCommandController.java +++ b/src/main/java/bst/bobsoolting/like/command/application/controller/PostLikeCommandController.java @@ -1,8 +1,11 @@ package bst.bobsoolting.like.command.application.controller; import bst.bobsoolting.like.command.application.controller.docs.PostLikeCommandControllerDocs; +import bst.bobsoolting.like.command.application.dto.PostLikeDTO; +import bst.bobsoolting.like.command.application.mapper.PostLikeConverter; import bst.bobsoolting.like.command.application.service.PostLikeCommandService; import bst.bobsoolting.common.exception.CommonException; +import bst.bobsoolting.like.command.domain.vo.response.ResponsePostLikeVO; import bst.bobsoolting.util.SecurityUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -18,14 +21,16 @@ public class PostLikeCommandController implements PostLikeCommandControllerDocs private final PostLikeCommandService postLikeCommandService; private final SecurityUtil securityUtil; + private final PostLikeConverter postLikeConverter; @PostMapping("/{postId}") - public ResponseEntity likePost(@PathVariable Long postId, @RequestHeader(HttpHeaders.AUTHORIZATION) String token) { + public ResponseEntity likePost(@PathVariable Long postId, @RequestHeader(HttpHeaders.AUTHORIZATION) String token) { String kakaoId = securityUtil.getKakaoIdFromToken(token.replace("Bearer ", "")); log.info("좋아요 요청 - postId: {}, kakaoId: {}", postId, kakaoId); try { - postLikeCommandService.likePost(postId, kakaoId); - return ResponseEntity.ok("좋아요가 성공적으로 등록되었습니다."); + PostLikeDTO postLikeDTO = postLikeCommandService.likePost(postId, kakaoId); + ResponsePostLikeVO response = postLikeConverter.fromDTOToVO(postLikeDTO); + return ResponseEntity.status(HttpStatus.OK).body(response); } catch (CommonException e) { log.error("좋아요 처리 오류: {}", e.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage()); diff --git a/src/main/java/bst/bobsoolting/like/command/application/controller/docs/PostLikeCommandControllerDocs.java b/src/main/java/bst/bobsoolting/like/command/application/controller/docs/PostLikeCommandControllerDocs.java index 2ae3922..d40cfa2 100644 --- a/src/main/java/bst/bobsoolting/like/command/application/controller/docs/PostLikeCommandControllerDocs.java +++ b/src/main/java/bst/bobsoolting/like/command/application/controller/docs/PostLikeCommandControllerDocs.java @@ -25,5 +25,5 @@ public interface PostLikeCommandControllerDocs { @ApiResponse(responseCode = "500", description = "서버 오류") }) @PostMapping("/{postId}") - ResponseEntity likePost(@Parameter(description = "게시글 ID") @PathVariable Long postId, @RequestHeader(HttpHeaders.AUTHORIZATION) String token); + ResponseEntity likePost(@Parameter(description = "게시글 ID") @PathVariable Long postId, @RequestHeader(HttpHeaders.AUTHORIZATION) String token); } diff --git a/src/main/java/bst/bobsoolting/like/command/application/dto/PostLikeDTO.java b/src/main/java/bst/bobsoolting/like/command/application/dto/PostLikeDTO.java new file mode 100644 index 0000000..2227aab --- /dev/null +++ b/src/main/java/bst/bobsoolting/like/command/application/dto/PostLikeDTO.java @@ -0,0 +1,18 @@ +package bst.bobsoolting.like.command.application.dto; + +import lombok.*; + +import java.time.LocalDateTime; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +@ToString +public class PostLikeDTO { + private Long likeId; + private LocalDateTime createdAt; + private Long postId; + private String memberId; +} diff --git a/src/main/java/bst/bobsoolting/like/command/application/mapper/PostLikeConverter.java b/src/main/java/bst/bobsoolting/like/command/application/mapper/PostLikeConverter.java new file mode 100644 index 0000000..9a61daf --- /dev/null +++ b/src/main/java/bst/bobsoolting/like/command/application/mapper/PostLikeConverter.java @@ -0,0 +1,18 @@ +package bst.bobsoolting.like.command.application.mapper; + +import bst.bobsoolting.like.command.application.dto.PostLikeDTO; +import bst.bobsoolting.like.command.domain.vo.response.ResponsePostLikeVO; +import org.springframework.stereotype.Component; + +@Component +public class PostLikeConverter { + + public ResponsePostLikeVO fromDTOToVO(PostLikeDTO postLikeDTO) { + return ResponsePostLikeVO.builder() + .likeId(postLikeDTO.getLikeId()) + .createdAt(postLikeDTO.getCreatedAt()) + .postId(postLikeDTO.getPostId()) + .memberId(postLikeDTO.getMemberId()) + .build(); + } +} diff --git a/src/main/java/bst/bobsoolting/like/command/application/service/PostLikeCommandService.java b/src/main/java/bst/bobsoolting/like/command/application/service/PostLikeCommandService.java index 81a94fa..33f3999 100644 --- a/src/main/java/bst/bobsoolting/like/command/application/service/PostLikeCommandService.java +++ b/src/main/java/bst/bobsoolting/like/command/application/service/PostLikeCommandService.java @@ -1,8 +1,9 @@ package bst.bobsoolting.like.command.application.service; +import bst.bobsoolting.like.command.application.dto.PostLikeDTO; import jakarta.transaction.Transactional; public interface PostLikeCommandService { @Transactional - void likePost(Long postId, String kakaoId); + PostLikeDTO likePost(Long postId, String kakaoId); } diff --git a/src/main/java/bst/bobsoolting/like/command/application/service/PostLikeCommandServiceImpl.java b/src/main/java/bst/bobsoolting/like/command/application/service/PostLikeCommandServiceImpl.java index 9b88aa1..211d738 100644 --- a/src/main/java/bst/bobsoolting/like/command/application/service/PostLikeCommandServiceImpl.java +++ b/src/main/java/bst/bobsoolting/like/command/application/service/PostLikeCommandServiceImpl.java @@ -2,6 +2,7 @@ import bst.bobsoolting.common.exception.CommonException; import bst.bobsoolting.common.exception.ErrorCode; +import bst.bobsoolting.like.command.application.dto.PostLikeDTO; import bst.bobsoolting.like.command.domain.aggregate.entity.PostLike; import bst.bobsoolting.like.command.domain.repository.PostLikeRepository; import bst.bobsoolting.member.command.domain.aggregate.entity.Member; @@ -9,10 +10,9 @@ import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.security.oauth2.core.user.OAuth2User; import org.springframework.stereotype.Service; -import java.util.Optional; +import java.time.LocalDateTime; @Slf4j @Service @@ -24,19 +24,17 @@ public class PostLikeCommandServiceImpl implements PostLikeCommandService { @Transactional @Override - public void likePost(Long postId, String kakaoId) { + public PostLikeDTO likePost(Long postId, String kakaoId) { log.info("좋아요 처리 시작 - postId: {}", postId); - try {Member member = memberMapper.findByKakaoId(kakaoId); + try { + Member member = memberMapper.findByKakaoId(kakaoId); if (member == null) throw new CommonException(ErrorCode.NOT_FOUND_MEMBER); String memberId = member.getMemberId(); - Optional existingLike = postLikeRepository.findByPostIdAndMemberId(postId, memberId); - if (existingLike.isPresent()) throw new CommonException(ErrorCode.ALREADY_LIKED); + PostLike existingLike = postLikeRepository.findByPostIdAndMemberId(postId, memberId); + if (existingLike != null) throw new CommonException(ErrorCode.ALREADY_LIKED); - PostLike postLike = PostLike.builder() - .postId(postId) - .memberId(memberId) - .build(); + PostLike postLike = like(postId, memberId); postLikeRepository.save(postLike); log.info("좋아요 등록 완료 - postId: {}, memberId: {}", postId, memberId); @@ -48,5 +46,15 @@ public void likePost(Long postId, String kakaoId) { log.error("예상치 못한 오류 발생", e); throw new CommonException(ErrorCode.INTERNAL_SERVER_ERROR); } + return null; + } + + private PostLike like(Long postId, String memberId) { + PostLike postLike = PostLike.builder() + .createdAt(LocalDateTime.now()) + .postId(postId) + .memberId(memberId) + .build(); + return postLike; } } diff --git a/src/main/java/bst/bobsoolting/like/command/domain/repository/PostLikeRepository.java b/src/main/java/bst/bobsoolting/like/command/domain/repository/PostLikeRepository.java index 38d427f..0959e92 100644 --- a/src/main/java/bst/bobsoolting/like/command/domain/repository/PostLikeRepository.java +++ b/src/main/java/bst/bobsoolting/like/command/domain/repository/PostLikeRepository.java @@ -8,5 +8,5 @@ @Repository public interface PostLikeRepository extends JpaRepository { - Optional findByPostIdAndMemberId(Long postId, String memberId); + PostLike findByPostIdAndMemberId(Long postId, String memberId); } diff --git a/src/main/java/bst/bobsoolting/like/command/domain/vo/response/ResponsePostLikeVO.java b/src/main/java/bst/bobsoolting/like/command/domain/vo/response/ResponsePostLikeVO.java new file mode 100644 index 0000000..1fecd66 --- /dev/null +++ b/src/main/java/bst/bobsoolting/like/command/domain/vo/response/ResponsePostLikeVO.java @@ -0,0 +1,32 @@ +package bst.bobsoolting.like.command.domain.vo.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +import java.time.LocalDateTime; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +@Builder +@ToString +@Schema(name = "ResponsePostLikeVO", description = "게시글 좋아요 응답 객체") +public class ResponsePostLikeVO { + + @Schema(description = "좋아요 ID", example = "1L") + @JsonProperty("like_id") + private Long likeId; + + @Schema(description = "좋아요 한 시각", example = "2024-03-04T14:30:00") + @JsonProperty("created_at") + private LocalDateTime createdAt; + + @Schema(description = "게시글 ID", example = "1L") + @JsonProperty("post_id") + private Long postId; + + @Schema(description = "좋아요 등록한 사용자 ID", example = "20250315-UUID") + @JsonProperty("member_id") + private String memberId; +} diff --git a/src/main/java/bst/bobsoolting/reply/command/domain/vo/response/ResponseReplyVO.java b/src/main/java/bst/bobsoolting/reply/command/domain/vo/response/ResponseReplyVO.java index 5554bd7..72c6b69 100644 --- a/src/main/java/bst/bobsoolting/reply/command/domain/vo/response/ResponseReplyVO.java +++ b/src/main/java/bst/bobsoolting/reply/command/domain/vo/response/ResponseReplyVO.java @@ -14,7 +14,7 @@ @Schema(name = "ResponseReplyVO", description = "대댓글 응답 객체") public class ResponseReplyVO { - @Schema(description = "대댓글 ID", example = "2001") + @Schema(description = "대댓글 ID", example = "1L") @JsonProperty("reply_id") private Long replyId; @@ -22,11 +22,15 @@ public class ResponseReplyVO { @JsonProperty("reply_content") private String replyContent; + @Schema(description = "대댓글 작성 시간", example = "2024-03-04T14:30:00") + @JsonProperty("created_at") + private LocalDateTime createdAt; + @Schema(description = "작성자 ID", example = "user5678") @JsonProperty("member_id") private String memberId; - @Schema(description = "대댓글 작성 시간", example = "2024-03-04T14:30:00") - @JsonProperty("created_at") - private LocalDateTime createdAt; + @Schema(description = "댓글 ID", example = "1L") + @JsonProperty("comment_id") + private Long commentId; }