package com.chan.ssb;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
@SpringBootApplication
@EnableMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true)
public class SsbApplication {
public static void main(String[] args) {
SpringApplication.run(SsbApplication.class, args);
}
}
@PreAuthorize("hasRole('ROOT')")
public List<PlayerDTO> getAllPlayers() {
List<Player> players = playerRepository.findAll();
List<PlayerDTO> returnPlayers = players.stream().map(PlayerDTO::fromEntity).toList();
if(returnPlayers.isEmpty()) {
throw new EntityNotFoundException("No players found");
}
return returnPlayers;
}
@PostMapping("")
@PostAuthorize("hasRole('ROOT')")
public ResponseEntity<CollectionModel<EntityModel<TeamDTO>>> createTeams(@Valid @RequestBody TeamDTOListWrapper teamDTOList) {
List<TeamDTO> savedTeams = teamService.createTeams(teamDTOList.getTeamDTOList());
URI location = ServletUriComponentsBuilder
.fromCurrentRequest()
.path("")
.build()
.toUri();
List<EntityModel<TeamDTO>> teamEntityModels = savedTeams.stream()
.map(team -> EntityModel.of(team,
linkTo(methodOn(TeamController.class).getTeam(team.getId())).withSelfRel(),
linkTo(methodOn(TeamController.class).getAllTeams()).withRel("teams")))
.toList();
return ResponseEntity.created(location).body(CollectionModel.of(teamEntityModels,
linkTo(methodOn(TeamController.class).getAllTeams()).withSelfRel()));
}
@PostMapping("/filter")
@PreFilter("filterObject.name != 'test'")
public List<TeamDTO> getTeamsByFilter(@RequestBody List<TeamDTO> teams) {
return teams;
}
@PostMapping("/filter")
// @PreFilter("filterObject.name != 'test'")
@PostFilter("filterObject.name != 'test'")
public List<TeamDTO> getTeamsByFilter(@RequestBody List<TeamDTO> teams) {
return teams;
}