Skip to content

Commit

Permalink
[#6] feat: Implements getting game list API
Browse files Browse the repository at this point in the history
  • Loading branch information
isaac56 committed May 7, 2021
1 parent f90d289 commit 6aa30fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public ApiGameController(GameService gameService) {
this.gameService = gameService;
}

@GetMapping("/list")
public ApiResult getGameDescriptions() {
return ApiResult.succeed(gameService.getAllGameList());
}

@PostMapping
public ApiResult createGame() {
gameService.createNewGame(1l, 1, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import team9.baseball.DTO.response.GameDescriptionDTO;
import team9.baseball.DTO.response.GameStatusDTO;
import team9.baseball.domain.aggregate.game.Game;
import team9.baseball.domain.aggregate.team.Team;
Expand All @@ -13,6 +14,8 @@
import team9.baseball.repository.TeamRepository;
import team9.baseball.repository.UserRepository;

import java.util.List;

@Service
public class GameService {
private final GameRepository gameRepository;
Expand Down Expand Up @@ -90,6 +93,10 @@ public void joinGame(long userId, long gameId, Venue venue) {
userRepository.save(user);
}

public List<GameDescriptionDTO> getAllGameList() {
return gameRepository.findAllGameDescription();
}

private User getUser(long userId) {
return userRepository.findById(userId).orElseThrow(() -> new NotFoundException(userId + " 사용자는 존재하지 않습니다."));
}
Expand Down

0 comments on commit 6aa30fb

Please sign in to comment.