forked from SteamWar/SteamWar
Refactor EventRelation: Fix query logic for byEvent, adjust insert fields, and update setFrom parameter handling. Update ResponseRelation to align with updated EventRelation structure.
This commit is contained in:
@@ -43,14 +43,14 @@ public class EventRelation {
|
||||
|
||||
private static final SelectStatement<EventRelation> get = new SelectStatement<>(table, "SELECT * FROM EventRelation WHERE FromType = ? AND FromId = ?");
|
||||
private static final SelectStatement<EventRelation> byId = new SelectStatement<>(table, "SELECT * FROM EventRelation WHERE id = ?");
|
||||
private static final SelectStatement<EventRelation> 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<EventRelation> 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<EventRelation> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user