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

implemented querie for multiple OPStaff with getOPStaffs().

parent 96978a9e
No related branches found
No related tags found
No related merge requests found
...@@ -20,4 +20,6 @@ public interface OPStaffService { ...@@ -20,4 +20,6 @@ public interface OPStaffService {
*/ */
public Optional<OPStaff> getOPStaff(Id<OPStaff> id); public Optional<OPStaff> getOPStaff(Id<OPStaff> id);
public List<OPStaff> getOPStaffs();
} }
\ No newline at end of file
import java.time.Instant; import java.time.Instant;
import java.util.Optional; import java.util.Optional;
import java.util.List;
public class OPStaffServiceImpl implements OPStaffService{ public class OPStaffServiceImpl implements OPStaffService{
...@@ -31,11 +32,15 @@ public class OPStaffServiceImpl implements OPStaffService{ ...@@ -31,11 +32,15 @@ public class OPStaffServiceImpl implements OPStaffService{
return opStaff; return opStaff;
} }
@Override
public Optional<OPStaff> getOPStaff(Id<OPStaff> id) {
public Optional<OPStaff> getOPStaff(Id<OPStaff> id) {
return repo.findOPStaff(id); return repo.findOPStaff(id);
} }
public List<OPStaff> getOPStaffs(){
return repo.findOPStaffs();
}
} }
...@@ -71,4 +71,6 @@ public interface Repository { ...@@ -71,4 +71,6 @@ public interface Repository {
Optional<OPStaff> findOPStaff(Id<OPStaff> id); Optional<OPStaff> findOPStaff(Id<OPStaff> id);
List<OPStaff> findOPStaffs();
} }
...@@ -479,6 +479,32 @@ class JDBCRepository implements Repository ...@@ -479,6 +479,32 @@ class JDBCRepository implements Repository
} }
} }
/**
* Reads an OPStaff from the OPStaff-SQLTable with the given ID.
* If no OPStaff with this ID is found, it will return an empty Optional.
* @return the found Operation
*/
@Override
public List<OPStaff> findOPStaffs(){
try (
var result =
conn.createStatement()
.executeQuery("SELECT * FROM opstaff;")
){
var opStaffs = new ArrayList<OPStaff>();
while(result.next()){
opStaffs.add(readOPStaffFromRow(result));
}
return opStaffs;
} catch (SQLException e){
throw new RuntimeException(e);
}
}
/** /**
* Creates an Operation object with the given result of a read SQL-Row. * Creates an Operation object with the given result of a read SQL-Row.
* @param rs the result of a read SQL-Row * @param rs the result of a read SQL-Row
......
...@@ -213,7 +213,7 @@ public final class Tests ...@@ -213,7 +213,7 @@ public final class Tests
OPStaff createOPStaff = opStaffService.process(createCommand); OPStaff createOPStaff = opStaffService.process(createCommand);
} }
@Test //@Test
public void testGetOPStaff() { public void testGetOPStaff() {
try{ try{
...@@ -223,7 +223,22 @@ public final class Tests ...@@ -223,7 +223,22 @@ public final class Tests
} catch (Exception e){ } catch (Exception e){
e.printStackTrace(); e.printStackTrace();
} }
//assertEquals(operation.date(), testDate);
}
@Test
public void testGetOPStaffs() {
try{
List<OPStaff> opStaff = opStaffService.getOPStaffs();
for(OPStaff opStaff1 : opStaff){
System.out.println(opStaff1);
}
} catch (Exception e){
e.printStackTrace();
}
//assertEquals(operation.date(), testDate); //assertEquals(operation.date(), testDate);
} }
} }
......
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