-
Notifications
You must be signed in to change notification settings - Fork 0
[#30] 관심 작품 등록/해제/목록보기 #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/22
Are you sure you want to change the base?
Conversation
|
f-lab-saponin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
관심 작품 도메인 확인했습니다. 고생하셨습니다!
리뷰한번 봐주세요 감사합니다!
|
|
||
| import com.creatorhub.constant.ErrorCode; | ||
|
|
||
| public class CreationFavoriteNotFoundException extends CreatorException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CreationException 을 상속하는게 맞을 것 같아요 🙂
| @Modifying(clearAutomatically = true, flushAutomatically = true) | ||
| @Query(""" | ||
| UPDATE Creation c | ||
| SET c.favoriteCount = | ||
| CASE | ||
| WHEN :delta < 0 AND COALESCE(c.favoriteCount, 0) <= 0 | ||
| THEN 0 | ||
| ELSE COALESCE(c.favoriteCount, 0) + :delta | ||
| END | ||
| WHERE c.id = :creationId | ||
| """) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분은 왜 이렇게 했는지 한 번 설명해주시면 좋을 것 같아요!
정리한번 해보셨으면 좋겠네요 :)
| // 이미 관심이면 그대로 반환 | ||
| if (creationFavoriteRepository.existsByMemberIdAndCreationId(memberId, creationId)) { | ||
| Integer count = creation.getFavoriteCount(); | ||
| return CreationFavoriteResponse.of(creationId, count == null ? 0 : count, true); | ||
| } | ||
|
|
||
| // 관심 등록 | ||
| creationFavoriteRepository.save(CreationFavorite.create(member, creation)); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
save 할 때 동시성문제로 2개의 같은 행이 쌓일 수 있을 것 같아요. 한 번 방어해볼까요?
| // 최신 카운트 다시 읽기(정확한 값 응답용) | ||
| Integer newCount = creationRepository.findById(creationId) | ||
| .map(c -> c.getFavoriteCount() == null ? 0 : c.getFavoriteCount()) | ||
| .orElse(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
위 쿼리가 성공했다면 굳이 조회 안하고, count + delta 로 반환해도 좋아보여요.
|
|
||
| // 최신 카운트 다시 읽기(정확한 값 응답용) | ||
| Integer newCount = creationRepository.findById(creationId) | ||
| .map(c -> c.getFavoriteCount() == null ? 0 : c.getFavoriteCount()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이렇게 체크하는 로직이 많은데, CreateFavorite.favoriteCount = 0 이렇게 기본값 정해놓으면 이런게 필요없을 것 같아요!
| @PostMapping("/create") | ||
| public ResponseEntity<CreationFavoriteResponse> favorite( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
url 명에 create 를 빼고, 대신 POST "/api/creations/favorites" 이면 생성으로 약속하는게 어떨까요?
(보통 관례)
아래 delete 도 마찬가지 입니다!



작업 내용
테스트 내용