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:
+42
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user