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 @@ -124,5 +124,12 @@ select count(c)
""")
Long countByUserIdAndIsDeletedFalseAndIsSharedTrue(@Param("userId") Long userId);

boolean existsByUserIdAndMealAndCreatedAtBetweenAndIsDeletedFalse(
Long userId,
Meal meal,
LocalDateTime startOfDay,
LocalDateTime endOfDay
);
Comment on lines +127 to +132

Choose a reason for hiding this comment

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

medium

메서드 이름이 너무 길어 가독성이 저하될 수 있습니다. Spring Data JPA의 쿼리 메서드 이름 규칙은 편리하지만, 조건이 많아지면 메서드 이름이 과도하게 길어지는 단점이 있습니다.

@Query 어노테이션을 사용하여 JPQL을 직접 작성하면, 메서드 이름을 더 간결하고 의미있게 만들 수 있어 코드의 가독성과 유지보수성을 높일 수 있습니다. 이 리포지토리의 다른 부분(findFeedExcludeBlocked, findCardsByHashtag 등)에서도 @Query를 사용하고 있으므로, 일관성을 유지하는 좋은 방법이기도 합니다.

아래와 같이 변경하는 것을 제안합니다.

Suggested change
boolean existsByUserIdAndMealAndCreatedAtBetweenAndIsDeletedFalse(
Long userId,
Meal meal,
LocalDateTime startOfDay,
LocalDateTime endOfDay
);
@Query("select count(c) > 0 from Card c where c.user.id = :userId and c.meal = :meal and c.createdAt between :startOfDay and :endOfDay and c.isDeleted = false")
boolean existsActiveCardByMealAndDate(
@Param("userId") Long userId,
@Param("meal") Meal meal,
@Param("startOfDay") LocalDateTime startOfDay,
@Param("endOfDay") LocalDateTime endOfDay
);



}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public CardResponse.CreateCardResponse createNewCard(HttpServletRequest req, Car
LocalDateTime endOfDay = today.atTime(LocalTime.MAX);

// 같은 날짜, 같은 meal 타입 카드 중복 확인
boolean existsSameMealCard = cardRepository.existsByUserIdAndMealAndCreatedAtBetween(
boolean existsSameMealCard = cardRepository.existsByUserIdAndMealAndCreatedAtBetweenAndIsDeletedFalse(

Choose a reason for hiding this comment

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

medium

CardRepository에 제안된 변경 사항에 맞춰, 여기서도 새로운 메서드 이름을 사용하도록 수정해야 합니다. 이렇게 하면 코드의 일관성을 유지하고 가독성을 높일 수 있습니다.

Suggested change
boolean existsSameMealCard = cardRepository.existsByUserIdAndMealAndCreatedAtBetweenAndIsDeletedFalse(
boolean existsSameMealCard = cardRepository.existsActiveCardByMealAndDate(

userId,
request.getMeal(),
startOfDay,
Expand Down
Loading