Skip to content

Conversation

@hado0123
Copy link
Collaborator

@hado0123 hado0123 commented Jan 6, 2026

작업 내용

  • 관련 엔티티 구현(EpisodeLike)
  • 회차별 좋아요 등록
  • 회차별 좋아요 해제

테스트 내용

  • 엔티티 -> DB내 테이블 생성 확인
  • 회차별 좋아요 등록
  • 회차별 좋아요 해제
  • episode 테이블내 favorite_count 컬럼 값 집계 처리

@hado0123 hado0123 requested a review from f-lab-saponin January 6, 2026 13:30
@hado0123 hado0123 self-assigned this Jan 6, 2026
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 6, 2026

@hado0123 hado0123 changed the base branch from main to feature/30 January 9, 2026 09:00
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 lombok.Getter;

@Getter
public class EpisodeException extends RuntimeException {

Choose a reason for hiding this comment

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

EpisodeException 이게 사용중인 곳이 없어서 사용하는지 한번 확인부탁드려요!

Comment on lines +42 to +44
Integer newCount = episodeRepository.findById(episodeId)
.map(ep -> ep.getLikeCount() == null ? 0 : ep.getLikeCount())
.orElse(0);

Choose a reason for hiding this comment

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

여기도 굳이 다시 쿼리하지 않아도 업뎅트 성공했다면 likeCount + delta 로 반환해도될것 같아요.

Comment on lines +19 to +33
@PostMapping("/create")
public ResponseEntity<EpisodeLikeResponse> like(
@AuthenticationPrincipal CustomUserPrincipal principal,
@Valid @RequestBody EpisodeLikeRequest req
) {
EpisodeLikeResponse episodeLikeResponse
= episodeLikeService.like(principal.id(), req.episodeId());

return ResponseEntity.ok(episodeLikeResponse);
}

@DeleteMapping("/delete/{episodeId}")
public ResponseEntity<EpisodeLikeResponse> unlike(
@AuthenticationPrincipal CustomUserPrincipal principal,
@PathVariable Long episodeId

Choose a reason for hiding this comment

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

throw new AlreadyEpisodeLikeException();
}

episodeLikeRepository.save(EpisodeLike.like(member, episode));

Choose a reason for hiding this comment

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

member_id, episode_id 유니크 조건이 있으면 중복 인서트를 방지할 수 있을 것 같아요. 혹은 다른 좋은 방법이 있으면 적용해보면 좋아요.

Comment on lines +12 to +24
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("""
UPDATE Episode e
SET e.likeCount =
CASE
WHEN :delta < 0 AND COALESCE(e.likeCount, 0) <= 0
THEN 0
ELSE COALESCE(e.likeCount, 0) + :delta
END
WHERE e.id = :episodeId
""")
void updateLikeCountSafely(@Param("episodeId") Long episodeId,
@Param("delta") int delta);

Choose a reason for hiding this comment

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

deleted_at IS NULL
조건은 필요없을지 고민이 필요해보여요!

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