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

fix: added check to setGameWinner to only allow one of the team playing or none to be the winner

parent 002e4148
No related branches found
No related tags found
No related merge requests found
package cz.muni.fi.pa165.icehockeymanager.services; package cz.muni.fi.pa165.icehockeymanager.services;
import cz.muni.fi.pa165.icehockeymanager.dao.GameDao; import cz.muni.fi.pa165.icehockeymanager.dao.GameDao;
import cz.muni.fi.pa165.icehockeymanager.exceptions.UnknownTeamException;
import cz.muni.fi.pa165.icehockeymanager.model.Game; import cz.muni.fi.pa165.icehockeymanager.model.Game;
import cz.muni.fi.pa165.icehockeymanager.model.Team; import cz.muni.fi.pa165.icehockeymanager.model.Team;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -57,6 +58,9 @@ public class GameServiceImpl implements GameService { ...@@ -57,6 +58,9 @@ public class GameServiceImpl implements GameService {
@Override @Override
public void setGameWinner(Game game, Team team) { public void setGameWinner(Game game, Team team) {
if (team != null &&!team.equals(game.getHomeTeam()) && !team.equals(game.getAwayTeam())) {
throw new UnknownTeamException("The winner is not part of this game");
}
game.setWinner(team); game.setWinner(team);
gameDao.update(game); 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