Skip to content

Commit e13580d

Browse files
authored
Merge pull request #36 from HSU-capston/feat/#35
[#35]Feat: 게임 리스트 조회 API 구현
2 parents 702080c + 23c03eb commit e13580d

File tree

7 files changed

+88
-7
lines changed

7 files changed

+88
-7
lines changed

src/main/java/capstone/SportyUp/SportyUp_Server/converter/GameConverter.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,21 @@ public static GameResponseDTO.GameDateListDTO toGameDateListDTO(List<Game> gameL
5555
.gameDateList(dateList)
5656
.build();
5757
}
58+
59+
public static GameResponseDTO.GameInfoListDTO toGameInfoListDTO(List<Game> gameList){
60+
List<GameResponseDTO.GameInfoDTO> result = new ArrayList<>();
61+
for(Game game : gameList){
62+
result.add(GameResponseDTO.GameInfoDTO.builder()
63+
.id(game.getId())
64+
.sportsId(game.getSports().getId())
65+
.score(game.getScore())
66+
.playDate(game.getPlayDate())
67+
.build());
68+
}
69+
70+
return GameResponseDTO.GameInfoListDTO.builder()
71+
.gameInfoList(result)
72+
.build();
73+
74+
}
5875
}

src/main/java/capstone/SportyUp/SportyUp_Server/repository/GameRepository.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,23 @@ List<Game> findByUserIdAndYearAndMonth(
2727
@Param("year") Integer year,
2828
@Param("month") Integer month
2929
);
30+
31+
@Query("SELECT g FROM Game g WHERE g.user.id = :userId AND YEAR(g.playDate) = :year AND MONTH(g.playDate) = :month AND DAY(g.playDate) = :day ORDER BY g.playDate DESC")
32+
List<Game> findByUserIdAndPlayDate(
33+
@Param("userId") Long userId,
34+
@Param("year") Integer year,
35+
@Param("month") Integer month,
36+
@Param("day") Integer day
37+
);
38+
39+
@Query("SELECT g FROM Game g WHERE g.user.id = :userId AND g.sports.id = :sportsId AND YEAR(g.playDate) = :year AND MONTH(g.playDate) = :month AND DAY(g.playDate) = :day ORDER BY g.playDate DESC")
40+
List<Game> findByUserIdAndSportsIdAndPlayDate(
41+
@Param("userId") Long userId,
42+
@Param("sportsId") Long sportsId,
43+
@Param("year") Integer year,
44+
@Param("month") Integer month,
45+
@Param("day") Integer day
46+
);
47+
3048
}
3149

src/main/java/capstone/SportyUp/SportyUp_Server/service/GameService/GameQueryService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
import capstone.SportyUp.SportyUp_Server.web.DTO.GameDTO.GameResponseDTO;
44

5+
import java.time.LocalDate;
6+
57
public interface GameQueryService {
68
public GameResponseDTO.ChartDTO getChart(Long userId, Long sportsId);
79
public GameResponseDTO.GameDateListDTO getGameDateListAllCategory(Long userId, Integer year, Integer month);
810
public GameResponseDTO.GameDateListDTO getGameDateListOneCategory(Long userId, Integer year, Integer month, Long sportsId);
11+
public GameResponseDTO.GameInfoListDTO getGameListAllCategory(Long userId, LocalDate date);
12+
public GameResponseDTO.GameInfoListDTO getGameListOneCategory(Long userId, LocalDate date, Long sportsId);
913
}

src/main/java/capstone/SportyUp/SportyUp_Server/service/GameService/GameQueryServiceImpl.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import lombok.RequiredArgsConstructor;
1010
import org.springframework.stereotype.Service;
1111

12+
import java.time.LocalDate;
1213
import java.util.ArrayList;
1314
import java.util.List;
1415
import java.util.stream.Collectors;
@@ -89,4 +90,31 @@ public GameResponseDTO.GameDateListDTO getGameDateListOneCategory(Long userId, I
8990

9091
return GameConverter.toGameDateListDTO(distinctByDate);
9192
}
93+
94+
@Override
95+
public GameResponseDTO.GameInfoListDTO getGameListAllCategory(Long userId, LocalDate date) {
96+
97+
User user = userRepository.findById(userId).orElse(null);
98+
Integer year = date.getYear();
99+
Integer month = date.getMonthValue();
100+
Integer day = date.getDayOfMonth();
101+
102+
List<Game> gameList = gameRepository.findByUserIdAndPlayDate(userId, year, month, day);
103+
104+
105+
return GameConverter.toGameInfoListDTO(gameList);
106+
}
107+
108+
@Override
109+
public GameResponseDTO.GameInfoListDTO getGameListOneCategory(Long userId, LocalDate date, Long sportsId) {
110+
111+
User user = userRepository.findById(userId).orElse(null);
112+
Integer year = date.getYear();
113+
Integer month = date.getMonthValue();
114+
Integer day = date.getDayOfMonth();
115+
116+
List<Game> gameList = gameRepository.findByUserIdAndSportsIdAndPlayDate(userId, sportsId, year, month, day);
117+
118+
return GameConverter.toGameInfoListDTO(gameList);
119+
}
92120
}

src/main/java/capstone/SportyUp/SportyUp_Server/web/DTO/GameDTO/GameResponseDTO.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public static class GameDateListDTO{
2525
@AllArgsConstructor
2626
public static class GameInfoDTO{
2727
Long id; //게임 번호
28-
String sports; //스포츠 종목
29-
LocalDate playDate; //게임 진행 날짜
28+
Long sportsId; //스포츠 종목
29+
LocalDateTime playDate; //게임 진행 날짜
3030
Integer score; //점수
3131
}
3232

src/main/java/capstone/SportyUp/SportyUp_Server/web/controller/GameController.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,15 @@ public class GameController implements GameSpecification {
2222
private final GameQueryService gameQueryService;
2323

2424
@Override
25-
public ApiResponse<GameResponseDTO.GameInfoListDTO> getGameList(LocalDate date, String sports) {
26-
return null;
25+
public ApiResponse<GameResponseDTO.GameInfoListDTO> getGameListAllCategory(Long userId, LocalDate date) {
26+
27+
return ApiResponse.onSuccess(gameQueryService.getGameListAllCategory(userId, date));
28+
}
29+
30+
@Override
31+
public ApiResponse<GameResponseDTO.GameInfoListDTO> getGameListOneCategory(Long userId, LocalDate date, Long sportsId) {
32+
33+
return ApiResponse.onSuccess(gameQueryService.getGameListOneCategory(userId, date, sportsId));
2734
}
2835

2936
@Override

src/main/java/capstone/SportyUp/SportyUp_Server/web/controller/specification/GameSpecification.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@
1111

1212
public interface GameSpecification {
1313

14-
@GetMapping("")
15-
@Operation(summary = "게임 리스트 조회 API", description = "한 날짜에 진행된 게임들의 리스트를 보여주는 API입니다. QueryString으로 date, sports 필요")
14+
@GetMapping("/list")
15+
@Operation(summary = "게임 리스트 조회(전체종목) API", description = "한 날짜에 진행된 전체종목 게임들의 리스트를 보여주는 API입니다. QueryString으로 date필요")
1616
@ApiResponses({
1717
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"),
1818
})
19-
ApiResponse<GameResponseDTO.GameInfoListDTO> getGameList(@RequestParam LocalDate date, @RequestParam String sports);
19+
ApiResponse<GameResponseDTO.GameInfoListDTO> getGameListAllCategory(@RequestParam Long userId, @RequestParam LocalDate date);
20+
21+
@GetMapping("/{sportsId}/list")
22+
@Operation(summary = "게임 리스트 조회(한 개 종목) API", description = "한 날짜에 진행된 전체종목 게임들의 리스트를 보여주는 API입니다. QueryString으로 date필요, PathVariable로 sportsId 필요")
23+
@ApiResponses({
24+
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"),
25+
})
26+
ApiResponse<GameResponseDTO.GameInfoListDTO> getGameListOneCategory(@RequestParam Long userId, @RequestParam LocalDate date, @PathVariable Long sportsId);
2027

2128
@GetMapping("/dates")
2229
@Operation(summary = "캘린더 탭 조회(전체종목) API", description = "달력에서 전체종목으로 게임이 진행된 날짜를 표시하기 위한 API입니다. QueryString으로 year와 month 필요")

0 commit comments

Comments
 (0)