Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ public interface PostLikeCommandControllerDocs {
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@PostMapping("/{postId}")
ResponseEntity<String> 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);
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

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;
import bst.bobsoolting.member.query.repository.MemberMapper;
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
Expand All @@ -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<PostLike> 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);
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

@Repository
public interface PostLikeRepository extends JpaRepository<PostLike, Long> {
Optional<PostLike> findByPostIdAndMemberId(Long postId, String memberId);
PostLike findByPostIdAndMemberId(Long postId, String memberId);
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@
@Schema(name = "ResponseReplyVO", description = "대댓글 응답 객체")
public class ResponseReplyVO {

@Schema(description = "대댓글 ID", example = "2001")
@Schema(description = "대댓글 ID", example = "1L")
@JsonProperty("reply_id")
private Long replyId;

@Schema(description = "대댓글 내용", example = "저도 그렇게 생각해요!")
@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;
}
Loading