From 21d628b33861432933b5517f7841c33d79a2d8cc Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 28 Sep 2025 10:28:24 +0200 Subject: [PATCH] Refactor `EventRelation`: Fix query logic for `byEvent`, adjust insert fields, and update `setFrom` parameter handling. Update `ResponseRelation` to align with updated `EventRelation` structure. --- .../SQL/src/de/steamwar/sql/EventRelation.java | 12 ++++++------ WebsiteBackend/src/de/steamwar/routes/Events.kt | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java b/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java index a4a93687..539908de 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java +++ b/CommonCore/SQL/src/de/steamwar/sql/EventRelation.java @@ -43,14 +43,14 @@ public class EventRelation { private static final SelectStatement get = new SelectStatement<>(table, "SELECT * FROM EventRelation WHERE FromType = ? AND FromId = ?"); private static final SelectStatement byId = new SelectStatement<>(table, "SELECT * FROM EventRelation WHERE id = ?"); - private static final SelectStatement byEvent = new SelectStatement<>(table, "SELECT ER.* FROM EventRelation ER JOIN EventFight EF ON EF.id = ER.fightId WHERE EF.EventID = ?"); - private static final Statement insert = table.insertAll(true); + private static final SelectStatement byEvent = new SelectStatement<>(table, "SELECT ER.* FROM EventRelation ER JOIN EventFight EF ON EF.fightId = ER.fightId WHERE EF.EventID = ?"); + private static final Statement insert = table.insertFields(true, "fightId", "fightTeam", "fromType", "fromId", "fromPlace"); private static final Statement update = table.update(Table.PRIMARY, "fromType", "fromId", "fromPlace"); private static final Statement updateTeam = table.update(Table.PRIMARY, "fightTeam"); private static final Statement delete = table.delete(Table.PRIMARY); public static List get(Event event) { - return byId.listSelect(event.getEventID()); + return byEvent.listSelect(event.getEventID()); } public static EventRelation get(int id) { @@ -125,10 +125,10 @@ public class EventRelation { setFrom(group.getId(), place, FromType.GROUP); } - private void setFrom(int id, int place, FromType type) { - update.update(id, type, id, place); + private void setFrom(int fightId, int place, FromType type) { + update.update(type, fightId, place, id); this.fromType = type; - this.fromId = id; + this.fromId = fightId; this.fromPlace = place; } diff --git a/WebsiteBackend/src/de/steamwar/routes/Events.kt b/WebsiteBackend/src/de/steamwar/routes/Events.kt index 8dbb3993..34e337ce 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Events.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Events.kt @@ -63,7 +63,8 @@ data class ResponseGroups( @Serializable data class ResponseRelation( val id: Int, - val fight: ResponseEventFight, + val fight: Int, + val team: EventRelation.FightTeam, val type: FromType, val fromFight: ResponseEventFight? = null, val fromGroup: ResponseGroups? = null, @@ -71,7 +72,8 @@ data class ResponseRelation( ) { constructor(relation: EventRelation) : this( relation.id, - ResponseEventFight(relation.fight), + relation.fightId, + relation.fightTeam, relation.fromType, relation.fromFight.map { ResponseEventFight(it) }.orElse(null), relation.fromGroup.map { ResponseGroups(it) }.orElse(null),