package app.controllers.admin; import app.annotations.interfaces.CheckPermitionFlag; import app.annotations.interfaces.NeedValidCookie; import app.entities.db.Ban; import app.entities.other.SteamID; import app.services.ProfileService; import app.services.db.BanService; import app.services.db.PermitionService; import app.utils.SteamIDConverter; 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.*; import java.util.List; @RestController @RequestMapping("api/admin/ban") public class BanController { ProfileService profileService; BanService banService; PermitionService permitionService; @Autowired public BanController(ProfileService profileService, BanService banService, PermitionService permitionService) { this.profileService = profileService; this.banService = banService; this.permitionService = permitionService; } @PostMapping @NeedValidCookie @CheckPermitionFlag(flag = "z") public ResponseEntity banPlayer( HttpServletRequest request, @CookieValue(value = "steam64") String admin_steam64, @RequestParam(value = "steam64") String user_steam64, @RequestParam(value = "ban_length", required = false, defaultValue = "0") int ban_length, @RequestParam(value = "ban_reason", required = false, defaultValue = "фурриёб") String ban_reason ){ if (!permitionService.CheckMorePowerfull(SteamIDConverter.getSteamID(admin_steam64), SteamIDConverter.getSteamID(user_steam64))) return new ResponseEntity(HttpStatus.FORBIDDEN); boolean result = banService.addBan( profileService.GetProfile(user_steam64, List.of("steam_data")), profileService.GetProfile(admin_steam64, List.of("steam_data")), ban_length, ban_reason); return result ? new ResponseEntity(result, HttpStatus.CREATED) : new ResponseEntity(result, HttpStatus.NOT_FOUND); } @DeleteMapping @NeedValidCookie @CheckPermitionFlag(flag = "z") public ResponseEntity unbanPlayer( HttpServletRequest request, @CookieValue(value = "steam64") String admin_steam64, @RequestParam(value = "steam64") String user_steam64 ){ boolean result = banService.removeBan( profileService.GetProfile(user_steam64, List.of()), profileService.GetProfile(admin_steam64, List.of())); return result ? new ResponseEntity(result, HttpStatus.OK) : new ResponseEntity(result, HttpStatus.NOT_FOUND); } }