Skip to content

Conversation

@hado0123
Copy link
Collaborator

@hado0123 hado0123 commented Jan 5, 2026

작업 내용

  • 관련 엔티티 구현(CreationFavorite)
  • 관심 작품 등록
  • 관심 작품 해제
  • 관심 작품 목록 보기

테스트 내용

  • 엔티티 -> DB내 테이블 생성 확인
  • 관심 작품 등록
  • 관심 작품 해제
  • creation 테이블내 favorite_count 컬럼 값 집계 처리
  • 특정 회원의 관심 작품 목록 응답

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 5, 2026

@hado0123 hado0123 self-assigned this Jan 6, 2026
@f-lab-saponin
Copy link

f-lab-saponin commented Jan 6, 2026

@hado0123 안녕하세요~ 혹시 이전 브랜치 (feature/22) 에서 파생된 브랜치라면 이전 브랜치로 다시 merge 하도록 변경 부탁드립니다.
#31 PR 도 마찬가지로요!

변경된 파일수가 많아서 보기가 어렵네요 😢

@hado0123 hado0123 changed the base branch from main to feature/22 January 9, 2026 08:59
@hado0123
Copy link
Collaborator Author

hado0123 commented Jan 9, 2026

@hado0123 안녕하세요~ 혹시 이전 브랜치 (feature/22) 에서 파생된 브랜치라면 이전 브랜치로 다시 merge 하도록 변경 부탁드립니다. #31 PR 도 마찬가지로요!

변경된 파일수가 많아서 보기가 어렵네요 😢

어머.. 완료했습니다!

Copy link

@f-lab-saponin f-lab-saponin left a 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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreationException 을 상속하는게 맞을 것 같아요 🙂

Comment on lines +12 to +22
@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
""")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 왜 이렇게 했는지 한 번 설명해주시면 좋을 것 같아요!
정리한번 해보셨으면 좋겠네요 :)

Comment on lines +39 to +47
// 이미 관심이면 그대로 반환
if (creationFavoriteRepository.existsByMemberIdAndCreationId(memberId, creationId)) {
Integer count = creation.getFavoriteCount();
return CreationFavoriteResponse.of(creationId, count == null ? 0 : count, true);
}

// 관심 등록
creationFavoriteRepository.save(CreationFavorite.create(member, creation));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

save 할 때 동시성문제로 2개의 같은 행이 쌓일 수 있을 것 같아요. 한 번 방어해볼까요?

Comment on lines +51 to +54
// 최신 카운트 다시 읽기(정확한 값 응답용)
Integer newCount = creationRepository.findById(creationId)
.map(c -> c.getFavoriteCount() == null ? 0 : c.getFavoriteCount())
.orElse(0);

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())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 체크하는 로직이 많은데, CreateFavorite.favoriteCount = 0 이렇게 기본값 정해놓으면 이런게 필요없을 것 같아요!

Comment on lines +26 to +27
@PostMapping("/create")
public ResponseEntity<CreationFavoriteResponse> favorite(

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 도 마찬가지 입니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants