package app.controllers.user; import app.annotations.enums.AuthMethod; import app.annotations.enums.FirstTouch; import app.annotations.interfaces.BurstUpdatePlayers; import app.annotations.interfaces.CheckWebAccess; import app.annotations.interfaces.CollectStatistic; import app.annotations.interfaces.WaitAfterNext; import app.entities.SearchFilter; import app.entities.db.DonateStat; import app.entities.other.SteamID; import app.repositories.DonateStatRepository; import app.repositories.GametimeRepository; import app.services.ProfileService; import app.utils.SteamIDConverter; import jakarta.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.HashMap; /** * контроллер для конечного(конченного) пользователя для просмотра профиля */ @RestController @RequestMapping("api/profile") public class DetailController { private ProfileService profileService; @Autowired private DonateStatRepository donateStatRepository; @Autowired private GametimeRepository gametimeRepository; @Autowired public DetailController(ProfileService profileService) { this.profileService = profileService; } @GetMapping @CheckWebAccess(auth_method = AuthMethod.SECRET_KEY) @BurstUpdatePlayers public ResponseEntity GetUser(HttpServletRequest request, @RequestParam String steam64) { return new ResponseEntity(profileService.GetProfile(steam64), HttpStatus.OK); } @GetMapping("/web") @CheckWebAccess(auth_method = AuthMethod.STEAM64) @BurstUpdatePlayers @WaitAfterNext(order = "getprofile") @CollectStatistic public ResponseEntity GetUser4Web(HttpServletRequest request, @RequestParam String steam64, @RequestParam(required = false, defaultValue = "") String requests) { return new ResponseEntity(profileService.GetProfile(steam64, requests), HttpStatus.OK); } @GetMapping("/steam") @CheckWebAccess(auth_method = AuthMethod.SECRET_KEY) public ResponseEntity GetSteam(HttpServletRequest request, @RequestParam String any) { return new ResponseEntity<>(profileService.GetSteamIDFromAnyData(any), HttpStatus.OK); } @GetMapping("/steam/web") @CheckWebAccess(auth_method = AuthMethod.STEAM64) @WaitAfterNext(order = "search") @CollectStatistic public ResponseEntity GetSteam4Web(HttpServletRequest request, @RequestParam String any) { return new ResponseEntity<>(profileService.GetSteamIDFromAnyData(any), HttpStatus.OK); } @PostMapping("/steam") @CheckWebAccess(auth_method = AuthMethod.SECRET_KEY) public ResponseEntity GetSteamOnHashMap(HttpServletRequest request, @RequestBody HashMap container) { if (!container.containsKey("any")) return new ResponseEntity(HttpStatus.BAD_REQUEST); return new ResponseEntity<>(profileService.GetSteamIDFromAnyData(container.get("any")), HttpStatus.OK); } @PostMapping("/steam/web") @CheckWebAccess(auth_method = AuthMethod.STEAM64) @WaitAfterNext(order = "search") @CollectStatistic public ResponseEntity GetSteamOnHashMap4Web(HttpServletRequest request, @RequestBody HashMap container) { if (!container.containsKey("any")) return new ResponseEntity(HttpStatus.BAD_REQUEST); return new ResponseEntity<>(profileService.GetSteamIDFromAnyData(container.get("any")), HttpStatus.OK); } @GetMapping("/gametime/web") @CheckWebAccess(auth_method = AuthMethod.STEAM64) @WaitAfterNext(order = "gametime") @CollectStatistic public ResponseEntity GetGametime4Web(HttpServletRequest request, @RequestParam String steam64, @RequestParam String srv, @RequestParam(required = false, defaultValue = "0") Integer offset, @RequestParam(required = false, defaultValue = "20") Integer limit) { SteamID steamID = SteamIDConverter.getSteamID(steam64); if (steamID == null) return new ResponseEntity(HttpStatus.NOT_FOUND); if (limit > 20) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE); return new ResponseEntity<>(new HashMap<>(){{ put("array", profileService.usertimeService.getGametimeOnServer(steamID, srv, limit, offset)); put("total", profileService.usertimeService.getTotalGametimeOnServer(steamID, srv)); }}, HttpStatus.OK); } @PostMapping("/donate") @CheckWebAccess(auth_method = AuthMethod.STEAM64, firstTouch = FirstTouch.FIRST_PAGE) @WaitAfterNext(order = "donatelist") @CollectStatistic public ResponseEntity> getDonatePage(Pageable pageable, @RequestBody(required = false) SearchFilter searchFilter) { String ids = searchFilter.getAccountsSteam2(profileService); Page donates = donateStatRepository.getDonate(pageable, ids.isEmpty(), ids, searchFilter.getBeginUnixTime() == null ? 0L : searchFilter.getBeginUnixTime(), searchFilter.getEndUnixTime() == null ? 0L : searchFilter.getEndUnixTime(), searchFilter.getBeginUnixTime(), searchFilter.getEndUnixTime()); donates.getContent().forEach((donateStat -> { donateStat.setGametime(gametimeRepository.searchGametimeBySteam2(donateStat.getSteam2())); })); return new ResponseEntity<>(donates, HttpStatus.OK); } }