Skip to content
Snippets Groups Projects
Commit 90d12c1e authored by Jonas's avatar Jonas
Browse files

18.12.2023 - create controller class and endpoints #22

parent 40414997
No related branches found
No related tags found
1 merge request!7Dev in Main Merge
package hdm.mi.sthbackend.controller;
import hdm.mi.sthbackend.exeptions.PlayerIdNotFoundException;
import hdm.mi.sthbackend.exeptions.TournamentIdNotFoundException;
import hdm.mi.sthbackend.model.Player;
import hdm.mi.sthbackend.model.Team;
import hdm.mi.sthbackend.model.Tournament;
import hdm.mi.sthbackend.service.TournamentService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.UUID;
@RestController
@RequestMapping("/api/v1/tournaments")
@AllArgsConstructor
public class TournamentController {
private final TournamentService service;
/**
* Player Endpoints
**/
@PatchMapping("/{tournamentId}/teams/{teamId}/players/{playerId}")
public UUID updatePlayerName(@PathVariable UUID tournamentId,
@PathVariable UUID teamId,
@PathVariable UUID playerId,
@RequestBody String newPlayerName) throws Exception {
return service.updatePlayerName(tournamentId, teamId, playerId, newPlayerName);
}
/**
* Team Endpoints
**/
@PostMapping("/{tournamentId}/teams")
public Team createTeam(@PathVariable UUID tournamentId,
@RequestBody String teamName) throws TournamentIdNotFoundException {
return service.createTeam(tournamentId, teamName);
}
@PostMapping("/{tournamentId}/teams/{teamId}/addPlayer")
public Player addPlayerToTeam(@PathVariable UUID tournamentId,
@PathVariable UUID teamId,
@RequestBody String playerName) throws Exception {
return service.addPlayerToTeam(tournamentId, teamId, playerName);
}
@DeleteMapping("/{tournamentId}/teams/{teamId}/players/{playerId}")
public Player removePlayerFromTeam(@PathVariable UUID tournamentId,
@PathVariable UUID teamId,
@PathVariable UUID playerId) throws PlayerIdNotFoundException, TournamentIdNotFoundException {
return service.removePlayerFromTeam(tournamentId, teamId, playerId);
}
/**
* Tournament Endpoints
*/
@PostMapping
public Tournament createTournament(@RequestBody String tournamentName) {
return service.createTournament(tournamentName);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment