Skip to content

Commit

Permalink
Disallow adding already existing games
Browse files Browse the repository at this point in the history
  • Loading branch information
JJtan2002 committed Nov 1, 2024
1 parent 0a58c97 commit ea120a1
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class AddGameCommand extends Command {
+ PREFIX_USERNAME + "johndoe420";

public static final String MESSAGE_ADD_GAME_SUCCESS = "Added Game to Person: %1$s";
public static final String MESSAGE_GAME_EXISTS = "The game provided already exists for that person.";

private final Index index;
private final AddGameDescriptor addGameDescriptor;
private final String gameName;
Expand Down Expand Up @@ -77,6 +79,10 @@ public CommandResult execute(Model model) throws CommandException {
personToEdit = lastShownList.get(index.getZeroBased());
Map<String, Game> gameMap = personToEdit.getGames();

if (gameMap.containsKey(gameName)) {
throw new CommandException(MESSAGE_GAME_EXISTS);
}

Game editedGame = createNewGame(gameName, addGameDescriptor);
gameMap.put(gameName, editedGame);
model.setPerson(personToEdit, personToEdit);
Expand Down

0 comments on commit ea120a1

Please sign in to comment.