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.
184 lines
9.1 KiB
184 lines
9.1 KiB
package app.controllers.user;
|
|
|
|
import app.annotations.enums.AuthMethod;
|
|
import app.annotations.interfaces.CheckWebAccess;
|
|
import app.annotations.interfaces.CollectStatistic;
|
|
import app.annotations.interfaces.WaitAfterNext;
|
|
import app.entities.SearchFilter;
|
|
import app.entities.db.Gametime;
|
|
import app.entities.killfeed.FeedType;
|
|
import app.entities.killfeed.KillsInFeed;
|
|
import app.entities.other.SteamID;
|
|
import app.repositories.GametimeRepository;
|
|
import app.repositories.KillfeedRepository;
|
|
import app.services.ProfileService;
|
|
import app.services.db.KillfeedService;
|
|
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.PageImpl;
|
|
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.Collections;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.function.Function;
|
|
|
|
/**
|
|
* контроллер для получение списка убийств\ассистов\смертей
|
|
*/
|
|
@RestController
|
|
@RequestMapping("api/profile/killfeed")
|
|
public class KillFeedController {
|
|
private KillfeedService killfeedService;
|
|
|
|
@Autowired
|
|
private ProfileService profileService;
|
|
|
|
@Autowired
|
|
private KillfeedRepository killfeedRepository;
|
|
|
|
@Autowired
|
|
private GametimeRepository gametimeRepository;
|
|
|
|
@Autowired
|
|
KillFeedController(KillfeedService killfeedService) {
|
|
this.killfeedService = killfeedService;
|
|
}
|
|
|
|
private final Function<Long, String> accountId2Nickname = (account_id) -> {
|
|
if (account_id == null || account_id < 0) return "";
|
|
Gametime gametime = gametimeRepository.searchGametimeByAccountId(account_id);
|
|
return gametime == null ? "Unknown" : gametime.getPlayer_name();
|
|
};
|
|
|
|
@GetMapping("/weapons")
|
|
@CheckWebAccess(auth_method = AuthMethod.STEAM64)
|
|
@WaitAfterNext(order = "weapons")
|
|
@CollectStatistic
|
|
public ResponseEntity getPopulateWeapons(HttpServletRequest request,
|
|
@CookieValue(value = "steam64", defaultValue = "") String mysteam64,
|
|
@RequestParam(required = false) String steam64,
|
|
@RequestParam(required = false) String srv,
|
|
@RequestParam(required = false, defaultValue = "0") Integer offset,
|
|
@RequestParam(required = false, defaultValue = "20") Integer limit) {
|
|
SteamID steamID = steam64 == null || steam64.isEmpty() ? SteamIDConverter.getSteamID(mysteam64) : SteamIDConverter.getSteamID(steam64);
|
|
if (steamID == null) return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
if (limit > 20) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE);
|
|
return new ResponseEntity(killfeedService.getPopulateWeapons(steamID, srv, offset, limit), HttpStatus.OK);
|
|
}
|
|
|
|
@GetMapping("/top")
|
|
@CheckWebAccess(auth_method = AuthMethod.STEAM64)
|
|
@WaitAfterNext(order = "top")
|
|
@CollectStatistic
|
|
public ResponseEntity getTopKills(HttpServletRequest request,
|
|
@RequestParam(required = false) String srv) {
|
|
return new ResponseEntity(killfeedService.getTopKills(srv), HttpStatus.OK);
|
|
}
|
|
|
|
@PostMapping
|
|
@CheckWebAccess(auth_method = AuthMethod.STEAM64)
|
|
@WaitAfterNext(order = "killfeed")
|
|
@CollectStatistic
|
|
public Page<KillsInFeed> getKillFeed(Pageable pageable,
|
|
@RequestBody(required = false) SearchFilter searchFilter,
|
|
@RequestParam String mode) {
|
|
if (searchFilter == null) searchFilter = new SearchFilter();
|
|
List<Long> accs = searchFilter.getAccounts(profileService);
|
|
|
|
Page<KillsInFeed> result;
|
|
|
|
switch (mode) {
|
|
case "kills" -> {
|
|
result = killfeedRepository.getKills(
|
|
pageable, accs.isEmpty(), accs, searchFilter.getServerId(), searchFilter.getBeginUnixTime(), searchFilter.getEndUnixTime()
|
|
);
|
|
}
|
|
case "assists" -> {
|
|
result = killfeedRepository.getAssists(
|
|
pageable, accs.isEmpty(), accs, searchFilter.getServerId(), searchFilter.getBeginUnixTime(), searchFilter.getEndUnixTime()
|
|
);
|
|
}
|
|
case "deads" -> {
|
|
result = killfeedRepository.getDeads(
|
|
pageable, accs.isEmpty(), accs, searchFilter.getServerId(), searchFilter.getBeginUnixTime(), searchFilter.getEndUnixTime()
|
|
);
|
|
}
|
|
default -> result = new PageImpl<>(List.of());
|
|
}
|
|
result.getContent().forEach(k -> {
|
|
k.setAssister_name(accountId2Nickname.apply(k.getAssister_id()));
|
|
k.setVictim_name(accountId2Nickname.apply(k.getVictim_id()));
|
|
k.setAttacker_name(accountId2Nickname.apply(k.getAttacker_id()));
|
|
});
|
|
return result;
|
|
}
|
|
|
|
@GetMapping
|
|
@CheckWebAccess(auth_method = AuthMethod.STEAM64)
|
|
@WaitAfterNext(order = "kills")
|
|
@CollectStatistic
|
|
public ResponseEntity getKills(HttpServletRequest request,
|
|
@CookieValue(value = "steam64", defaultValue = "") String mysteam64,
|
|
@RequestParam(required = false) String steam64,
|
|
@RequestParam(required = false) String srv,
|
|
Pageable pageable,
|
|
@RequestParam(required = false, defaultValue = "false") boolean current) {
|
|
SteamID steamID = steam64 == null || steam64.isEmpty() ? SteamIDConverter.getSteamID(mysteam64) : SteamIDConverter.getSteamID(steam64);
|
|
if (steamID == null) return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
if (pageable.getPageSize() > 20) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE);
|
|
Page<KillsInFeed> res = killfeedService.getKills(pageable, Collections.singletonList(steamID), srv, current);
|
|
|
|
return new ResponseEntity(Map.of("result", res.getContent(), "count", res.getTotalElements(), "type", FeedType.KILL.ordinal()), HttpStatus.OK);
|
|
}
|
|
|
|
@PutMapping
|
|
@CheckWebAccess(auth_method = AuthMethod.STEAM64)
|
|
@WaitAfterNext(order = "assists")
|
|
@CollectStatistic
|
|
public ResponseEntity getAssists(HttpServletRequest request,
|
|
@CookieValue(value = "steam64", defaultValue = "") String mysteam64,
|
|
@RequestParam(required = false) String steam64,
|
|
@RequestParam(required = false) String srv,
|
|
Pageable pageable,
|
|
@RequestParam(required = false, defaultValue = "false") boolean current) {
|
|
SteamID steamID = steam64 == null || steam64.isEmpty() ? SteamIDConverter.getSteamID(mysteam64) : SteamIDConverter.getSteamID(steam64);
|
|
if (steamID == null) return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
if (pageable.getPageSize() > 20) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE);
|
|
Page<KillsInFeed> res = killfeedService.getAssists(pageable, Collections.singletonList(steamID), srv, current);
|
|
|
|
return new ResponseEntity(Map.of("result", res.getContent(), "count", res.getTotalElements(), "type", FeedType.ASSIST.ordinal()), HttpStatus.OK);
|
|
}
|
|
|
|
@DeleteMapping
|
|
@CheckWebAccess(auth_method = AuthMethod.STEAM64)
|
|
@WaitAfterNext(order = "deads")
|
|
@CollectStatistic
|
|
public ResponseEntity getDeads(HttpServletRequest request,
|
|
@CookieValue(value = "steam64", defaultValue = "") String mysteam64,
|
|
@RequestParam(required = false) String steam64,
|
|
@RequestParam(required = false) String srv,
|
|
Pageable pageable,
|
|
@RequestParam(required = false, defaultValue = "false") boolean current) {
|
|
SteamID steamID = steam64 == null || steam64.isEmpty() ? SteamIDConverter.getSteamID(mysteam64) : SteamIDConverter.getSteamID(steam64);
|
|
if (steamID == null) return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
if (pageable.getPageSize() > 20) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE);
|
|
Page<KillsInFeed> res = killfeedService.getDeads(pageable, Collections.singletonList(steamID), srv, current);
|
|
|
|
return new ResponseEntity(Map.of("result", res.getContent(), "count", res.getTotalElements(), "type", FeedType.DEAD.ordinal()), HttpStatus.OK);
|
|
}
|
|
|
|
@DeleteMapping("/top")
|
|
@CheckWebAccess(auth_method = AuthMethod.STEAM64)
|
|
@WaitAfterNext(order = "top")
|
|
@CollectStatistic
|
|
public ResponseEntity getTopDeads(HttpServletRequest request,
|
|
@RequestParam(required = false) String srv) {
|
|
return new ResponseEntity(killfeedService.getTopDeads(srv), HttpStatus.OK);
|
|
}
|
|
}
|
|
|