Add API endpoints for search result counts by name and UUID

Introduced new API paths and backend logic to retrieve total punishment counts based on user search queries using names or UUIDs. Updated the frontend to utilize these endpoints and display the total search results dynamically.
This commit is contained in:
2025-04-18 20:43:17 +02:00
parent ee66bdda83
commit ecee377f01
6 changed files with 216 additions and 16 deletions
@@ -111,6 +111,48 @@ public class HistoryApiController implements HistoryApi {
return mapHistoryCount(historyCountCompletableFuture.join());
}
@Override
public ResponseEntity<Integer> getTotalResultsForUserSearch(String userType, String type, String user) {
UserType userTypeEnum = UserType.getUserType(userType);
HistoryType historyTypeEnum = HistoryType.getHistoryType(type);
CompletableFuture<Integer> searchResultCountCompletableFuture = new CompletableFuture<>();
Connection.getConnection(Databases.LITE_BANS)
.runQuery(sqlSession -> {
log.debug("Loading name search result count");
try {
Integer punishmentCount = sqlSession.getMapper(HistoryCountMapper.class)
.getNamePunishmentCount(historyTypeEnum, userTypeEnum, user);
searchResultCountCompletableFuture.complete(punishmentCount);
} catch (Exception e) {
log.error("Failed to load history count", e);
searchResultCountCompletableFuture.completeExceptionally(e);
}
});
return ResponseEntity.ok().body(searchResultCountCompletableFuture.join());
}
@Override
public ResponseEntity<Integer> getTotalResultsForUuidSearch(String userType, String type, String uuid) {
UserType userTypeEnum = UserType.getUserType(userType);
HistoryType historyTypeEnum = HistoryType.getHistoryType(type);
CompletableFuture<Integer> searchResultCountCompletableFuture = new CompletableFuture<>();
Connection.getConnection(Databases.LITE_BANS)
.runQuery(sqlSession -> {
log.debug("Loading uuid search result count");
try {
Integer punishmentCount = sqlSession.getMapper(HistoryCountMapper.class)
.getUuidPunishmentCount(historyTypeEnum, userTypeEnum, UUID.fromString(uuid));
searchResultCountCompletableFuture.complete(punishmentCount);
} catch (Exception e) {
log.error("Failed to load history count", e);
searchResultCountCompletableFuture.completeExceptionally(e);
}
});
return ResponseEntity.ok().body(searchResultCountCompletableFuture.join());
}
private ResponseEntity<HistoryCountDto> mapHistoryCount(HistoryCount historyCount) {
HistoryCountDto historyCountDto = new HistoryCountDto();
historyCountDto.setBans(historyCount.getBans());