mirror of
https://github.com/PaulReichmuth/timekeep-backend.git
synced 2026-02-06 04:53:25 +00:00
Revert "refactor pure objects as request body into WSTOs"
This reverts commit a87a5a6198.
This commit is contained in:
@@ -8,7 +8,6 @@ import de.pnreichmuth.timekeep_backend.exceptions.TeamNotFoundException;
|
|||||||
import de.pnreichmuth.timekeep_backend.services.RacerService;
|
import de.pnreichmuth.timekeep_backend.services.RacerService;
|
||||||
import de.pnreichmuth.timekeep_backend.services.TeamService;
|
import de.pnreichmuth.timekeep_backend.services.TeamService;
|
||||||
import de.pnreichmuth.timekeep_backend.wsto.RacerWSTO;
|
import de.pnreichmuth.timekeep_backend.wsto.RacerWSTO;
|
||||||
import de.pnreichmuth.timekeep_backend.wsto.TeamWSTO;
|
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -29,8 +28,7 @@ public class RacerRestController {
|
|||||||
private final TeamService teamService;
|
private final TeamService teamService;
|
||||||
// ///////////////////////////////////////////////BEGIN POST MAPPINGS///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////BEGIN POST MAPPINGS///////////////////////////////////////////////////
|
||||||
@PostMapping("createRacer")
|
@PostMapping("createRacer")
|
||||||
public ResponseEntity<@NonNull RacerWSTO> createRacer(@RequestBody RacerWSTO racerWSTO) {
|
public ResponseEntity<@NonNull RacerWSTO> createRacer(@RequestBody Racer racer) {
|
||||||
Racer racer = RacerWSTO.toEntity(racerWSTO);
|
|
||||||
try {
|
try {
|
||||||
racerService.updateRacer(racer);
|
racerService.updateRacer(racer);
|
||||||
return new ResponseEntity<>(RacerWSTO.of(racer), HttpStatus.CREATED);
|
return new ResponseEntity<>(RacerWSTO.of(racer), HttpStatus.CREATED);
|
||||||
@@ -51,24 +49,26 @@ public class RacerRestController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("singleRacer")
|
@GetMapping("singleRacer")
|
||||||
public ResponseEntity<@NonNull RacerWSTO> getSingleRacers(@RequestBody RacerWSTO requestRacerWSTO){
|
public ResponseEntity<@NonNull RacerWSTO> getSingleRacers(@RequestBody Racer requestRacer){
|
||||||
try{
|
Racer actualRacer = racerService.getRacer(requestRacer);
|
||||||
Racer actualRacer = racerService.getRacer(RacerWSTO.toEntity(requestRacerWSTO));
|
if (actualRacer == null){
|
||||||
return ResponseEntity.ok(RacerWSTO.of(actualRacer));
|
return ResponseEntity.of(
|
||||||
}
|
ProblemDetail.forStatusAndDetail(
|
||||||
catch (RacerNotFoundException e){
|
HttpStatus.NOT_FOUND,
|
||||||
return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND, e.getMessage())).build();
|
String.format("Racer with name %s %s not found",
|
||||||
}
|
requestRacer.getFirstName(), requestRacer.getLastName()
|
||||||
catch (IllegalArgumentException e) {
|
)
|
||||||
return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, e.getMessage())).build();
|
)
|
||||||
|
).build();
|
||||||
}
|
}
|
||||||
|
return ResponseEntity.ok(RacerWSTO.of(actualRacer));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("byTeam")
|
@GetMapping("byTeam")
|
||||||
public ResponseEntity<@NonNull List<RacerWSTO>> getByTeam(@RequestBody TeamWSTO requestTeamWSTO){
|
public ResponseEntity<@NonNull List<RacerWSTO>> getByTeam(@RequestBody Team requestTeam){
|
||||||
Team dbTeam;
|
Team dbTeam;
|
||||||
try {
|
try {
|
||||||
dbTeam = teamService.getTeam(TeamWSTO.toEntity(requestTeamWSTO));
|
dbTeam = teamService.getTeam(requestTeam);
|
||||||
} catch (TeamNotFoundException e) {
|
} catch (TeamNotFoundException e) {
|
||||||
return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND, e.getMessage())).build();
|
return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND, e.getMessage())).build();
|
||||||
}
|
}
|
||||||
@@ -81,8 +81,7 @@ public class RacerRestController {
|
|||||||
|
|
||||||
// ////////////////////////////////////////////////BEGIN DELETE MAPPINGS///////////////////////////////////////////////////
|
// ////////////////////////////////////////////////BEGIN DELETE MAPPINGS///////////////////////////////////////////////////
|
||||||
@DeleteMapping("/removeRacer")
|
@DeleteMapping("/removeRacer")
|
||||||
public ResponseEntity<?> removeRacer(@RequestBody RacerWSTO racerWSTO){
|
public ResponseEntity<?> removeRacer(@RequestBody Racer racer){
|
||||||
Racer racer = RacerWSTO.toEntity(racerWSTO);
|
|
||||||
try {
|
try {
|
||||||
racerService.deleteRacer(racer);
|
racerService.deleteRacer(racer);
|
||||||
return ResponseEntity.ok(racer);
|
return ResponseEntity.ok(racer);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import de.pnreichmuth.timekeep_backend.entities.Team;
|
|||||||
import de.pnreichmuth.timekeep_backend.exceptions.ExistsException;
|
import de.pnreichmuth.timekeep_backend.exceptions.ExistsException;
|
||||||
import de.pnreichmuth.timekeep_backend.exceptions.NotFoundException;
|
import de.pnreichmuth.timekeep_backend.exceptions.NotFoundException;
|
||||||
import de.pnreichmuth.timekeep_backend.services.TeamService;
|
import de.pnreichmuth.timekeep_backend.services.TeamService;
|
||||||
import de.pnreichmuth.timekeep_backend.wsto.RacerWSTO;
|
|
||||||
import de.pnreichmuth.timekeep_backend.wsto.TeamWSTO;
|
import de.pnreichmuth.timekeep_backend.wsto.TeamWSTO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -24,10 +23,9 @@ public class TeamMemberRestController {
|
|||||||
|
|
||||||
// ///////////////////////////////////////////////BEGIN POST MAPPINGS///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////BEGIN POST MAPPINGS///////////////////////////////////////////////////
|
||||||
@PostMapping("/addMemberToTeam")
|
@PostMapping("/addMemberToTeam")
|
||||||
public ResponseEntity<?> addMemberToTeam(@RequestParam("teamName") String teamName, @RequestBody RacerWSTO racerWsto) {
|
public ResponseEntity<?> addMemberToTeam(@RequestParam("teamName") String teamName, @RequestBody Racer racer) {
|
||||||
Team mockTeam = new Team();
|
Team mockTeam = new Team();
|
||||||
mockTeam.setTeamName(teamName);
|
mockTeam.setTeamName(teamName);
|
||||||
Racer racer = RacerWSTO.toEntity(racerWsto);
|
|
||||||
try{
|
try{
|
||||||
this.teamService.addMember(mockTeam,racer);
|
this.teamService.addMember(mockTeam,racer);
|
||||||
}
|
}
|
||||||
@@ -41,10 +39,9 @@ public class TeamMemberRestController {
|
|||||||
}
|
}
|
||||||
// ///////////////////////////////////////////////BEGIN DELETE MAPPINGS///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////BEGIN DELETE MAPPINGS///////////////////////////////////////////////////
|
||||||
@DeleteMapping("/removeMemberFromTeam")
|
@DeleteMapping("/removeMemberFromTeam")
|
||||||
public ResponseEntity<?> removeMemberFromTeam(@RequestParam("teamName") String teamName, @RequestBody RacerWSTO racerWsto) {
|
public ResponseEntity<?> removeMemberFromTeam(@RequestParam("teamName") String teamName, @RequestBody Racer racer) {
|
||||||
Team mockTeam = new Team();
|
Team mockTeam = new Team();
|
||||||
mockTeam.setTeamName(teamName);
|
mockTeam.setTeamName(teamName);
|
||||||
Racer racer = RacerWSTO.toEntity(racerWsto);
|
|
||||||
try{
|
try{
|
||||||
this.teamService.removeMember(mockTeam,racer);
|
this.teamService.removeMember(mockTeam,racer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,8 +34,7 @@ public class TeamRestController {
|
|||||||
* either containing a TeamWSTO if a team was successfully created or a HttpStatus.CONFLICT if the team already existed beforehand
|
* either containing a TeamWSTO if a team was successfully created or a HttpStatus.CONFLICT if the team already existed beforehand
|
||||||
*/
|
*/
|
||||||
@PostMapping("createTeam")
|
@PostMapping("createTeam")
|
||||||
public ResponseEntity<@NonNull TeamWSTO> createTeam(@RequestBody TeamWSTO teamwsto){
|
public ResponseEntity<@NonNull TeamWSTO> createTeam(@RequestBody Team team){
|
||||||
Team team = TeamWSTO.toEntity(teamwsto);
|
|
||||||
try {
|
try {
|
||||||
teamService.createTeam(team);
|
teamService.createTeam(team);
|
||||||
return new ResponseEntity<>(TeamWSTO.of(team), HttpStatus.CREATED);
|
return new ResponseEntity<>(TeamWSTO.of(team), HttpStatus.CREATED);
|
||||||
@@ -66,12 +65,11 @@ public class TeamRestController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all the information pertaining to a given team via the API
|
* Gets all the information pertaining to a given team via the API
|
||||||
* @param reqTeamWSTO the teamWSTO to query all information about with either a name or an id field set
|
* @param reqTeam the team to query all information about with either a name or an id field set
|
||||||
* @return a ResponseEntity containing the team in WSTO form, or a ResponseEntity containing either BAD_REQUEST or NOT_FOUND.
|
* @return a ResponseEntity containing the team in WSTO form, or a ResponseEntity containing either BAD_REQUEST or NOT_FOUND.
|
||||||
*/
|
*/
|
||||||
@GetMapping("single-team")
|
@GetMapping("single-team")
|
||||||
public ResponseEntity<@NonNull TeamWSTO> getSingleTeam(@RequestBody TeamWSTO reqTeamWSTO){
|
public ResponseEntity<@NonNull TeamWSTO> getSingleTeam(@RequestBody Team reqTeam){
|
||||||
Team reqTeam = TeamWSTO.toEntity(reqTeamWSTO);
|
|
||||||
UUID id = reqTeam.getId();
|
UUID id = reqTeam.getId();
|
||||||
String name = reqTeam.getTeamName();
|
String name = reqTeam.getTeamName();
|
||||||
Team actualTeam;
|
Team actualTeam;
|
||||||
@@ -102,13 +100,12 @@ public class TeamRestController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a team via its name or id
|
* Deletes a team via its name or id
|
||||||
* @param teamWSTO the teamWSTO to query all information about with either a name or an id field set
|
* @param team the team to query all information about with either a name or an id field set
|
||||||
* @return a ResponseEntity containing HttpStatus.OK if deletion was successful,
|
* @return a ResponseEntity containing HttpStatus.OK if deletion was successful,
|
||||||
* or a ResponseEntity containing either BAD_REQUEST or NOT_FOUND.
|
* or a ResponseEntity containing either BAD_REQUEST or NOT_FOUND.
|
||||||
*/
|
*/
|
||||||
@DeleteMapping("single-team")
|
@DeleteMapping("single-team")
|
||||||
public ResponseEntity<@NonNull String> deleteTeam(@RequestBody TeamWSTO teamWSTO){
|
public ResponseEntity<@NonNull String> deleteTeam(@RequestBody Team team){
|
||||||
Team team = TeamWSTO.toEntity(teamWSTO);
|
|
||||||
String name = team.getTeamName();
|
String name = team.getTeamName();
|
||||||
UUID id = team.getId();
|
UUID id = team.getId();
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user