diff --git a/opp/core/src/main/java/PreparationNote.java b/opp/core/src/main/java/PreparationNote.java
index 958257d223e7c3a917452f4a091ee21b775f6c88..435270b5be9f8ebc7d1b20d4e363631c1a7bbd72 100644
--- a/opp/core/src/main/java/PreparationNote.java
+++ b/opp/core/src/main/java/PreparationNote.java
@@ -1,6 +1,7 @@
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalTime;
+import java.util.Optional;
public record PreparationNote (
@@ -10,12 +11,17 @@ public record PreparationNote (
Instant lastUpdate
) {
- public static sealed interface Command permits Create { } //Update, Delete
+ public static sealed interface Command permits Create, Update { } //Update, Delete
public static record Create(
String note,
Id<Operation> operationsId
) implements Command {}
+ public static record Update(
+ Id<PreparationNote> id,
+ String note
+ ) implements Command {}
+
}
diff --git a/opp/core/src/main/java/PreparationNoteImpl.java b/opp/core/src/main/java/PreparationNoteImpl.java
index 112215a04850fb53882abf800cc117fd70257a90..f25bafd15ca8eebfa6c0af7b4b1cdc3cf75624fe 100644
--- a/opp/core/src/main/java/PreparationNoteImpl.java
+++ b/opp/core/src/main/java/PreparationNoteImpl.java
@@ -13,8 +13,8 @@ public class PreparationNoteImpl implements PreparationNoteService {
public PreparationNote process(PreparationNote.Command cmd) throws Exception {
return switch (cmd){
case PreparationNote.Create cr -> create(cr);
- //case Operation.Update up -> update(up);
- //case Operation.Delete del -> delete(del);
+ case PreparationNote.Update up -> update(up);
+ //case PreparationNote.Delete del -> delete(del);
};
}
@@ -31,6 +31,27 @@ public class PreparationNoteImpl implements PreparationNoteService {
return preparationNote;
}
+ public PreparationNote update(PreparationNote.Update up) throws Exception {
+
+ Optional<PreparationNote> foundPreparationNote = repo.findPreparationNote(up.id());
+
+ PreparationNote preparationNote = null;
+ if (foundPreparationNote.isPresent()) {
+ PreparationNote currentPreparationNote = foundPreparationNote.get();
+
+ preparationNote =
+ new PreparationNote(
+ currentPreparationNote.id(),
+ up.note(),
+ currentPreparationNote.operationsId(),
+ Instant.now());
+
+ repo.save(preparationNote);
+ }
+
+ return preparationNote;
+ }
+
public Optional<PreparationNote> findPreparationNote(Id<PreparationNote> id){
return null;
}
diff --git a/opp/jdbc-repo-impl/src/test/java/Tests.java b/opp/jdbc-repo-impl/src/test/java/Tests.java
index 35e0fcff0346ab1c6d26ac2b385e461c9d7324fb..7177ea7ee20a8bb5e0c774b8d069314dc56fa9b2 100644
--- a/opp/jdbc-repo-impl/src/test/java/Tests.java
+++ b/opp/jdbc-repo-impl/src/test/java/Tests.java
@@ -127,6 +127,49 @@ public final class Tests
);
}
+@Ignore
+ @Test
+ public void testCreatePreparationNote() throws Exception {
+
+ PreparationNote.Create createCommand = new PreparationNote.Create(
+ ("Notiz erstellt mit Command"),
+ testOperation.id()
+ );
+
+ PreparationNote createdPreparationNote = preparationNoteService.process(createCommand);
+
+ assertTrue(
+ repo.findPreparationNote(createdPreparationNote.id()).isPresent()
+ );
+ }
+
+
+ @Ignore
+ @Test
+ public void testUpdatePreparationNote() throws Exception {
+
+ PreparationNote.Update updateCommand = new PreparationNote.Update(
+ testPreparationNote.id(),
+ ("COmmand wurde hier geupdaet!?!?!?!?")
+ );
+
+ PreparationNote updatePreparationNote = preparationNoteService.process(updateCommand);
+
+ Optional<PreparationNote> readPreparationNote = repo.findPreparationNote(updatePreparationNote.id());
+
+ if (readPreparationNote.isPresent()) {
+ assertNotEquals(readPreparationNote.get().note(), testPreparationNote.note());
+
+ assertEquals(readPreparationNote.get().operationsId(), testPreparationNote.operationsId());
+
+ assertEquals(readPreparationNote.get().id(), testPreparationNote.id());
+
+ assertNotEquals(readPreparationNote.get().lastUpdate(), testPreparationNote.lastUpdate());
+ } else {
+ throw new Exception();
+ }
+ }
+
@Ignore
@Test
public void testRepoPreparationNoteSave(){
@@ -144,6 +187,7 @@ public final class Tests
+ @Ignore
@Test
public void testRepoPreparationNoteUpdate() throws Exception {