Fix history not loading

This commit is contained in:
2025-04-11 21:37:21 +02:00
parent 97e5d202bb
commit 23367b6dea
4 changed files with 13 additions and 5 deletions
@@ -14,6 +14,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
public ResponseEntity<ApiErrorDto> 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);
}
}
@@ -90,17 +90,24 @@ public class HistoryApiController implements HistoryApi {
private ResponseEntity<PunishmentHistoryDto> mapPunishmentHistory(PunishmentHistoryDto punishmentHistory, CompletableFuture<List<HistoryRecord>> 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);