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

implemented delete for OPStaff.

parent ae22b551
No related merge requests found
...@@ -13,7 +13,7 @@ public record OPStaff( ...@@ -13,7 +13,7 @@ public record OPStaff(
/** /**
* OPStaff commands * OPStaff commands
*/ */
public static sealed interface Command permits OPStaff.CreateOPStaff, OPStaff.UpdateOPStaff { } //OPStaff.DeleteOPStaff public static sealed interface Command permits OPStaff.CreateOPStaff, OPStaff.DeleteOPStaff, OPStaff.UpdateOPStaff { }
/** /**
* Create command to create a new Operation * Create command to create a new Operation
...@@ -31,5 +31,8 @@ public record OPStaff( ...@@ -31,5 +31,8 @@ public record OPStaff(
Optional<Specialty> specialty Optional<Specialty> specialty
) implements Command {} ) implements Command {}
public static record DeleteOPStaff(
Id<OPStaff> id
) implements Command {}
} }
...@@ -15,7 +15,7 @@ public class OPStaffServiceImpl implements OPStaffService{ ...@@ -15,7 +15,7 @@ public class OPStaffServiceImpl implements OPStaffService{
return switch (cmd){ return switch (cmd){
case OPStaff.CreateOPStaff cr -> createOPStaffimpl(cr); case OPStaff.CreateOPStaff cr -> createOPStaffimpl(cr);
case OPStaff.UpdateOPStaff up -> updateOPStaffimpl(up); case OPStaff.UpdateOPStaff up -> updateOPStaffimpl(up);
//case OPStaff.Delete del -> delete(del); case OPStaff.DeleteOPStaff del -> deleteOPStaffimpl(del);
}; };
} }
...@@ -47,6 +47,15 @@ public class OPStaffServiceImpl implements OPStaffService{ ...@@ -47,6 +47,15 @@ public class OPStaffServiceImpl implements OPStaffService{
return opStaff; return opStaff;
} }
public OPStaff deleteOPStaffimpl(OPStaff.DeleteOPStaff del) throws Exception{
OPStaff opStaff = repo.findOPStaff(del.id()).get();
repo.deleteOPStaff(del.id());
return opStaff;
}
public Optional<OPStaff> getOPStaff(Id<OPStaff> id) { public Optional<OPStaff> getOPStaff(Id<OPStaff> id) {
return repo.findOPStaff(id); return repo.findOPStaff(id);
......
...@@ -73,4 +73,6 @@ public interface Repository { ...@@ -73,4 +73,6 @@ public interface Repository {
List<OPStaff> findOPStaffs(); List<OPStaff> findOPStaffs();
void deleteOPStaff(Id<OPStaff> id) throws SQLException;
} }
...@@ -536,6 +536,18 @@ class JDBCRepository implements Repository ...@@ -536,6 +536,18 @@ class JDBCRepository implements Repository
"WHERE id = " + sqlValue(opStaff.id().value()) + ";"; "WHERE id = " + sqlValue(opStaff.id().value()) + ";";
} }
@Override
public void deleteOPStaff(Id<OPStaff> id) throws SQLException{
var opStaff = findOPStaff(id);
if(opStaff.isPresent()) {
conn.createStatement().executeUpdate(
"DELETE FROM opstaff WHERE id = " + quoted(id.value()) + ";");
}
}
} }
......
...@@ -226,7 +226,7 @@ public final class Tests ...@@ -226,7 +226,7 @@ public final class Tests
//assertEquals(operation.date(), testDate); //assertEquals(operation.date(), testDate);
} }
//@Test //@Test //getting all the OPStaffs
public void testGetOPStaffs() { public void testGetOPStaffs() {
try{ try{
...@@ -242,7 +242,7 @@ public final class Tests ...@@ -242,7 +242,7 @@ public final class Tests
//assertEquals(operation.date(), testDate); //assertEquals(operation.date(), testDate);
} }
@Test //@Test
public void testUpdateOPStaff() throws Exception{ public void testUpdateOPStaff() throws Exception{
OPStaff.UpdateOPStaff updateCommand = new OPStaff.UpdateOPStaff( OPStaff.UpdateOPStaff updateCommand = new OPStaff.UpdateOPStaff(
...@@ -254,6 +254,20 @@ public final class Tests ...@@ -254,6 +254,20 @@ public final class Tests
OPStaff updateOPStaff = opStaffService.process(updateCommand); OPStaff updateOPStaff = opStaffService.process(updateCommand);
} }
//@Test
public void testDeleteOPStaff() throws Exception{
var id = new Id<OPStaff>("b940de7b-a9a3-40e5-b465-12b018390061");
OPStaff.DeleteOPStaff deleteCommand = new OPStaff.DeleteOPStaff(
id
);
OPStaff deleteOPStaff = opStaffService.process(deleteCommand);
}
} }
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