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.
 
 
 
 

123 lines
4.6 KiB

package app.controllers.user;
import app.annotations.enums.AuthMethod;
import app.annotations.enums.FirstTouch;
import app.annotations.interfaces.CheckWebAccess;
import app.annotations.interfaces.CollectStatistic;
import app.annotations.interfaces.WaitAfterNext;
import app.entities.db.Annonce;
import app.entities.db.ban.Ban;
import app.entities.db.ban.BanSearchFilter;
import app.entities.report.Report;
import app.entities.report.ReportSearchFilter;
import app.repositories.AnnonceRepository;
import app.repositories.BanRepository;
import app.repositories.ReportRepository;
import app.services.ProfileService;
import app.services.db.BanService;
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.HashMap;
import java.util.List;
/**
* контролллер для просмотра всякой хуйни, например банлиста (нахуя он отдельный, незнаю, захотел)
*/
@RestController
@RequestMapping("api/web")
public class PublicController {
BanService banService;
@Autowired
private AnnonceRepository annonceRepository;
@Autowired
private BanRepository banRepository;
@Autowired
private ProfileService profileService;
@Autowired
private ReportRepository reportRepository;
@Autowired
public PublicController(BanService banService) {
this.banService = banService;
}
@GetMapping("/banlist")
@CheckWebAccess(auth_method = AuthMethod.STEAM64)
@WaitAfterNext(order = "banlist")
@CollectStatistic
@Deprecated
public ResponseEntity<HashMap> getBanList(
HttpServletRequest request,
@RequestParam(required = false, defaultValue = "20") Integer limit,
@RequestParam(required = false, defaultValue = "0") Long offset) {
if (limit > 20) return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
return new ResponseEntity<>(new HashMap<>(){{
put("bans", banService.getLastBans(limit,offset));
put("count", banService.getBansCount());
}}, HttpStatus.OK);
}
@PostMapping("/banlist")
@CheckWebAccess(auth_method = AuthMethod.STEAM64, firstTouch = FirstTouch.FIRST_PAGE)
@WaitAfterNext(order = "banlist")
@CollectStatistic
public ResponseEntity<Page<Ban>> getBanListWithFilters(Pageable pageable, @RequestBody(required = false) BanSearchFilter banSearchFilter) {
if (banSearchFilter == null) banSearchFilter = new BanSearchFilter();
List<Long> ban_ids = banSearchFilter.getBan_ids();
List<Long> account_ids = banSearchFilter.getAccounts(profileService);
List<String> admin_ids = banSearchFilter.getAdminIds(profileService);
return new ResponseEntity<>(
banRepository.getBans(pageable,
ban_ids.isEmpty(), ban_ids,
account_ids.isEmpty(), account_ids,
banSearchFilter.getBeginUnixTime(),
banSearchFilter.getEndUnixTime(),
banSearchFilter.getActive(),
admin_ids.isEmpty(), admin_ids, banSearchFilter.getReason())
, HttpStatus.OK);
}
@PostMapping("/reports")
@CheckWebAccess(auth_method = AuthMethod.STEAM64, firstTouch = FirstTouch.FIRST_PAGE)
@WaitAfterNext(order = "reports")
@CollectStatistic
public Page<Report> getReports(Pageable pageable,
@RequestBody(required = false)ReportSearchFilter reportSearchFilter) {
if (reportSearchFilter == null) reportSearchFilter = new ReportSearchFilter();
String al = reportSearchFilter.getAccountsSteam2(profileService);
String rl = reportSearchFilter.getAccounts2Steam2(profileService);
return reportRepository.getReports(pageable,
al.isEmpty(), al,
rl.isEmpty(), rl,
reportSearchFilter.getServerId(),
reportSearchFilter.getBeginUnixTime(),
reportSearchFilter.getEndUnixTime());
}
@GetMapping("/news")
public ResponseEntity<Page<Annonce>> getNews(Pageable pageable) {
return ResponseEntity.ok(annonceRepository.getNews(pageable));
}
@GetMapping("/annonces")
public ResponseEntity<Page<Annonce>> getAnnonces(Pageable pageable) {
return ResponseEntity.ok(annonceRepository.getAnnonce(pageable));
}
}