Browse Source

бан лист

master
gsd 2 years ago
parent
commit
7baa2f1a65
  1. 10
      src/main/java/app/controllers/admin/BanController.java
  2. 8
      src/main/java/app/services/db/BanService.java

10
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);
}
}

8
src/main/java/app/services/db/BanService.java

@ -47,6 +47,14 @@ public class BanService {
return result.stream().map(Ban::new).toList();
}
public List<Ban> 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();
}

Loading…
Cancel
Save