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 @@ -28,7 +28,7 @@ public static PartnershipInfo fromEntity(Partnership partnership,
.startDate(partnership.getStartDate())
.endDate(partnership.getEndDate())
.collegeName(partnership.getPartnershipCollege() == null && partnership.getPartnershipDepartment() == null
? "총학"
? "총학생회"
: (partnership.getPartnershipCollege() != null ? partnership.getPartnershipCollege().getName() : null))
.departmentName(partnership.getPartnershipDepartment() != null ? partnership.getPartnershipDepartment().getName() : null)
.likeCount(restaurant.getLikes() != null ? restaurant.getLikes().size() : 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface PartnershipRepository extends JpaRepository<Partnership, Long>
or pd = :department
or (pc is null and pd is null)
)
and p.startDate <= current_date
and p.startDate >= current_date - 7

Choose a reason for hiding this comment

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

medium

JPQL 쿼리 내에 매직 넘버 7이 사용되었습니다. 이 값은 '최근 제휴를 보여주기 위한 기간'이라는 의미를 가지는 것으로 보입니다. 이처럼 의미를 가지는 숫자는 상수로 정의하여 사용하면 코드의 가독성과 유지보수성을 높일 수 있습니다. 예를 들어, PARTNERSHIP_LOOKBACK_DAYS와 같은 이름의 상수로 관리하는 것을 고려해 보세요.

and (p.endDate is null or p.endDate >= current_date)
""")
List<PartnershipRestaurant> findRestaurantsWithMyPartnerships(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public interface PartnershipRestaurantRepository extends JpaRepository<Partnersh
LEFT JOIN FETCH pr.partnerships p
LEFT JOIN FETCH p.partnershipCollege
LEFT JOIN FETCH p.partnershipDepartment
WHERE p.startDate <= CURRENT_DATE and (p.endDate is null or p.endDate >= CURRENT_DATE)""")
WHERE p.startDate >= current_date - 7 and (p.endDate is null or p.endDate >= CURRENT_DATE)""")

Choose a reason for hiding this comment

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

medium

이 쿼리에는 두 가지 개선점을 제안합니다.

  1. 매직 넘버 사용: PartnershipRepository와 마찬가지로 숫자 7이 매직 넘버로 사용되었습니다. 이 값을 상수로 추출하여 관리하면 여러 곳에서 동일한 값을 일관되게 사용하고 변경이 필요할 때 한 번에 수정할 수 있어 유지보수성이 향상됩니다.

  2. SQL 키워드 대소문자 불일치: 쿼리 내에서 current_dateCURRENT_DATE가 함께 사용되고 있습니다. 기능적으로는 문제가 없지만, 코드의 일관성을 위해 하나의 스타일(예: 소문자)로 통일하는 것이 좋습니다.

            WHERE p.startDate >= current_date - 7 and (p.endDate is null or p.endDate >= current_date)")

List<PartnershipRestaurant> findAllWithDetails();
}