You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

68 lines
2.5 KiB

package app.controllers.admin;
import app.annotations.interfaces.CheckPermitionFlag;
import app.annotations.interfaces.CheckWebAccess;
import app.annotations.interfaces.CollectStatistic;
import app.annotations.interfaces.WaitAfterNext;
import app.entities.VipGiveMethod;
import app.services.db.VIPService;
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.*;
@RestController
@RequestMapping("api/admin/vip")
public class VIPController {
VIPService vipService;
@Autowired
public VIPController(VIPService vipService) {
this.vipService = vipService;
}
@PostMapping
@CheckWebAccess
@CheckPermitionFlag(flag = "z")
@WaitAfterNext(order = "givevip")
@CollectStatistic
public ResponseEntity giveVIP(
HttpServletRequest request,
@CookieValue(value = "steam64") String admin_steam64,
@RequestParam(value = "steam64") String user_steam64,
@RequestParam int amount
) {
int result = vipService.addVIP(
SteamIDConverter.getSteamID(user_steam64),
amount,
VipGiveMethod.MANUAL,
SteamIDConverter.getSteamID(admin_steam64).steam2);
if (result == 0) return new ResponseEntity(HttpStatus.CONFLICT);
if (result > 0) return new ResponseEntity(HttpStatus.CREATED);
if (result < 0) return new ResponseEntity(HttpStatus.RESET_CONTENT);
return new ResponseEntity(HttpStatus.BAD_REQUEST);
}
@DeleteMapping
@CheckWebAccess
@CheckPermitionFlag(flag = "z")
@WaitAfterNext(order = "removevip")
@CollectStatistic
public ResponseEntity removeVIP(
HttpServletRequest request,
@CookieValue(value = "steam64") String admin_steam64,
@RequestParam(value = "steam64") String user_steam64
) {
int result = vipService.removeVIP(
SteamIDConverter.getSteamID(user_steam64),
SteamIDConverter.getSteamID(admin_steam64),
VipGiveMethod.MANUAL
);
if (result == 0) return new ResponseEntity(HttpStatus.CONFLICT);
if (result > 0) return new ResponseEntity(HttpStatus.OK);
if (result < 0) return new ResponseEntity(HttpStatus.NOT_FOUND);
return new ResponseEntity(HttpStatus.BAD_REQUEST);
}
}