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

preparatioNote command for delete working

parent 9f6bd1d5
No related merge requests found
......@@ -11,7 +11,7 @@ public record PreparationNote (
Instant lastUpdate
) {
public static sealed interface Command permits Create, Update { } //Update, Delete
public static sealed interface Command permits Create, Update, Delete { }
public static record Create(
String note,
......@@ -23,5 +23,9 @@ public record PreparationNote (
String note
) implements Command {}
public static record Delete(
Id<PreparationNote> id
) implements Command {}
}
......@@ -14,7 +14,7 @@ public class PreparationNoteImpl implements PreparationNoteService {
return switch (cmd){
case PreparationNote.Create cr -> create(cr);
case PreparationNote.Update up -> update(up);
//case PreparationNote.Delete del -> delete(del);
case PreparationNote.Delete del -> delete(del);
};
}
......@@ -52,10 +52,20 @@ public class PreparationNoteImpl implements PreparationNoteService {
return preparationNote;
}
public Optional<PreparationNote> findPreparationNote(Id<PreparationNote> id){
private PreparationNote delete(PreparationNote.Delete del) throws Exception {
Optional<PreparationNote> returnedPreparationNote = repo.findPreparationNote(del.id());
if(returnedPreparationNote.isPresent()) {
return repo.deletePreparationNote(del.id());
}
return null;
}
public Optional<PreparationNote> findPreparationNote(Id<PreparationNote> id){
return repo.findPreparationNote(id);
}
}
......@@ -106,4 +106,6 @@ public interface Repository {
Optional<PreparationNote> findPreparationNote(Id<PreparationNote> id);
void save(PreparationNote preparationNote);
PreparationNote deletePreparationNote(Id<PreparationNote> id);
}
......@@ -907,6 +907,23 @@ class JDBCRepository implements Repository
");";
}
@Override
public PreparationNote deletePreparationNote(Id<PreparationNote> id) {
var preparationNote = findPreparationNote(id);
if(preparationNote.isPresent()) {
var sql = "DELETE FROM preparationNote WHERE id = " + quoted(id.value()) + ";";
try {
conn.createStatement().executeUpdate(sql);
return preparationNote.get();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
return null;
}
}
......
......@@ -170,6 +170,22 @@ public final class Tests
}
}
@Ignore
@Test
public void testDeletePreparationNote() throws Exception {
repo.save(testPreparationNote);
PreparationNote.Delete deleteCommand = new PreparationNote.Delete(
testPreparationNote.id()
);
PreparationNote deletePreparationNote = preparationNoteService.process(deleteCommand);
assertFalse(repo.findPreparationNote(deletePreparationNote.id()).isPresent());
}
@Ignore
@Test
public void testRepoPreparationNoteSave(){
......
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