From 23367b6dea4c70c9c10f3b742f73560e37d82c19 Mon Sep 17 00:00:00 2001 From: Teriuihi Date: Fri, 11 Apr 2025 21:37:21 +0200 Subject: [PATCH] Fix history not loading --- .../controllers/GlobalExceptionHandler.java | 1 + .../controllers/history/HistoryApiController.java | 11 +++++++++-- .../database/litebans/NameHistoryMapper.java | 4 ++-- open_api/src/main/resources/schemas/bans/bans.yml | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/com/alttd/altitudeweb/controllers/GlobalExceptionHandler.java b/backend/src/main/java/com/alttd/altitudeweb/controllers/GlobalExceptionHandler.java index 17eb4ef..366c8a8 100644 --- a/backend/src/main/java/com/alttd/altitudeweb/controllers/GlobalExceptionHandler.java +++ b/backend/src/main/java/com/alttd/altitudeweb/controllers/GlobalExceptionHandler.java @@ -14,6 +14,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { public ResponseEntity handleException(Exception ex) { ApiErrorDto error = new ApiErrorDto(); error.reason("Error: " + ex.getMessage()); + logger.error(ex.getMessage(), ex); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(error); } } diff --git a/backend/src/main/java/com/alttd/altitudeweb/controllers/history/HistoryApiController.java b/backend/src/main/java/com/alttd/altitudeweb/controllers/history/HistoryApiController.java index d46b398..3ffabc3 100644 --- a/backend/src/main/java/com/alttd/altitudeweb/controllers/history/HistoryApiController.java +++ b/backend/src/main/java/com/alttd/altitudeweb/controllers/history/HistoryApiController.java @@ -90,17 +90,24 @@ public class HistoryApiController implements HistoryApi { private ResponseEntity mapPunishmentHistory(PunishmentHistoryDto punishmentHistory, CompletableFuture> historyRecords) { historyRecords.join().forEach(historyRecord -> { + PunishmentHistoryInnerDto.TypeEnum type = switch (historyRecord.getType().toLowerCase()) { + case "ban" -> PunishmentHistoryInnerDto.TypeEnum.BAN; + case "mute" -> PunishmentHistoryInnerDto.TypeEnum.MUTE; + case "warn" -> PunishmentHistoryInnerDto.TypeEnum.WARN; + case "kick" -> PunishmentHistoryInnerDto.TypeEnum.KICK; + default -> throw new IllegalStateException("Unexpected value: " + historyRecord.getType()); + }; PunishmentHistoryInnerDto innerDto = new PunishmentHistoryInnerDto() .uuid(historyRecord.getUuid()) .username(historyRecord.getPunishedName()) - .reason(PunishmentHistoryInnerDto.ReasonEnum.valueOf(historyRecord.getReason())) + .reason(historyRecord.getReason()) .punishedByUuid(historyRecord.getBannedByUuid()) .punishedBy(historyRecord.getBannedByName()) .removedBy(historyRecord.getRemovedByName()) .punishmentTime(historyRecord.getTime()) .expiryTime(historyRecord.getUntil()) .removedReason(historyRecord.getRemovedByReason()) - .type(historyRecord.getType()); + .type(type); punishmentHistory.add(innerDto); }); return ResponseEntity.ok().body(punishmentHistory); diff --git a/database/src/main/java/com/alttd/altitudeweb/database/litebans/NameHistoryMapper.java b/database/src/main/java/com/alttd/altitudeweb/database/litebans/NameHistoryMapper.java index fc1d1bf..bc97d23 100644 --- a/database/src/main/java/com/alttd/altitudeweb/database/litebans/NameHistoryMapper.java +++ b/database/src/main/java/com/alttd/altitudeweb/database/litebans/NameHistoryMapper.java @@ -41,7 +41,7 @@ public interface NameHistoryMapper { FROM all_punishments INNER JOIN user_lookup ON user_lookup.uuid = all_punishments.uuid - WHERE all_punishments.${name_column} LIKE #{partialName} + WHERE ${name_column} LIKE #{partialName} ORDER BY time DESC LIMIT #{limit} OFFSET #{offset} """) @@ -79,7 +79,7 @@ public interface NameHistoryMapper { removed_by_name, time, until, removed_by_reason FROM ${tableName} AS punishment INNER JOIN user_lookup ON user_lookup.uuid = punishment.uuid - WHERE punishment.${name_column} LIKE #{partialName} + WHERE ${name_column} LIKE #{partialName} LIMIT #{limit} OFFSET #{offset} """) List getRecentHistory(@Param("tableName") String tableName, diff --git a/open_api/src/main/resources/schemas/bans/bans.yml b/open_api/src/main/resources/schemas/bans/bans.yml index 9ac71d1..3bc1a3c 100644 --- a/open_api/src/main/resources/schemas/bans/bans.yml +++ b/open_api/src/main/resources/schemas/bans/bans.yml @@ -167,10 +167,10 @@ components: reason: type: string description: The reason for the punishment - enum: [ ban, mute, kick, warn ] type: type: string description: The type of punishment + enum: [ ban, mute, kick, warn ] punishmentTime: type: integer format: int64