Browse Source

интеграция с дискордом

master
gsd 2 years ago
parent
commit
d035184c98
  1. 38
      src/main/java/app/controllers/bot/DiscordVIPController.java
  2. 30
      src/main/java/app/services/db/VIPService.java

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

30
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<Long> 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<Long> 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();
}
}
Loading…
Cancel
Save