mirror of
https://github.com/PaulReichmuth/timekeep-backend.git
synced 2026-02-06 04:53:25 +00:00
added Mappings
This commit is contained in:
@@ -2,12 +2,14 @@ package de.pnreichmuth.timekeep_backend.controllers;
|
||||
|
||||
import de.pnreichmuth.timekeep_backend.entities.Racer;
|
||||
import de.pnreichmuth.timekeep_backend.entities.Team;
|
||||
import de.pnreichmuth.timekeep_backend.services.RacerService;
|
||||
import de.pnreichmuth.timekeep_backend.exceptions.ExistsException;
|
||||
import de.pnreichmuth.timekeep_backend.exceptions.NotFoundException;
|
||||
import de.pnreichmuth.timekeep_backend.services.TeamService;
|
||||
import de.pnreichmuth.timekeep_backend.wsto.RacerWSTO;
|
||||
import de.pnreichmuth.timekeep_backend.wsto.TeamWSTO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ProblemDetail;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -17,8 +19,38 @@ import org.springframework.web.bind.annotation.*;
|
||||
@RequiredArgsConstructor
|
||||
public class TeamMemberRestController {
|
||||
private final TeamService teamService;
|
||||
private final RacerService racerService;
|
||||
// ///////////////////////////////////////////////BEGIN GET MAPPINGS///////////////////////////////////////////////////
|
||||
|
||||
// ///////////////////////////////////////////////BEGIN POST MAPPINGS///////////////////////////////////////////////////
|
||||
@PostMapping("/addMemberToTeam")
|
||||
public <T> ResponseEntity<?> addMemberToTeam(@RequestParam("teamName") String teamName, @RequestBody Racer racer) {
|
||||
Team mockTeam = new Team();
|
||||
mockTeam.setTeamName(teamName);
|
||||
try{
|
||||
this.teamService.addMember(mockTeam,racer);
|
||||
}
|
||||
catch(NotFoundException e){
|
||||
return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND, e.getMessage())).build();
|
||||
}
|
||||
catch (ExistsException e){
|
||||
return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, e.getMessage())).build();
|
||||
}
|
||||
return ResponseEntity.ok(TeamWSTO.of(teamService.getTeam(mockTeam)));
|
||||
}
|
||||
// ///////////////////////////////////////////////BEGIN DELETE MAPPINGS///////////////////////////////////////////////////
|
||||
@DeleteMapping("/removeMemberFromTeam")
|
||||
public <T> ResponseEntity<?> removeMemberFromTeam(@RequestParam("teamName") String teamName, @RequestBody Racer racer) {
|
||||
Team mockTeam = new Team();
|
||||
mockTeam.setTeamName(teamName);
|
||||
try{
|
||||
this.teamService.removeMember(mockTeam,racer);
|
||||
}
|
||||
catch(NotFoundException e){
|
||||
return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND, e.getMessage())).build();
|
||||
}
|
||||
catch (ExistsException e){
|
||||
return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, e.getMessage())).build();
|
||||
}
|
||||
return ResponseEntity.ok(TeamWSTO.of(teamService.getTeam(mockTeam)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user