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