|
@@ -1,19 +1,27 @@
|
|
|
package eu.jovian_hersemeule.dev.squad.squad_composer.controllers;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import eu.jovian_hersemeule.dev.squad.squad_composer.data.input.NewSquad;
|
|
|
+import eu.jovian_hersemeule.dev.squad.squad_composer.data.jpa.SquadEntity;
|
|
|
import eu.jovian_hersemeule.dev.squad.squad_composer.data.projections.SquadDetails;
|
|
|
import eu.jovian_hersemeule.dev.squad.squad_composer.data.projections.SquadItem;
|
|
|
import eu.jovian_hersemeule.dev.squad.squad_composer.data.repos.SquadRepository;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.logging.Logger;
|
|
|
+
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/squads")
|
|
|
public class SquadController {
|
|
|
|
|
|
+ final private Logger logger = Logger.getLogger(SquadController.class.getName());
|
|
|
+
|
|
|
final private SquadRepository repo;
|
|
|
|
|
|
SquadController(final SquadRepository squadRepository) {
|
|
@@ -22,6 +30,7 @@ public class SquadController {
|
|
|
|
|
|
@GetMapping("/")
|
|
|
public List<SquadItem> list() {
|
|
|
+ logger.fine("Listing squads");
|
|
|
return repo.findAll().stream()
|
|
|
.map(SquadItem::project)
|
|
|
.toList();
|
|
@@ -29,9 +38,17 @@ public class SquadController {
|
|
|
|
|
|
@GetMapping("/{id}")
|
|
|
public SquadDetails get(@PathVariable final long id) {
|
|
|
+ logger.fine("Getting squad " + id);
|
|
|
return repo.findById(id)
|
|
|
.map(SquadDetails::project)
|
|
|
.orElseThrow(() -> new RuntimeException("Squad not found"));
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/")
|
|
|
+ public SquadDetails create(final NewSquad newSquad) {
|
|
|
+ logger.info("Creating squad " + newSquad);
|
|
|
+ final SquadEntity newEntity = repo.save(newSquad.buildEntity());
|
|
|
+ return SquadDetails.project(newEntity);
|
|
|
+ }
|
|
|
+
|
|
|
}
|