Skip to content

Commit

Permalink
[Feat] Group 정렬 조건 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
NARUBROWN committed Feb 14, 2024
1 parent 4db378f commit ee1d49d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ public interface GroupRepository extends JpaRepository<Group, Long> {
@Query("SELECT DISTINCT e.year FROM Group e ORDER BY e.year")
List<Double> findAllYears();

List<Group> findAllByYearAndPart(Double year, String part);
@Query("SELECT e FROM Group e WHERE e.year = :year AND e.part = :part ORDER BY CASE WHEN e.role.roleName = '파트장' THEN 0 ELSE 1 END, e.member.name")
List<Group> findAllByYearAndPartOrderByYear(Double year, String part);

List<Group> findAllByYear(Double year);
@Query("SELECT e FROM Group e WHERE e.year = :year ORDER BY CASE WHEN e.role.roleName = '파트장'THEN 0 ELSE 1 END, e.part")
List<Group> findAllByYearOrderByPart(Double year);

List<Group> findAllByPart(String part);
List<Group> findAllByPartOrderByYearDesc(String part);

@Query("SELECT DISTINCT e.part FROM Group e")
List<String> findAllParts();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ public GroupResponseDto getGroup(Long id) {
@Transactional(readOnly = true)
public List<GroupResponseDto> findAllGroup(Double year, String part) {
if (year != null && part != null) {
List<Group> foundGroups = groupRepository.findAllByYearAndPart(year, part);
List<Group> foundGroups = groupRepository.findAllByYearAndPartOrderByYear(year, part);
return foundGroups.stream()
.map(data -> data.toGroupResponseDto(data))
.collect(Collectors.toList());
} else if (year != null) {
List<Group> foundGroups = groupRepository.findAllByYear(year);
List<Group> foundGroups = groupRepository.findAllByYearOrderByPart(year);
return foundGroups.stream()
.map(data -> data.toGroupResponseDto(data))
.collect(Collectors.toList());
} else if (part != null) {
List<Group> foundGroups = groupRepository.findAllByPart(part);
List<Group> foundGroups = groupRepository.findAllByPartOrderByYearDesc(part);
return foundGroups.stream()
.map(data -> data.toGroupResponseDto(data))
.collect(Collectors.toList());
Expand Down

0 comments on commit ee1d49d

Please sign in to comment.