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

updated the method delete(OperationTeam), removeStaff() has now the according...

updated the method delete(OperationTeam), removeStaff() has now the according return object with no opStaffs, deleteOPStaff() will now querie if the opStaff is in a team
parent ca56d37c
No related branches found
No related tags found
No related merge requests found
...@@ -55,8 +55,10 @@ public class OPStaffServiceImpl implements OPStaffService{ ...@@ -55,8 +55,10 @@ public class OPStaffServiceImpl implements OPStaffService{
public OPStaff delete(OPStaff.Delete del) throws Exception{ public OPStaff delete(OPStaff.Delete del) throws Exception{
return repo.deleteOPStaff(del.id()); if(repo.findOPStaffOperationTeams(del.id())==false){ //wenn false, dann ist er keinem team zugewiesen
return repo.deleteOPStaff(del.id());
}
return null;
} }
@Override @Override
......
import java.sql.SQLException; import java.sql.SQLException;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
...@@ -22,8 +23,23 @@ public class OperationTeamImpl implements OperationTeamService{ ...@@ -22,8 +23,23 @@ public class OperationTeamImpl implements OperationTeamService{
}; };
} }
private OperationTeam delete(OperationTeam.Delete del) throws SQLException { private OperationTeam delete(OperationTeam.Delete del) throws Exception {
return repo.deleteOperationTeam(del.operationTeamId());
Optional<OperationTeam> returnedOperationTeam = repo.findOperationTeam(del.operationTeamId());
if(returnedOperationTeam.isPresent()) {
if (returnedOperationTeam.get().opStaffs().isEmpty()) {
return repo.deleteOperationTeam(del.operationTeamId());
} else {
int sizeOPStafflist = returnedOperationTeam.get().opStaffs().size();
for(int i = 0; i<sizeOPStafflist; i++){
repo.removeOPStaffInOperationTeam(del.operationTeamId(),returnedOperationTeam.get().opStaffs().get(i).id());
}
return repo.deleteOperationTeam(del.operationTeamId());
}
}
return null;
} }
//Only creates a connection between the newly created operationTeam and the already existing opStaffs. //Only creates a connection between the newly created operationTeam and the already existing opStaffs.
...@@ -65,10 +81,13 @@ public class OperationTeamImpl implements OperationTeamService{ ...@@ -65,10 +81,13 @@ public class OperationTeamImpl implements OperationTeamService{
private OperationTeam removeStaff(OperationTeam.RemoveStaff rs) throws Exception { private OperationTeam removeStaff(OperationTeam.RemoveStaff rs) throws Exception {
OperationTeam findOperationTeam = repo.getOperationTeam(rs.operationTeamId()); Optional<OperationTeam> findOperationTeam = repo.findOperationTeam(rs.operationTeamId());
if(repo.removeOPStaffInOperationTeam(rs.operationTeamId(), rs.opStaffId())){ if(findOperationTeam.isPresent()){
return findOperationTeam; if(repo.removeOPStaffInOperationTeam(rs.operationTeamId(), rs.opStaffId())){
Optional<OperationTeam> newOperationTeam = repo.findOperationTeam(rs.operationTeamId());
return newOperationTeam.get();
}
} }
return null; return null;
} }
......
...@@ -97,4 +97,6 @@ public interface Repository { ...@@ -97,4 +97,6 @@ public interface Repository {
Boolean findOperationTeamOPStaff(Id<OperationTeam> operationTeamId, Id<OPStaff> opStaffId); Boolean findOperationTeamOPStaff(Id<OperationTeam> operationTeamId, Id<OPStaff> opStaffId);
Boolean findOPStaffOperationTeams(Id<OPStaff> opStaffId);
} }
...@@ -763,6 +763,22 @@ class JDBCRepository implements Repository ...@@ -763,6 +763,22 @@ class JDBCRepository implements Repository
} }
} }
@Override
public Boolean findOPStaffOperationTeams(Id<OPStaff> opStaffId){
try(
var result =
conn.createStatement()
.executeQuery("SELECT * " +
"FROM opStaffsInOperationTeams " +
"WHERE opStaffsInOperationTeams.opStaffId = " + quoted(opStaffId.value()) + ";")
) {
return result.next();
}catch(SQLException e){
throw new RuntimeException(e);
}
}
/* /*
@Override @Override
public List<OPStaff> getOperationTeamOPStaffImpl(Id<OperationTeam> operationTeamId){ public List<OPStaff> getOperationTeamOPStaffImpl(Id<OperationTeam> operationTeamId){
......
...@@ -98,6 +98,7 @@ public final class Tests ...@@ -98,6 +98,7 @@ public final class Tests
} }
@Ignore
@Test @Test
public void testRepoOperationSave(){ public void testRepoOperationSave(){
...@@ -113,6 +114,7 @@ public final class Tests ...@@ -113,6 +114,7 @@ public final class Tests
); );
} }
@Ignore
@Test @Test
public void testRepoOperationUpdate() throws Exception { public void testRepoOperationUpdate() throws Exception {
...@@ -148,6 +150,7 @@ public final class Tests ...@@ -148,6 +150,7 @@ public final class Tests
} }
} }
@Ignore
@Test @Test
public void testRepoOperationDelete() { public void testRepoOperationDelete() {
try { try {
...@@ -166,7 +169,7 @@ public final class Tests ...@@ -166,7 +169,7 @@ public final class Tests
assertFalse(repo.findOperation(testOperation.id()).isPresent()); assertFalse(repo.findOperation(testOperation.id()).isPresent());
} }
@Ignore
@Test @Test
public void testCreateOperation() throws Exception { public void testCreateOperation() throws Exception {
...@@ -186,7 +189,7 @@ public final class Tests ...@@ -186,7 +189,7 @@ public final class Tests
repo.findOperation(createdOperation.id()).isPresent() repo.findOperation(createdOperation.id()).isPresent()
); );
} }
@Ignore
@Test @Test
public void testUpdateOperation() throws Exception { public void testUpdateOperation() throws Exception {
...@@ -218,7 +221,7 @@ public final class Tests ...@@ -218,7 +221,7 @@ public final class Tests
throw new Exception(); throw new Exception();
} }
} }
@Ignore
@Test @Test
public void testDeleteOperation() throws Exception { public void testDeleteOperation() throws Exception {
...@@ -234,6 +237,7 @@ public final class Tests ...@@ -234,6 +237,7 @@ public final class Tests
assertFalse(repo.findOperation(deleteOperation.id()).isPresent()); assertFalse(repo.findOperation(deleteOperation.id()).isPresent());
} }
@Ignore
@Test @Test
public void testGetOperation() throws Exception { public void testGetOperation() throws Exception {
repo.save(testOperationTeam1); repo.save(testOperationTeam1);
...@@ -253,6 +257,7 @@ public final class Tests ...@@ -253,6 +257,7 @@ public final class Tests
} }
} }
@Ignore
@Test @Test
public void testGetOperations() throws Exception { public void testGetOperations() throws Exception {
...@@ -270,7 +275,7 @@ public final class Tests ...@@ -270,7 +275,7 @@ public final class Tests
assertEquals(operation.date(), testDate); assertEquals(operation.date(), testDate);
} }
} }
@Ignore
@Test @Test
public void testRepoOPStaffSave(){ public void testRepoOPStaffSave(){
...@@ -284,7 +289,7 @@ public final class Tests ...@@ -284,7 +289,7 @@ public final class Tests
repo.findOPStaff(testOPStaff1.id()).isPresent() repo.findOPStaff(testOPStaff1.id()).isPresent()
); );
} }
@Ignore
@Test @Test
public void testRepoOPStaffUpdate() throws Exception { public void testRepoOPStaffUpdate() throws Exception {
...@@ -316,6 +321,7 @@ public final class Tests ...@@ -316,6 +321,7 @@ public final class Tests
} }
} }
@Ignore
@Test @Test
public void testRepoOPStaffDelete() { public void testRepoOPStaffDelete() {
try { try {
...@@ -333,6 +339,7 @@ public final class Tests ...@@ -333,6 +339,7 @@ public final class Tests
assertFalse(repo.findOPStaff(testOPStaff1.id()).isPresent()); assertFalse(repo.findOPStaff(testOPStaff1.id()).isPresent());
} }
@Ignore
@Test @Test
public void testCreateOPStaff() throws Exception { public void testCreateOPStaff() throws Exception {
...@@ -348,6 +355,7 @@ public final class Tests ...@@ -348,6 +355,7 @@ public final class Tests
); );
} }
@Ignore
@Test @Test
public void testUpdateOPStaff() throws Exception { public void testUpdateOPStaff() throws Exception {
...@@ -374,6 +382,7 @@ public final class Tests ...@@ -374,6 +382,7 @@ public final class Tests
} }
} }
@Ignore
@Test @Test
public void testDeleteOPStaff() throws Exception { public void testDeleteOPStaff() throws Exception {
...@@ -388,6 +397,7 @@ public final class Tests ...@@ -388,6 +397,7 @@ public final class Tests
assertFalse(repo.findOPStaff(deletedOPStaff.id()).isPresent()); assertFalse(repo.findOPStaff(deletedOPStaff.id()).isPresent());
} }
@Ignore
@Test @Test
public void testGetOPStaff() throws Exception { public void testGetOPStaff() throws Exception {
repo.save(testOPStaff1); repo.save(testOPStaff1);
...@@ -403,6 +413,7 @@ public final class Tests ...@@ -403,6 +413,7 @@ public final class Tests
} }
} }
@Ignore
@Test @Test
public void testGetOPStaffs() throws Exception { public void testGetOPStaffs() throws Exception {
...@@ -419,6 +430,7 @@ public final class Tests ...@@ -419,6 +430,7 @@ public final class Tests
assertEquals(2, filteredList.size()); assertEquals(2, filteredList.size());
} }
@Ignore
@Test @Test
public void testRepoOperationTeamAssignStaff(){ public void testRepoOperationTeamAssignStaff(){
...@@ -441,6 +453,7 @@ public final class Tests ...@@ -441,6 +453,7 @@ public final class Tests
} }
} }
@Ignore
@Test @Test
public void testCreateOperationTeam() throws Exception { public void testCreateOperationTeam() throws Exception {
...@@ -494,8 +507,7 @@ public final class Tests ...@@ -494,8 +507,7 @@ public final class Tests
throw new Exception(); throw new Exception();
} }
} }
@Ignore
@Ignore
@Test @Test
public void testRepoOperationTeamDelete() { public void testRepoOperationTeamDelete() {
try { try {
...@@ -517,6 +529,7 @@ public final class Tests ...@@ -517,6 +529,7 @@ public final class Tests
assertFalse(repo.findOperationTeam(testOperationTeam1.id()).isPresent()); assertFalse(repo.findOperationTeam(testOperationTeam1.id()).isPresent());
} }
@Ignore @Ignore
@Test @Test
public void testDeleteOperationTeam() throws Exception { public void testDeleteOperationTeam() throws Exception {
...@@ -581,7 +594,7 @@ public final class Tests ...@@ -581,7 +594,7 @@ public final class Tests
assertTrue(result); assertTrue(result);
} }
@Ignore @Ignore
@Test @Test
public void testAssignStaffToOperationTeam() throws Exception { public void testAssignStaffToOperationTeam() throws Exception {
...@@ -600,7 +613,10 @@ public final class Tests ...@@ -600,7 +613,10 @@ public final class Tests
assertTrue(result); assertTrue(result);
} }
@Ignore
@Ignore
@Test @Test
public void testRemoveOPStaffsInOperationTeams() throws Exception{ public void testRemoveOPStaffsInOperationTeams() throws Exception{
...@@ -612,6 +628,7 @@ public final class Tests ...@@ -612,6 +628,7 @@ public final class Tests
OperationTeam removedTeam = operationTeamService.process(removeStaffCommand); OperationTeam removedTeam = operationTeamService.process(removeStaffCommand);
assertEquals(testOperationTeam1.id().value(), removedTeam.id().value()); assertEquals(testOperationTeam1.id().value(), removedTeam.id().value());
assertFalse(repo.findOperationTeamOPStaff(testOperationTeam1.id(), testOPStaff1.id()));
} }
} }
......
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