Merge remote-tracking branch 'origin/master'

This commit is contained in:
Peter 2025-04-11 23:36:14 +02:00
commit 6526bad733
6 changed files with 107 additions and 7 deletions

View File

@ -1,6 +1,7 @@
package com.alttd.altitudeweb.controllers.history; package com.alttd.altitudeweb.controllers.history;
import com.alttd.altitudeweb.api.HistoryApi; import com.alttd.altitudeweb.api.HistoryApi;
import com.alttd.altitudeweb.model.HistoryCountDto;
import com.alttd.altitudeweb.setup.Connection; import com.alttd.altitudeweb.setup.Connection;
import com.alttd.altitudeweb.database.Databases; import com.alttd.altitudeweb.database.Databases;
import com.alttd.altitudeweb.database.litebans.*; import com.alttd.altitudeweb.database.litebans.*;
@ -88,6 +89,34 @@ public class HistoryApiController implements HistoryApi {
return ResponseEntity.ok().body(playerGroupFuture.join()); return ResponseEntity.ok().body(playerGroupFuture.join());
} }
@Override
public ResponseEntity<HistoryCountDto> getTotalPunishments() {
CompletableFuture<HistoryCount> historyCountCompletableFuture = new CompletableFuture<>();
Connection.getConnection(Databases.LITE_BANS)
.runQuery(sqlSession -> {
log.debug("Loading history count");
try {
HistoryCount punishmentCounts = sqlSession.getMapper(HistoryCountMapper.class)
.getPunishmentCounts();
historyCountCompletableFuture.complete(punishmentCounts);
} catch (Exception e) {
log.error("Failed to load history count", e);
historyCountCompletableFuture.completeExceptionally(e);
}
});
return mapHistoryCount(historyCountCompletableFuture.join());
}
private ResponseEntity<HistoryCountDto> mapHistoryCount(HistoryCount historyCount) {
HistoryCountDto historyCountDto = new HistoryCountDto();
historyCountDto.setBans(historyCount.getBans());
historyCountDto.setMutes(historyCount.getMutes());
historyCountDto.setWarnings(historyCount.getWarnings());
historyCountDto.setKicks(historyCount.getKicks());
return ResponseEntity.ok().body(historyCountDto);
}
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()) { PunishmentHistoryInnerDto.TypeEnum type = switch (historyRecord.getType().toLowerCase()) {

View File

@ -0,0 +1,11 @@
package com.alttd.altitudeweb.database.litebans;
import lombok.Data;
@Data
public class HistoryCount {
private int bans;
private int mutes;
private int warnings;
private int kicks;
}

View File

@ -0,0 +1,20 @@
package com.alttd.altitudeweb.database.litebans;
import org.apache.ibatis.annotations.Select;
public interface HistoryCountMapper {
/**
* Gets the total count of punishments from all LiteBans tables.
*
* @return A PunishmentCount object containing counts from each table
*/
@Select({"""
SELECT
(SELECT COUNT(*) FROM litebans_bans) AS bans,
(SELECT COUNT(*) FROM litebans_mutes) AS mutes,
(SELECT COUNT(*) FROM litebans_warnings) AS warnings,
(SELECT COUNT(*) FROM litebans_kicks) AS kicks
"""
})
HistoryCount getPunishmentCounts();
}

View File

@ -1,9 +1,7 @@
package com.alttd.altitudeweb.setup; package com.alttd.altitudeweb.setup;
import com.alttd.altitudeweb.database.Databases; import com.alttd.altitudeweb.database.Databases;
import com.alttd.altitudeweb.database.litebans.NameHistoryMapper; import com.alttd.altitudeweb.database.litebans.*;
import com.alttd.altitudeweb.database.litebans.RecentNamesMapper;
import com.alttd.altitudeweb.database.litebans.UUIDHistoryMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSession;
@ -19,6 +17,7 @@ public class InitializeLiteBans {
configuration.addMapper(RecentNamesMapper.class); configuration.addMapper(RecentNamesMapper.class);
configuration.addMapper(NameHistoryMapper.class); configuration.addMapper(NameHistoryMapper.class);
configuration.addMapper(UUIDHistoryMapper.class); configuration.addMapper(UUIDHistoryMapper.class);
configuration.addMapper(HistoryCountMapper.class);
}).join() }).join()
.runQuery(sqlSession -> { .runQuery(sqlSession -> {
createAllPunishmentsView(sqlSession); createAllPunishmentsView(sqlSession);

View File

@ -22,3 +22,5 @@ paths:
$ref: './schemas/bans/bans.yml#/getHistoryForAll' $ref: './schemas/bans/bans.yml#/getHistoryForAll'
/history/{userType}/uuid/{type}/{uuid}/{page}: /history/{userType}/uuid/{type}/{uuid}/{page}:
$ref: './schemas/bans/bans.yml#/getHistoryForUuid' $ref: './schemas/bans/bans.yml#/getHistoryForUuid'
/history/total:
$ref: './schemas/bans/bans.yml#/getTotalPunishments'

View File

@ -23,7 +23,7 @@ getUserNames:
content: content:
application/json: application/json:
schema: schema:
$ref: "../generic/errors.yml#/components/schemas/ApiError" $ref: '../generic/errors.yml#/components/schemas/ApiError'
getHistoryForUsers: getHistoryForUsers:
get: get:
tags: tags:
@ -50,7 +50,7 @@ getHistoryForUsers:
content: content:
application/json: application/json:
schema: schema:
$ref: "../generic/errors.yml#/components/schemas/ApiError" $ref: '../generic/errors.yml#/components/schemas/ApiError'
getHistoryForAll: getHistoryForAll:
get: get:
tags: tags:
@ -76,7 +76,7 @@ getHistoryForAll:
content: content:
application/json: application/json:
schema: schema:
$ref: "../generic/errors.yml#/components/schemas/ApiError" $ref: '../generic/errors.yml#/components/schemas/ApiError'
getHistoryForUuid: getHistoryForUuid:
get: get:
tags: tags:
@ -103,7 +103,27 @@ getHistoryForUuid:
content: content:
application/json: application/json:
schema: schema:
$ref: "../generic/errors.yml#/components/schemas/ApiError" $ref: '../generic/errors.yml#/components/schemas/ApiError'
getTotalPunishments:
get:
tags:
- history
summary: Get total history count per type
description: Retrieves the total count of punishments for each type available (ban, mute, kick, warn, or all).
operationId: getTotalPunishments
responses:
'200':
description: Successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/HistoryCount'
default:
description: Unexpected error
content:
application/json:
schema:
$ref: '../generic/errors.yml#/components/schemas/ApiError'
components: components:
parameters: parameters:
HistoryType: HistoryType:
@ -205,3 +225,22 @@ components:
required: required:
- name - name
- uuid - uuid
HistoryCount:
type: object
properties:
bans:
type: integer
description: The total amounts of bans
example: 10528
mutes:
type: integer
description: The total amounts of mutes
example: 2350
warnings:
type: integer
description: The total amounts of warnings
example: 3881
kicks:
type: integer
description: The total amounts of kicks
example: 1769