|
@@ -1,8 +1,8 @@
|
|
package eu.jovian_hersemeule.dev.squad.squad_composer.controllers;
|
|
package eu.jovian_hersemeule.dev.squad.squad_composer.controllers;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
-import eu.jovian_hersemeule.dev.squad.squad_composer.data.jpa.PlayerEntity;
|
|
|
|
import eu.jovian_hersemeule.dev.squad.squad_composer.data.projections.PlayerItem;
|
|
import eu.jovian_hersemeule.dev.squad.squad_composer.data.projections.PlayerItem;
|
|
|
|
+import eu.jovian_hersemeule.dev.squad.squad_composer.data.projections.SquadItem;
|
|
import eu.jovian_hersemeule.dev.squad.squad_composer.data.repos.PlayerRepository;
|
|
import eu.jovian_hersemeule.dev.squad.squad_composer.data.repos.PlayerRepository;
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -22,17 +22,25 @@ public class PlayerController {
|
|
}
|
|
}
|
|
|
|
|
|
@GetMapping("/")
|
|
@GetMapping("/")
|
|
- public List<PlayerItem> list() {
|
|
|
|
|
|
+ public List<PlayerItem> listPlayers() {
|
|
return repo.findAll().stream()
|
|
return repo.findAll().stream()
|
|
.map(PlayerItem::project)
|
|
.map(PlayerItem::project)
|
|
.toList();
|
|
.toList();
|
|
}
|
|
}
|
|
|
|
|
|
@GetMapping("/{id}")
|
|
@GetMapping("/{id}")
|
|
- public PlayerItem get(@PathVariable final long id) {
|
|
|
|
|
|
+ public PlayerItem getASpecificPlayer(@PathVariable final long id) {
|
|
return repo.findById(id)
|
|
return repo.findById(id)
|
|
.map(PlayerItem::project)
|
|
.map(PlayerItem::project)
|
|
.orElseThrow(() -> new RuntimeException("Player not found"));
|
|
.orElseThrow(() -> new RuntimeException("Player not found"));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @GetMapping("/{id}/squads")
|
|
|
|
+ public List<SquadItem> getSquadsOfPlayer(@PathVariable final long id) {
|
|
|
|
+ return repo.findById(id).stream()
|
|
|
|
+ .flatMap(player -> player.getSquads().stream())
|
|
|
|
+ .map(SquadItem::project)
|
|
|
|
+ .toList();
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|