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(); + } +}