Fix history not loading
This commit is contained in:
parent
97e5d202bb
commit
23367b6dea
|
|
@ -14,6 +14,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
|
||||||
public ResponseEntity<ApiErrorDto> handleException(Exception ex) {
|
public ResponseEntity<ApiErrorDto> handleException(Exception ex) {
|
||||||
ApiErrorDto error = new ApiErrorDto();
|
ApiErrorDto error = new ApiErrorDto();
|
||||||
error.reason("Error: " + ex.getMessage());
|
error.reason("Error: " + ex.getMessage());
|
||||||
|
logger.error(ex.getMessage(), ex);
|
||||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(error);
|
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) {
|
private ResponseEntity<PunishmentHistoryDto> mapPunishmentHistory(PunishmentHistoryDto punishmentHistory, CompletableFuture<List<HistoryRecord>> historyRecords) {
|
||||||
historyRecords.join().forEach(historyRecord -> {
|
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()
|
PunishmentHistoryInnerDto innerDto = new PunishmentHistoryInnerDto()
|
||||||
.uuid(historyRecord.getUuid())
|
.uuid(historyRecord.getUuid())
|
||||||
.username(historyRecord.getPunishedName())
|
.username(historyRecord.getPunishedName())
|
||||||
.reason(PunishmentHistoryInnerDto.ReasonEnum.valueOf(historyRecord.getReason()))
|
.reason(historyRecord.getReason())
|
||||||
.punishedByUuid(historyRecord.getBannedByUuid())
|
.punishedByUuid(historyRecord.getBannedByUuid())
|
||||||
.punishedBy(historyRecord.getBannedByName())
|
.punishedBy(historyRecord.getBannedByName())
|
||||||
.removedBy(historyRecord.getRemovedByName())
|
.removedBy(historyRecord.getRemovedByName())
|
||||||
.punishmentTime(historyRecord.getTime())
|
.punishmentTime(historyRecord.getTime())
|
||||||
.expiryTime(historyRecord.getUntil())
|
.expiryTime(historyRecord.getUntil())
|
||||||
.removedReason(historyRecord.getRemovedByReason())
|
.removedReason(historyRecord.getRemovedByReason())
|
||||||
.type(historyRecord.getType());
|
.type(type);
|
||||||
punishmentHistory.add(innerDto);
|
punishmentHistory.add(innerDto);
|
||||||
});
|
});
|
||||||
return ResponseEntity.ok().body(punishmentHistory);
|
return ResponseEntity.ok().body(punishmentHistory);
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ public interface NameHistoryMapper {
|
||||||
FROM all_punishments
|
FROM all_punishments
|
||||||
INNER JOIN user_lookup
|
INNER JOIN user_lookup
|
||||||
ON user_lookup.uuid = all_punishments.uuid
|
ON user_lookup.uuid = all_punishments.uuid
|
||||||
WHERE all_punishments.${name_column} LIKE #{partialName}
|
WHERE ${name_column} LIKE #{partialName}
|
||||||
ORDER BY time DESC
|
ORDER BY time DESC
|
||||||
LIMIT #{limit} OFFSET #{offset}
|
LIMIT #{limit} OFFSET #{offset}
|
||||||
""")
|
""")
|
||||||
|
|
@ -79,7 +79,7 @@ public interface NameHistoryMapper {
|
||||||
removed_by_name, time, until, removed_by_reason
|
removed_by_name, time, until, removed_by_reason
|
||||||
FROM ${tableName} AS punishment
|
FROM ${tableName} AS punishment
|
||||||
INNER JOIN user_lookup ON user_lookup.uuid = punishment.uuid
|
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}
|
LIMIT #{limit} OFFSET #{offset}
|
||||||
""")
|
""")
|
||||||
List<HistoryRecord> getRecentHistory(@Param("tableName") String tableName,
|
List<HistoryRecord> getRecentHistory(@Param("tableName") String tableName,
|
||||||
|
|
|
||||||
|
|
@ -167,10 +167,10 @@ components:
|
||||||
reason:
|
reason:
|
||||||
type: string
|
type: string
|
||||||
description: The reason for the punishment
|
description: The reason for the punishment
|
||||||
enum: [ ban, mute, kick, warn ]
|
|
||||||
type:
|
type:
|
||||||
type: string
|
type: string
|
||||||
description: The type of punishment
|
description: The type of punishment
|
||||||
|
enum: [ ban, mute, kick, warn ]
|
||||||
punishmentTime:
|
punishmentTime:
|
||||||
type: integer
|
type: integer
|
||||||
format: int64
|
format: int64
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user