From 8768fd7d8158e1697f39adb9919b2a4c4d634a0c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 22 May 2025 19:42:49 +0200 Subject: [PATCH] Refactor event handling and group assignment logic Replaced `fight.event` with `event.eventID` for consistency and improved event handling. Adjusted `setGroup` to accept `Integer` instead of `EventGroup` to simplify group assignment logic. Removed unused `event` field in `CreateEventFight` and streamlined related processing. --- CommonCore/SQL/src/de/steamwar/sql/EventFight.java | 6 +++--- WebsiteBackend/src/de/steamwar/routes/EventFights.kt | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventFight.java b/CommonCore/SQL/src/de/steamwar/sql/EventFight.java index d23e7411..72b19b42 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventFight.java +++ b/CommonCore/SQL/src/de/steamwar/sql/EventFight.java @@ -153,9 +153,9 @@ public class EventFight implements Comparable { setFight.update(fight, fightID); } - public void setGroup(EventGroup group) { - setGroup.update(group.getId(), fightID); - this.groupId = group.getId(); + public void setGroup(Integer group) { + setGroup.update(group, fightID); + this.groupId = group; } public boolean hasFinished() { diff --git a/WebsiteBackend/src/de/steamwar/routes/EventFights.kt b/WebsiteBackend/src/de/steamwar/routes/EventFights.kt index bcdb1b6e..4823619f 100644 --- a/WebsiteBackend/src/de/steamwar/routes/EventFights.kt +++ b/WebsiteBackend/src/de/steamwar/routes/EventFights.kt @@ -74,7 +74,6 @@ data class UpdateEventFight( @Serializable data class CreateEventFight( - val event: Int, val spielmodus: String, val map: String, val blueTeam: Int, @@ -91,6 +90,8 @@ fun Route.configureEventFightRoutes() { call.respond(EventFight.getEvent(event.eventID).map { ResponseEventFight(it) }) } post { + val event = call.receiveEvent() ?: return@post + val fight = call.receiveNullable() if (fight == null) { call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid body")) @@ -98,7 +99,7 @@ fun Route.configureEventFightRoutes() { } val eventFight = EventFight.create( - fight.event, + event.eventID, Timestamp.from(Instant.ofEpochMilli(fight.start)), fight.spielmodus, fight.map, @@ -129,9 +130,9 @@ fun Route.configureEventFightRoutes() { if (updateFight.group != null) { if (updateFight.group == -1) { - fight.groupId = null + fight.setGroup(null) } else { - fight.groupId = updateFight.group + fight.setGroup(updateFight.group) } }