From d035184c9885a4722aec5614c6d47ad847c5c66e Mon Sep 17 00:00:00 2001 From: gsd Date: Sat, 11 Mar 2023 21:54:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=BD=D1=82=D0=B5=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D1=81=20=D0=B4=D0=B8=D1=81=D0=BA=D0=BE?= =?UTF-8?q?=D1=80=D0=B4=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/bot/DiscordVIPController.java | 38 +++++++++++++++++++ src/main/java/app/services/db/VIPService.java | 30 +++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/main/java/app/controllers/bot/DiscordVIPController.java create mode 100644 src/main/java/app/services/db/VIPService.java diff --git a/src/main/java/app/controllers/bot/DiscordVIPController.java b/src/main/java/app/controllers/bot/DiscordVIPController.java new file mode 100644 index 0000000..be32100 --- /dev/null +++ b/src/main/java/app/controllers/bot/DiscordVIPController.java @@ -0,0 +1,38 @@ +package app.controllers.bot; + +import app.annotations.enums.AuthMethod; +import app.annotations.interfaces.CheckWebAccess; +import app.services.db.VIPService; +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("api/bot/discord") +public class DiscordVIPController { + + VIPService vipService; + + @Autowired + public DiscordVIPController(VIPService vipService) { + this.vipService = vipService; + } + + @GetMapping("/viplist") + @CheckWebAccess(auth_method = AuthMethod.SECRET_KEY) + public ResponseEntity getDiscordIDsVIPList( + HttpServletRequest request) { + return new ResponseEntity(vipService.getUsersDiscordWithActiveVIP(), HttpStatus.OK); + } + + @GetMapping("/freeviplist") + @CheckWebAccess(auth_method = AuthMethod.SECRET_KEY) + public ResponseEntity getDiscordIDsFreeVIPList( + HttpServletRequest request) { + return new ResponseEntity(vipService.getUsersDiscordWithActiveFreeVIP(), HttpStatus.OK); + } +} diff --git a/src/main/java/app/services/db/VIPService.java b/src/main/java/app/services/db/VIPService.java new file mode 100644 index 0000000..b7cee46 --- /dev/null +++ b/src/main/java/app/services/db/VIPService.java @@ -0,0 +1,30 @@ +package app.services.db; + +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service +@Transactional +public class VIPService { + @PersistenceContext + EntityManager entityManager; + + public List getUsersDiscordWithActiveVIP() { + return entityManager.createNativeQuery("SELECT `discord_id` FROM `sm_admins` INNER JOIN `steam2discord` ON `sm_admins`.`status` LIKE ?1 AND (`sm_admins`.`comment` LIKE ?2 OR `sm_admins`.`comment` LIKE ?3) AND `sm_admins`.`identity` = `steam2discord`.`steam_id`") + .setParameter(1, "VIP") + .setParameter(2, "Donate.User") + .setParameter(3, "f13bot.User") + .getResultList(); + } + + public List getUsersDiscordWithActiveFreeVIP() { + return entityManager.createNativeQuery("SELECT `discord_id` FROM `sm_admins` INNER JOIN `steam2discord` ON `sm_admins`.`status` LIKE ?1 AND `sm_admins`.`comment` LIKE ?2 AND `sm_admins`.`identity` = `steam2discord`.`steam_id`") + .setParameter(1, "VIP") + .setParameter(2, "f13bot.FreeVIP") + .getResultList(); + } +}