Преглед изворни кода

:wrench: Premiere route post

Tous les champs du record d'entree sont null, oups.
DricomDragon пре 1 месец
родитељ
комит
a201580e9e

+ 17 - 0
dev-back/src/main/java/eu/jovian_hersemeule/dev/squad/squad_composer/controllers/SquadController.java

@@ -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);
+    }
+
 }

+ 18 - 0
dev-back/src/main/java/eu/jovian_hersemeule/dev/squad/squad_composer/data/input/NewSquad.java

@@ -0,0 +1,18 @@
+package eu.jovian_hersemeule.dev.squad.squad_composer.data.input;
+
+import eu.jovian_hersemeule.dev.squad.squad_composer.data.jpa.SquadEntity;
+
+public record NewSquad(String name, String comment, Integer mech1Id, Integer mech2Id, Integer mech3Id) {
+
+    public SquadEntity buildEntity() {
+        var newEntity = new SquadEntity();
+
+        newEntity.setName(name);
+        newEntity.setComment(comment);
+        newEntity.setMech1Id(mech1Id);
+        newEntity.setMech2Id(mech2Id);
+        newEntity.setMech3Id(mech3Id);
+
+        return newEntity;
+    }
+};

+ 1 - 1
dev-back/src/main/java/eu/jovian_hersemeule/dev/squad/squad_composer/data/jpa/SquadEntity.java

@@ -16,7 +16,7 @@ public class SquadEntity {
     @JoinColumn(name = "player_id", insertable = false, updatable = false)
     private PlayerEntity player;
 
-    @Column(name = "creation_date", nullable = false)
+    @Column(name = "creation_date")
     private Timestamp creationDate;
 
     @Column(name = "name", nullable = false, length = 50)

+ 1 - 1
dev-back/src/main/resources/logback.xml

@@ -2,7 +2,7 @@
 <configuration>
     <include resource="org/springframework/boot/logging/logback/base.xml"/>
 
-    <logger name="org.flywaydb" level="DEBUG"/>
+    <logger name="eu.jovian_hersemeule.dev" level="DEBUG"/>
 
     <root level="INFO">
         <appender-ref ref="CONSOLE"/>

Разлика између датотеке није приказан због своје велике величине
+ 8 - 1
tools/api/SquadComposer-soapui-project.xml