Skip to content
Snippets Groups Projects
Commit 43f174d5 authored by Erik Moravec's avatar Erik Moravec
Browse files

feat: update game score functionality implemented along with relevant service...

feat: update game score functionality implemented along with relevant service functionality and with calculation/update of the game winner if some of the teams becomes winning with the new score
parent 38755411
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,7 @@ public interface LeagueManagerFacade {
void dropGame(long gameId);
void updateGameScore(int homeTeamScore, int awayTeamScore);
void updateGameScore(long gameId, int homeTeamScore, int awayTeamScore);
void setGameWinner(long gameId, long teamId);
......
......@@ -3,7 +3,9 @@ package cz.muni.fi.pa165.icehockeymanager.facades;
import cz.muni.fi.pa165.icehockeymanager.dto.GameCreateDTO;
import cz.muni.fi.pa165.icehockeymanager.dto.TeamCreateDTO;
import cz.muni.fi.pa165.icehockeymanager.exceptions.UnknownGameException;
import cz.muni.fi.pa165.icehockeymanager.exceptions.UnknownTeamException;
import cz.muni.fi.pa165.icehockeymanager.model.Game;
import cz.muni.fi.pa165.icehockeymanager.model.Team;
import cz.muni.fi.pa165.icehockeymanager.services.BeanMappingService;
import cz.muni.fi.pa165.icehockeymanager.services.GameService;
import cz.muni.fi.pa165.icehockeymanager.services.PlayerService;
......@@ -42,13 +44,21 @@ public class LeagueManagerFacadeImpl implements LeagueManagerFacade {
}
@Override
public void updateGameScore(int homeTeamScore, int awayTeamScore) {
public void updateGameScore(long gameId, int homeTeamScore, int awayTeamScore) {
Game game = gameService.findGame(gameId).orElseThrow(
() -> new UnknownGameException("Game not found")
);
gameService.updateGameScore(game, homeTeamScore, awayTeamScore);
}
@Override
public void setGameWinner(long gameId, long teamId) {
Game game = gameService.findGame(gameId).orElseThrow(
() -> new UnknownGameException("Game not found")
);
Team team = teamService.getTeam(teamId).orElseThrow(
() -> new UnknownTeamException("Team not found")
);
}
@Override
......
......@@ -22,4 +22,6 @@ public interface GameService {
Optional<Game> findGame(long gameId);
void deleteGame(Game game);
void updateGameScore(Game game, int homeTeamScore, int awayTeamScore);
}
......@@ -39,4 +39,18 @@ public class GameServiceImpl implements GameService {
public void deleteGame(Game game) {
gameDao.delete(game);
}
@Override
public void updateGameScore(Game game, int homeTeamScore, int awayTeamScore) {
game.setHomeTeamScore(homeTeamScore);
game.setAwayTeamScore(awayTeamScore);
if (homeTeamScore > awayTeamScore) {
game.setWinner(game.getHomeTeam());
} else if (awayTeamScore > homeTeamScore) {
game.setWinner(game.getAwayTeam());
} else {
game.setWinner(null);
}
gameDao.update(game);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment