From 931965dee7ce491e9fda616b2acbf7b8aeddd0bc Mon Sep 17 00:00:00 2001 From: Software Magico Date: Fri, 10 May 2024 16:32:27 +0200 Subject: [PATCH] Avoding empty fights --- .../kt/core/controller/FightController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/controller/FightController.java b/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/controller/FightController.java index e8a5dedc8..8a073a6b2 100644 --- a/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/controller/FightController.java +++ b/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/controller/FightController.java @@ -30,6 +30,7 @@ import com.softwaremagico.kt.core.converters.models.FightConverterRequest; import com.softwaremagico.kt.core.converters.models.TournamentConverterRequest; import com.softwaremagico.kt.core.exceptions.TournamentNotFoundException; +import com.softwaremagico.kt.core.exceptions.ValidateBadRequestException; import com.softwaremagico.kt.core.managers.TeamsOrder; import com.softwaremagico.kt.core.providers.FightProvider; import com.softwaremagico.kt.core.providers.GroupProvider; @@ -90,6 +91,14 @@ public void addFightsAddedListeners(FightsAddedListener listener) { fightsAddedListeners.add(listener); } + @Override + public void validate(FightDTO dto) throws ValidateBadRequestException { + if (dto.getTeam1() == null || dto.getTeam2() == null || dto.getTeam1().getMembers() == null || dto.getTeam2().getMembers() == null + || dto.getTeam1().getMembers().isEmpty() || dto.getTeam2().getMembers().isEmpty() || dto.getShiaijo() == null || dto.getLevel() == null) { + throw new ValidateBadRequestException(this.getClass(), "Fight '" + dto + "' is malformed."); + } + } + @Override protected FightConverterRequest createConverterRequest(Fight entity) { return new FightConverterRequest(entity);