diff --git a/src/main/java/cz/muni/fi/pa165/icehockeymanager/services/GameServiceImpl.java b/src/main/java/cz/muni/fi/pa165/icehockeymanager/services/GameServiceImpl.java index 18a1039722d8e06ee1d996f677c7d336a2078e99..e79d954950d6076a1817c016f2ebd13ce5d00d1c 100644 --- a/src/main/java/cz/muni/fi/pa165/icehockeymanager/services/GameServiceImpl.java +++ b/src/main/java/cz/muni/fi/pa165/icehockeymanager/services/GameServiceImpl.java @@ -1,6 +1,7 @@ package cz.muni.fi.pa165.icehockeymanager.services; 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.Team; import org.springframework.beans.factory.annotation.Autowired; @@ -57,6 +58,9 @@ public class GameServiceImpl implements GameService { @Override 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); gameDao.update(game); }