From 7baa2f1a65d143d6d856f616d34b1f5729ec102d Mon Sep 17 00:00:00 2001 From: gsd Date: Sat, 11 Mar 2023 11:28:03 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B1=D0=B0=D0=BD=20=D0=BB=D0=B8=D1=81=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/app/controllers/admin/BanController.java | 10 ++++++++++ src/main/java/app/services/db/BanService.java | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/src/main/java/app/controllers/admin/BanController.java b/src/main/java/app/controllers/admin/BanController.java index 22165a8..bded89f 100644 --- a/src/main/java/app/controllers/admin/BanController.java +++ b/src/main/java/app/controllers/admin/BanController.java @@ -1,5 +1,6 @@ package app.controllers.admin; +import app.annotations.enums.AuthMethod; import app.annotations.interfaces.CheckPermitionFlag; import app.annotations.interfaces.CheckWebAccess; import app.entities.db.Ban; @@ -66,4 +67,13 @@ public class BanController { profileService.GetProfile(admin_steam64, List.of())); return result ? new ResponseEntity(result, HttpStatus.OK) : new ResponseEntity(result, HttpStatus.NOT_FOUND); } + + @GetMapping("/list") + @CheckWebAccess(auth_method = AuthMethod.SECRET_KEY) + public ResponseEntity banList( + HttpServletRequest request, + @RequestParam(required = false, defaultValue = "10") Integer limit + ){ + return new ResponseEntity(banService.getLastBans(limit), HttpStatus.OK); + } } diff --git a/src/main/java/app/services/db/BanService.java b/src/main/java/app/services/db/BanService.java index abe2bff..03c3f8d 100644 --- a/src/main/java/app/services/db/BanService.java +++ b/src/main/java/app/services/db/BanService.java @@ -47,6 +47,14 @@ public class BanService { return result.stream().map(Ban::new).toList(); } + public List getLastBans(Integer limit) { + return entityManager.createNativeQuery("SELECT * FROM `light_bans` WHERE `active` = ?1 ORDER BY `light_bans`.`id` DESC LIMIT ?2") + .setParameter(1, 1) + .setParameter(2, limit) + .getResultStream().map(obj -> new Ban((Object[]) obj)).toList(); + //этот каст конечно пиздец, но он работает + } + public Long getBansCount(SteamID steamID) { return (Long) entityManager.createNativeQuery("SELECT COUNT(*) FROM light_bans WHERE account_id = ?1 AND active = 0").getSingleResult(); }