Skip to content

Commit

Permalink
[FEAT] 리그 관리를 위한 전체조회 기능 구현 #217
Browse files Browse the repository at this point in the history
  • Loading branch information
Zena0128 committed Sep 19, 2024
1 parent e965f3c commit 0998017
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,15 @@
import com.sports.server.command.member.domain.Member;
import com.sports.server.common.application.EntityUtils;
import com.sports.server.common.exception.NotFoundException;
import com.sports.server.query.dto.response.LeagueDetailResponse;
import com.sports.server.query.dto.response.LeagueResponse;
import com.sports.server.query.dto.response.LeagueResponseWithGames;
import com.sports.server.query.dto.response.LeagueResponseWithInProgressGames;
import com.sports.server.query.dto.response.LeagueSportResponse;
import com.sports.server.query.dto.response.LeagueTeamDetailResponse;
import com.sports.server.query.dto.response.LeagueTeamPlayerResponse;
import com.sports.server.query.dto.response.LeagueTeamResponse;
import com.sports.server.query.dto.response.*;
import com.sports.server.query.repository.GameQueryRepository;
import com.sports.server.query.repository.LeagueQueryRepository;
import com.sports.server.query.repository.LeagueSportQueryRepository;
import com.sports.server.query.repository.LeagueTeamDynamicRepository;
import com.sports.server.query.repository.LeagueTeamPlayerQueryRepository;
import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -113,4 +108,21 @@ public LeagueResponseWithGames findLeagueAndGames(final Long leagueId) {
List<Game> games = gameQueryRepository.findByLeagueWithGameTeams(league);
return LeagueResponseWithGames.of(league, games);
}

public List<LeagueResponseToManage> findLeaguesByManagerToManage(final Member manager) {
List<League> leagues = leagueQueryRepository.findByManagerToManage(manager);

Map<String, Integer> orderMap = new HashMap<>();
orderMap.put(LeagueProgress.IN_PROGRESS.getDescription(), 1);
orderMap.put(LeagueProgress.BEFORE_START.getDescription(), 2);
orderMap.put(LeagueProgress.FINISHED.getDescription(), 3);

Comparator<League> comparator = Comparator.comparing(
league -> orderMap.get(LeagueProgress.getProgressDescription(LocalDateTime.now(), league)));

return leagues.stream()
.sorted(comparator)
.map(LeagueResponseToManage::new)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.sports.server.query.dto.response;

import com.sports.server.command.game.domain.Game;
import com.sports.server.command.league.domain.League;
import com.sports.server.command.league.domain.LeagueProgress;

import java.time.LocalDateTime;
import java.util.List;

public record LeagueResponseToManage(
Long id,
String name,
String leagueProgress,
int sizeOfLeagueTeams,
String maxRound,
LocalDateTime startAt,
LocalDateTime endAt
) {
public LeagueResponseToManage(League league) {
this(
league.getId(),
league.getName(),
LeagueProgress.getProgressDescription(LocalDateTime.now(), league),
league.getLeagueTeams().size(),
league.getMaxRound().getDescription(),
league.getStartAt(),
league.getEndAt()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

import com.sports.server.command.member.domain.Member;
import com.sports.server.query.application.LeagueQueryService;
import com.sports.server.query.dto.response.LeagueDetailResponse;
import com.sports.server.query.dto.response.LeagueResponse;
import com.sports.server.query.dto.response.LeagueResponseWithGames;
import com.sports.server.query.dto.response.LeagueResponseWithInProgressGames;
import com.sports.server.query.dto.response.LeagueSportResponse;
import com.sports.server.query.dto.response.LeagueTeamDetailResponse;
import com.sports.server.query.dto.response.LeagueTeamPlayerResponse;
import com.sports.server.query.dto.response.LeagueTeamResponse;
import com.sports.server.query.dto.response.*;

import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -67,4 +61,9 @@ public ResponseEntity<LeagueTeamDetailResponse> findLeagueTeam(@PathVariable fin
public ResponseEntity<LeagueResponseWithGames> findLeagueAndGames(@PathVariable final Long leagueId) {
return ResponseEntity.ok(leagueQueryService.findLeagueAndGames(leagueId));
}

@GetMapping("/manager/manage")
public ResponseEntity<List<LeagueResponseToManage>> findLeaguesByManagerToManage(final Member manager) {
return ResponseEntity.ok(leagueQueryService.findLeaguesByManagerToManage(manager));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public interface LeagueQueryRepository extends Repository<League, Long>, LeagueQ
)
List<League> findByManager(Member member);

@Query(
"SELECT l FROM League l "
+ "WHERE l.manager =:member"
)
List<League> findByManagerToManage(Member member);

@Query(
"SELECT l FROM League l "
+ "JOIN FETCH l.leagueTeams "
Expand Down

0 comments on commit 0998017

Please sign in to comment.