mirror of
https://github.com/PaulReichmuth/timekeep-backend.git
synced 2026-02-06 04:53:25 +00:00
begin switch to WSTO architecture
This commit is contained in:
@@ -4,17 +4,16 @@ import de.pnreichmuth.timekeep_backend.entities.Team;
|
||||
import de.pnreichmuth.timekeep_backend.exceptions.TeamExistsException;
|
||||
import de.pnreichmuth.timekeep_backend.exceptions.TeamNotFoundException;
|
||||
import de.pnreichmuth.timekeep_backend.services.TeamService;
|
||||
import de.pnreichmuth.timekeep_backend.wsto.TeamWSTO;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.antlr.v4.runtime.misc.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ProblemDetail;
|
||||
import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -27,36 +26,41 @@ public class TeamRestController {
|
||||
private final TeamService teamService;
|
||||
|
||||
@PostMapping("createTeam")
|
||||
public ResponseEntity<Team> createTeam(@RequestBody Team team){
|
||||
public ResponseEntity<@NonNull TeamWSTO> createTeam(@RequestBody Team team){
|
||||
try {
|
||||
teamService.createTeam(team);
|
||||
return new ResponseEntity<>(team, HttpStatus.CREATED);
|
||||
return new ResponseEntity<>(TeamWSTO.of(team), HttpStatus.CREATED);
|
||||
} catch (TeamExistsException e) {
|
||||
return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.CONFLICT,"This team already exists")).build();
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("createTeamDebug")
|
||||
public ResponseEntity<Team> createTeam(){
|
||||
public ResponseEntity<@NonNull TeamWSTO> createTeam(){
|
||||
try {
|
||||
Team team = teamService.createTeam();
|
||||
return new ResponseEntity<>(team, HttpStatus.CREATED);
|
||||
team.setTeamName("DEBUG");
|
||||
return new ResponseEntity<>(TeamWSTO.of(team), HttpStatus.CREATED);
|
||||
} catch (TeamExistsException e) {
|
||||
return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.CONFLICT,"This team already exists")).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("all")
|
||||
public ResponseEntity<@NonNull List<Team>> getAllTeams(){
|
||||
public ResponseEntity<@NonNull List<TeamWSTO>> getAllTeams(){
|
||||
List<Team> teams = teamService.getTeams();
|
||||
List<TeamWSTO> teamWSTOs = new ArrayList<>();
|
||||
if(teams.isEmpty()){
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
return new ResponseEntity<>(teams, HttpStatus.OK);
|
||||
for(Team team : teams){
|
||||
teamWSTOs.add(TeamWSTO.of(team));
|
||||
}
|
||||
return new ResponseEntity<>(teamWSTOs, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("single-team")
|
||||
public ResponseEntity<@NonNull Team> getSingleTeam(@RequestBody Team reqTeam){
|
||||
public ResponseEntity<@NonNull TeamWSTO> getSingleTeam(@RequestBody Team reqTeam){
|
||||
UUID id = reqTeam.getId();
|
||||
String name = reqTeam.getTeamName();
|
||||
Team actualTeam;
|
||||
@@ -68,7 +72,7 @@ public class TeamRestController {
|
||||
actualTeam = teamService.getTeam(name);
|
||||
}
|
||||
else return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, "Must provide either id or name")).build();
|
||||
return new ResponseEntity<>(actualTeam, HttpStatus.OK);
|
||||
return new ResponseEntity<>(TeamWSTO.of(actualTeam), HttpStatus.OK);
|
||||
}
|
||||
catch(TeamNotFoundException e){
|
||||
if(id != null) return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND,"Team with id "+ id +" not found")).build();
|
||||
|
||||
Reference in New Issue
Block a user