Revert "refactor pure objects as request body into WSTOs"

This reverts commit a87a5a6198.
This commit is contained in:
2026-02-04 21:47:46 +01:00
parent a87a5a6198
commit b55f0ca6bf
3 changed files with 23 additions and 30 deletions

View File

@@ -8,7 +8,6 @@ import de.pnreichmuth.timekeep_backend.exceptions.TeamNotFoundException;
import de.pnreichmuth.timekeep_backend.services.RacerService;
import de.pnreichmuth.timekeep_backend.services.TeamService;
import de.pnreichmuth.timekeep_backend.wsto.RacerWSTO;
import de.pnreichmuth.timekeep_backend.wsto.TeamWSTO;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -29,8 +28,7 @@ public class RacerRestController {
private final TeamService teamService;
// ///////////////////////////////////////////////BEGIN POST MAPPINGS///////////////////////////////////////////////////
@PostMapping("createRacer")
public ResponseEntity<@NonNull RacerWSTO> createRacer(@RequestBody RacerWSTO racerWSTO) {
Racer racer = RacerWSTO.toEntity(racerWSTO);
public ResponseEntity<@NonNull RacerWSTO> createRacer(@RequestBody Racer racer) {
try {
racerService.updateRacer(racer);
return new ResponseEntity<>(RacerWSTO.of(racer), HttpStatus.CREATED);
@@ -51,24 +49,26 @@ public class RacerRestController {
}
@GetMapping("singleRacer")
public ResponseEntity<@NonNull RacerWSTO> getSingleRacers(@RequestBody RacerWSTO requestRacerWSTO){
try{
Racer actualRacer = racerService.getRacer(RacerWSTO.toEntity(requestRacerWSTO));
public ResponseEntity<@NonNull RacerWSTO> getSingleRacers(@RequestBody Racer requestRacer){
Racer actualRacer = racerService.getRacer(requestRacer);
if (actualRacer == null){
return ResponseEntity.of(
ProblemDetail.forStatusAndDetail(
HttpStatus.NOT_FOUND,
String.format("Racer with name %s %s not found",
requestRacer.getFirstName(), requestRacer.getLastName()
)
)
).build();
}
return ResponseEntity.ok(RacerWSTO.of(actualRacer));
}
catch (RacerNotFoundException e){
return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND, e.getMessage())).build();
}
catch (IllegalArgumentException e) {
return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, e.getMessage())).build();
}
}
@GetMapping("byTeam")
public ResponseEntity<@NonNull List<RacerWSTO>> getByTeam(@RequestBody TeamWSTO requestTeamWSTO){
public ResponseEntity<@NonNull List<RacerWSTO>> getByTeam(@RequestBody Team requestTeam){
Team dbTeam;
try {
dbTeam = teamService.getTeam(TeamWSTO.toEntity(requestTeamWSTO));
dbTeam = teamService.getTeam(requestTeam);
} catch (TeamNotFoundException e) {
return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND, e.getMessage())).build();
}
@@ -81,8 +81,7 @@ public class RacerRestController {
// ////////////////////////////////////////////////BEGIN DELETE MAPPINGS///////////////////////////////////////////////////
@DeleteMapping("/removeRacer")
public ResponseEntity<?> removeRacer(@RequestBody RacerWSTO racerWSTO){
Racer racer = RacerWSTO.toEntity(racerWSTO);
public ResponseEntity<?> removeRacer(@RequestBody Racer racer){
try {
racerService.deleteRacer(racer);
return ResponseEntity.ok(racer);

View File

@@ -5,7 +5,6 @@ import de.pnreichmuth.timekeep_backend.entities.Team;
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;
@@ -24,10 +23,9 @@ public class TeamMemberRestController {
// ///////////////////////////////////////////////BEGIN POST MAPPINGS///////////////////////////////////////////////////
@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();
mockTeam.setTeamName(teamName);
Racer racer = RacerWSTO.toEntity(racerWsto);
try{
this.teamService.addMember(mockTeam,racer);
}
@@ -41,10 +39,9 @@ public class TeamMemberRestController {
}
// ///////////////////////////////////////////////BEGIN DELETE MAPPINGS///////////////////////////////////////////////////
@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();
mockTeam.setTeamName(teamName);
Racer racer = RacerWSTO.toEntity(racerWsto);
try{
this.teamService.removeMember(mockTeam,racer);
}

View File

@@ -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
*/
@PostMapping("createTeam")
public ResponseEntity<@NonNull TeamWSTO> createTeam(@RequestBody TeamWSTO teamwsto){
Team team = TeamWSTO.toEntity(teamwsto);
public ResponseEntity<@NonNull TeamWSTO> createTeam(@RequestBody Team team){
try {
teamService.createTeam(team);
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
* @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.
*/
@GetMapping("single-team")
public ResponseEntity<@NonNull TeamWSTO> getSingleTeam(@RequestBody TeamWSTO reqTeamWSTO){
Team reqTeam = TeamWSTO.toEntity(reqTeamWSTO);
public ResponseEntity<@NonNull TeamWSTO> getSingleTeam(@RequestBody Team reqTeam){
UUID id = reqTeam.getId();
String name = reqTeam.getTeamName();
Team actualTeam;
@@ -102,13 +100,12 @@ public class TeamRestController {
/**
* 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,
* or a ResponseEntity containing either BAD_REQUEST or NOT_FOUND.
*/
@DeleteMapping("single-team")
public ResponseEntity<@NonNull String> deleteTeam(@RequestBody TeamWSTO teamWSTO){
Team team = TeamWSTO.toEntity(teamWSTO);
public ResponseEntity<@NonNull String> deleteTeam(@RequestBody Team team){
String name = team.getTeamName();
UUID id = team.getId();
try {