Skip to content
Snippets Groups Projects
Commit 9f6bd1d5 authored by Alexander Görlitz's avatar Alexander Görlitz
Browse files

preparatioNote command create and update working

parent 753e756e
No related branches found
No related tags found
No related merge requests found
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 {}
}
......@@ -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;
}
......
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment