Hotfix/mateboard : 게시글 좋아요, 댓글 좋아요 수정#181
Conversation
| @RequiredArgsConstructor | ||
| @RestController | ||
| @RequestMapping("/api/v1/mate-board/posts/{mateId}/comments") | ||
| @RequestMapping("/api/v1/mate-board/posts/{matePostId}/comments") |
There was a problem hiding this comment.
API 경로에 mateId 대신 matePostId를 사용하는 것이 더 명확합니다. 변경 사항은 적절해 보입니다.
| * @return 조회된 댓글 ID | ||
| */ | ||
| @GetMapping("/{id}") | ||
| @GetMapping("/{commentId}") |
There was a problem hiding this comment.
id 대신 commentId를 사용하여 경로 변수의 의미를 명확히 하는 것이 좋습니다. 변경 사항은 좋습니다.
| * @return 수정된 댓글 ID | ||
| */ | ||
| @PutMapping("/{id}") | ||
| @PutMapping("/{commentId}") |
There was a problem hiding this comment.
id 대신 commentId를 사용하여 경로 변수의 의미를 명확히 하는 것이 좋습니다. 변경 사항은 좋습니다.
| * @return | ||
| */ | ||
| @DeleteMapping("/{id}") | ||
| @DeleteMapping("/{commentId}") |
There was a problem hiding this comment.
id 대신 commentId를 사용하여 경로 변수의 의미를 명확히 하는 것이 좋습니다. 변경 사항은 좋습니다.
| @@ -1,7 +1,6 @@ | |||
| package com.frend.planit.domain.mateboard.comment.controller; | |||
|
|
|||
| import com.frend.planit.domain.mateboard.comment.service.MateCommentLikeService; | |||
There was a problem hiding this comment.
User 객체 대신 userId를 사용하도록 변경되었습니다. 이유를 확인해야 합니다. UserService 또는 다른 곳에서 User 객체를 가져오는 로직이 변경되었을 가능성이 높습니다. 상세한 이유를 추가로 설명해주세요.
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/v1/mateposts/comments") | ||
| @RequestMapping("/api/v1/mate-board/posts/{matePostId}/comments/") |
There was a problem hiding this comment.
경로가 /api/v1/mateposts/comments 에서 /api/v1/mate-board/posts/{matePostId}/comments/ 로 변경되었습니다. 일관성을 위해 다른 API 경로와 일치하는지 확인해야 합니다. matePostId를 사용하는 것은 좋습니다.
| public ResponseEntity<Void> likeComment(@PathVariable Long commentId, | ||
| @AuthenticationPrincipal User user) { | ||
| mateCommentLikeService.like(commentId, user); | ||
| @AuthenticationPrincipal Long userId) { |
There was a problem hiding this comment.
AuthenticationPrincipal을 통해 User 객체 대신 userId를 직접 주입받도록 변경되었습니다. MateCommentLikeService의 변경 사항과 일관성이 있는지 확인해야 합니다. 변경의 이유와 영향을 명확히 해주세요.
| public ResponseEntity<Void> unlikeComment(@PathVariable Long commentId, | ||
| @AuthenticationPrincipal User user) { | ||
| mateCommentLikeService.unlike(commentId, user); | ||
| @AuthenticationPrincipal Long userId) { |
There was a problem hiding this comment.
AuthenticationPrincipal을 통해 User 객체 대신 userId를 직접 주입받도록 변경되었습니다. MateCommentLikeService의 변경 사항과 일관성이 있는지 확인해야 합니다. 변경의 이유와 영향을 명확히 해주세요.
| @@ -1,9 +1,12 @@ | |||
| package com.frend.planit.domain.mateboard.comment.service; | |||
|
|
|||
| import static com.frend.planit.global.response.ErrorType.USER_NOT_FOUND; | |||
There was a problem hiding this comment.
USER_NOT_FOUND 에러 타입을 import 했습니다. 에러 핸들링 로직 추가를 위한 준비로 보입니다.
| import com.frend.planit.domain.mateboard.comment.entity.MateCommentLike; | ||
| import com.frend.planit.domain.mateboard.comment.repository.MateCommentLikeRepository; | ||
| import com.frend.planit.domain.user.entity.User; | ||
| import com.frend.planit.domain.user.repository.UserRepository; |
There was a problem hiding this comment.
UserRepository를 추가했습니다. 유저 정보를 데이터베이스에서 가져오기 위함으로 보입니다.
|
|
||
| private final MateCommentService mateCommentService; | ||
| private final MateCommentLikeRepository mateCommentLikeRepository; | ||
| private final UserRepository userRepository; |
There was a problem hiding this comment.
UserRepository 필드를 추가했습니다. Dependency Injection을 통해 UserRepository를 주입받아 사용할 것으로 예상됩니다.
| * | ||
| * @param commentId | ||
| * @param user | ||
| * @param userId |
There was a problem hiding this comment.
파라미터 user 대신 userId를 사용하도록 변경되었습니다. 이는 Controller에서 User 객체 대신 userId를 받도록 변경된 것과 일관성을 유지하기 위함입니다.
| @Transactional | ||
| public void like(Long commentId, User user) { | ||
| // 1. 댓글이 존재하는지 확인 | ||
| public void like(Long commentId, Long userId) { |
There was a problem hiding this comment.
userId를 사용하여 User를 조회하고, 존재하지 않으면 USER_NOT_FOUND 예외를 발생시키는 로직이 추가되었습니다. 좋은 변경입니다. NullPointerException을 방지하고 에러 핸들링을 개선했습니다.
| // 2. 댓글이 존재하는지 확인 | ||
| MateComment mateComment = mateCommentService.findMateCommentOrThrow(commentId); | ||
| // 2. 이미 좋아요를 눌렀는지 확인, 이미 눌렀다면 예외 | ||
|
|
There was a problem hiding this comment.
좋아요 확인 로직의 라인 번호가 변경되었습니다. 코드 자체는 변경되지 않았지만, 이전에 추가된 userId 확인 로직 때문에 라인 번호가 변경된 것으로 보입니다. 문제는 없습니다.
| throw new ServiceException(ErrorType.ALREADY_LIKED); | ||
| } | ||
| // 3. 아니라면 저장 | ||
| // 4. 좋아요 안 눌렀으면 저장 |
There was a problem hiding this comment.
저장 로직의 라인 번호가 변경되었습니다. 코드 자체는 변경되지 않았지만, 이전에 추가된 userId 확인 로직 때문에 라인 번호가 변경된 것으로 보입니다. 문제는 없습니다.
| * | ||
| * @param commentId | ||
| * @param user | ||
| * @param userId |
There was a problem hiding this comment.
파라미터 user 대신 userId를 사용하도록 변경되었습니다. 이는 Controller에서 User 객체 대신 userId를 받도록 변경된 것과 일관성을 유지하기 위함입니다.
| @Transactional | ||
| public void unlike(Long commentId, User user) { | ||
| // 댓글 존재 확인 | ||
| public void unlike(Long commentId, Long userId) { |
There was a problem hiding this comment.
userId를 사용하여 User를 조회하고, 존재하지 않으면 USER_NOT_FOUND 예외를 발생시키는 로직이 추가되었습니다. 좋은 변경입니다. NullPointerException을 방지하고 에러 핸들링을 개선했습니다.
| // 2. 댓글 존재 확인 | ||
| MateComment mateComment = mateCommentService.findMateCommentOrThrow(commentId); | ||
| // 좋아요 기록이 있는지 확인 | ||
|
|
There was a problem hiding this comment.
좋아요 기록 확인 로직의 라인 번호가 변경되었습니다. 코드 자체는 변경되지 않았지만, 이전에 추가된 userId 확인 로직 때문에 라인 번호가 변경된 것으로 보입니다. 문제는 없습니다.
| .orElseThrow(() -> new ServiceException(ErrorType.LIKE_NOT_FOUND)); | ||
|
|
||
| // 3. 존재하면 삭제 | ||
| // 4. 존재하면 삭제 |
There was a problem hiding this comment.
삭제 로직의 라인 번호가 변경되었습니다. 코드 자체는 변경되지 않았지만, 이전에 추가된 userId 확인 로직 때문에 라인 번호가 변경된 것으로 보입니다. 문제는 없습니다.
| * @return 조회된 된 게시글 id | ||
| */ | ||
| @GetMapping("/{id}") | ||
| @GetMapping("/{matePostId}") |
There was a problem hiding this comment.
id 대신 matePostId를 사용하여 경로 변수의 의미를 명확히 하는 것이 좋습니다. 변경 사항은 좋습니다.
| * @return 수정된 게시글 응답 DTO | ||
| */ | ||
| @PutMapping("/{id}") | ||
| @PutMapping("/{matePostId}") |
There was a problem hiding this comment.
id 대신 matePostId를 사용하여 경로 변수의 의미를 명확히 하는 것이 좋습니다. 변경 사항은 좋습니다.
| * @return 삭제한 게시글 응답 DTO | ||
| */ | ||
| @DeleteMapping("/{id}") | ||
| @DeleteMapping("/{matePostId}") |
There was a problem hiding this comment.
id 대신 matePostId를 사용하여 경로 변수의 의미를 명확히 하는 것이 좋습니다. 변경 사항은 좋습니다.
|
|
||
| import com.frend.planit.domain.mateboard.post.service.MatePostLikeService; | ||
| import com.frend.planit.domain.user.entity.User; | ||
| import io.swagger.v3.oas.annotations.security.SecurityRequirement; |
There was a problem hiding this comment.
User entity import 제거 및 SecurityRequirement 추가. User entity 대신 userId를 사용하는 것으로 보이며, Swagger에서 보안 요구사항을 명시적으로 정의합니다. 변경 사항은 좋습니다.
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("api/v1/mateposts") | ||
| @RequestMapping("/api/v1/mate-board/posts/") |
There was a problem hiding this comment.
API 경로 변경. 일관성을 위해 다른 API 경로와 일치하는지 확인해야 합니다. 변경 사항은 좋습니다.
| private final MatePostLikeService matePostLikeService; | ||
|
|
||
| @PostMapping("{matePostId}/like") | ||
| @SecurityRequirement(name = "bearerAuth") |
There was a problem hiding this comment.
SecurityRequirement 추가. Bearer 토큰 인증을 필요로 함을 명시합니다. 변경 사항은 좋습니다.
| public ResponseEntity<Void> like(@PathVariable Long matePostId, | ||
| @AuthenticationPrincipal User user) { | ||
| matePostLikeService.like(matePostId, user); | ||
| @AuthenticationPrincipal Long userId) { |
There was a problem hiding this comment.
AuthenticationPrincipal을 통해 User 객체 대신 userId를 직접 주입받도록 변경되었습니다. MatePostLikeService의 변경 사항과 일관성이 있는지 확인해야 합니다. 변경의 이유와 영향을 명확히 해주세요.
| public ResponseEntity<Void> unlike(@PathVariable Long matePostId, | ||
| @AuthenticationPrincipal User user) { | ||
| matePostLikeService.unLike(matePostId, user); | ||
| @AuthenticationPrincipal Long userId) { |
There was a problem hiding this comment.
AuthenticationPrincipal을 통해 User 객체 대신 userId를 직접 주입받도록 변경되었습니다. MatePostLikeService의 변경 사항과 일관성이 있는지 확인해야 합니다. 변경의 이유와 영향을 명확히 해주세요.
| @@ -1,10 +1,12 @@ | |||
| package com.frend.planit.domain.mateboard.post.service; | |||
|
|
|||
| import static com.frend.planit.global.response.ErrorType.USER_NOT_FOUND; | |||
There was a problem hiding this comment.
USER_NOT_FOUND 에러 타입을 import 했습니다. 에러 핸들링 로직 추가를 위한 준비로 보입니다.
| import com.frend.planit.domain.mateboard.post.repository.MatePostLikeRepository; | ||
| import com.frend.planit.domain.mateboard.post.repository.MateRepository; | ||
| import com.frend.planit.domain.user.entity.User; | ||
| import com.frend.planit.domain.user.repository.UserRepository; |
There was a problem hiding this comment.
UserRepository를 추가했습니다. 유저 정보를 데이터베이스에서 가져오기 위함으로 보입니다.
| @@ -16,43 +18,50 @@ | |||
| public class MatePostLikeService { | |||
|
|
|||
| private final MatePostLikeRepository matePostLikeRepository; | |||
There was a problem hiding this comment.
MateRepository 필드가 제거되었습니다. 게시글 정보는 다른 방법으로 가져오는 것으로 변경된 것 같습니다. 변경의 이유를 명확히 해주세요.
| private final MateRepository mateRepository; | ||
| private final MateService mateService; | ||
|
|
||
| private final UserRepository userRepository; |
There was a problem hiding this comment.
UserRepository 필드를 추가했습니다. Dependency Injection을 통해 UserRepository를 주입받아 사용할 것으로 예상됩니다.
| @Transactional | ||
| public void like(Long postId, User user) { | ||
| // 1. 게시글 존재하는지 확인 | ||
| public void like(Long postId, Long userId) { |
There was a problem hiding this comment.
userId를 사용하여 User를 조회하고, 존재하지 않으면 USER_NOT_FOUND 예외를 발생시키는 로직이 추가되었습니다. 좋은 변경입니다. NullPointerException을 방지하고 에러 핸들링을 개선했습니다.
| .isPresent(); | ||
|
|
||
| // 2. 이미 좋아요 눌렀는지 확인 | ||
| // 3. 이미 좋아요 눌렀는지 확인 |
There was a problem hiding this comment.
좋아요 확인 로직의 라인 번호가 변경되었습니다. 코드 자체는 변경되지 않았지만, 이전에 추가된 userId 확인 로직 때문에 라인 번호가 변경된 것으로 보입니다. 문제는 없습니다.
| } | ||
|
|
||
| // 3. 좋아요 안 눌렀으면 저장 | ||
| // 4. 좋아요 안 눌렀으면 저장 |
There was a problem hiding this comment.
저장 로직의 라인 번호가 변경되었습니다. 코드 자체는 변경되지 않았지만, 이전에 추가된 userId 확인 로직 때문에 라인 번호가 변경된 것으로 보입니다. 문제는 없습니다.
| @Transactional | ||
| public void unLike(Long postId, User user) { | ||
| // 1. 게시글 존재하는지 확인 | ||
| public void unLike(Long postId, Long userId) { |
There was a problem hiding this comment.
userId를 사용하여 User를 조회하고, 존재하지 않으면 USER_NOT_FOUND 예외를 발생시키는 로직이 추가되었습니다. 좋은 변경입니다. NullPointerException을 방지하고 에러 핸들링을 개선했습니다.
|
|
||
| // 2. 좋아요 기록 조회 | ||
| MatePostLike like = matePostLikeRepository.findByUserAndMatePost(user, mate) | ||
| // 3. 좋아요 기록 조회 |
There was a problem hiding this comment.
좋아요 기록 조회 로직의 라인 번호가 변경되었습니다. 코드 자체는 변경되지 않았지만, 이전에 추가된 userId 확인 로직 때문에 라인 번호가 변경된 것으로 보입니다. 문제는 없습니다. 변수 이름 like에서 matePostUnlike로 변경된 부분은 확인이 필요합니다. 의도가 명확하지 않습니다.
| // 3. 존재하면 삭제 | ||
| matePostLikeRepository.delete(like); | ||
|
|
||
| // 4. 존재하면 삭제 |
There was a problem hiding this comment.
삭제 로직의 라인 번호가 변경되었습니다. 코드 자체는 변경되지 않았지만, 이전에 추가된 userId 확인 로직 때문에 라인 번호가 변경된 것으로 보입니다. 문제는 없습니다. 변수 이름 변경과 마찬가지로 like에서 matePostUnlike로 변경된 부분에 대한 추가 설명이 필요합니다.
Hotfix/mateboard : 게시글 좋아요, 댓글 좋아요 수정
🔘 Part
🔎 PR Type
🔧 작업 내용 상세 작성
[레포 이름 #이슈번호](이슈 주소)
작업 내용을 상세하게 작성해 주세요!
✔️ PR Checklist
커밋 메세지를 컨벤션에 맞게 잘 적용 하였나요?
테스트 코드 작성 / 단위 테스트 or 통합 테스트 진행 하셨나요?