diff --git a/opp/core/src/main/java/OPStaffService.java b/opp/core/src/main/java/OPStaffService.java index d08b1a7c47b29fd2d67ceb200c80014d675529e3..679b57ef64cc6a3f354ececfea3b1cd9c578ac84 100644 --- a/opp/core/src/main/java/OPStaffService.java +++ b/opp/core/src/main/java/OPStaffService.java @@ -18,6 +18,6 @@ public interface OPStaffService { * @param id the ID of the OPStaff * @return the OPStaff */ - public Optional<OPStaff> getOPStaff(Id<Operation> id); + public Optional<OPStaff> getOPStaff(Id<OPStaff> id); } \ No newline at end of file diff --git a/opp/core/src/main/java/OPStaffServiceImpl.java b/opp/core/src/main/java/OPStaffServiceImpl.java index fadda58347d8f9aaa3e9ef668226f46a3124f95b..4b33714ffe51a808f9b1f4187e1b35d67e1c5af5 100644 --- a/opp/core/src/main/java/OPStaffServiceImpl.java +++ b/opp/core/src/main/java/OPStaffServiceImpl.java @@ -32,7 +32,10 @@ public class OPStaffServiceImpl implements OPStaffService{ } @Override - public Optional<OPStaff> getOPStaff(Id<Operation> id) { - return Optional.empty(); + public Optional<OPStaff> getOPStaff(Id<OPStaff> id) { + + return repo.findOPStaff(id); } + + } diff --git a/opp/core/src/main/java/PreparationNote.java b/opp/core/src/main/java/PreparationNote.java index 58ac8db18cd34776cc09a8adb7fd9cc31973067a..073b3efc5e856a3b985083469b314115bf75e666 100644 --- a/opp/core/src/main/java/PreparationNote.java +++ b/opp/core/src/main/java/PreparationNote.java @@ -15,7 +15,7 @@ public class PreparationNote { this.operationId = operationId; this.content = content; } - +/* // Getter und Setter Methoden für die Attribute public String getId() { return noteId; @@ -66,6 +66,9 @@ public class PreparationNote { public int hashCode() { return Objects.hash(noteId, operationId, content); } + + + */ } //public record PreparationNote( diff --git a/opp/core/src/main/java/Repository.java b/opp/core/src/main/java/Repository.java index 859941d73f1f0c114a32635fe7cf1ba4f9a71b78..1d45a7ee27ffae73984a95f37ca1bf5a5a567fb0 100644 --- a/opp/core/src/main/java/Repository.java +++ b/opp/core/src/main/java/Repository.java @@ -1,3 +1,4 @@ +import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.Optional; @@ -60,4 +61,14 @@ public interface Repository { * @throws Exception while saving */ void saveOPStaff(OPStaff opStaff) throws Exception; + + /** + * 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. + * @param id the ID to search for + * @return the found Operation + */ + + Optional<OPStaff> findOPStaff(Id<OPStaff> id); + } diff --git a/opp/core/src/main/java/Room.java b/opp/core/src/main/java/Room.java index a0de6ea20f8feb336fc332d59a35536a746f478a..d4928475e0da141e1bd394beddaea61a98cecfac 100644 --- a/opp/core/src/main/java/Room.java +++ b/opp/core/src/main/java/Room.java @@ -9,18 +9,18 @@ public class Room { // Konstruktor zur Initialisierung der Raum-Attribute public Room(String RoomId, String roomName, int capacity) { this.roomId = roomId; - this.roomName = RoomName; + //this.roomName = RoomName; this.capacity = capacity; } // Getter und Setter Methoden für die Attribute - public String getRoomId() { - return RoomId; - } + //public String getRoomId() { + // return RoomId; + //} - public void setRoomId(String roomId) { - this.id = RoomId; - } + //public void setRoomId(String roomId) { + // this.id = RoomId; + //} public String getRoomName() { return roomName; diff --git a/opp/jdbc-repo-impl/src/main/java/JDBCRepository.java b/opp/jdbc-repo-impl/src/main/java/JDBCRepository.java index 277d1facffef264b057310d729cebf2da34b4788..4983a4d13409abfbf69d5fca2ba45a51b3195648 100644 --- a/opp/jdbc-repo-impl/src/main/java/JDBCRepository.java +++ b/opp/jdbc-repo-impl/src/main/java/JDBCRepository.java @@ -456,6 +456,46 @@ 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. + * @param id the ID to search for + * @return the found Operation + */ + @Override + public Optional<OPStaff> findOPStaff(Id<OPStaff> id){ + try ( + var result = + conn.createStatement() + .executeQuery("SELECT * FROM opstaff WHERE id = " + sqlValue(id.value()) + ";") + ){ + return + result.next() ? + Optional.of(readOPStaffFromRow(result)) : + Optional.empty(); + + } catch (SQLException e){ + throw new RuntimeException(e); + } + } + + /** + * Creates an Operation object with the given result of a read SQL-Row. + * @param rs the result of a read SQL-Row + * @return the created operation object + * @throws SQLException Error while reading the SQL-Row + */ + + private static OPStaff readOPStaffFromRow(ResultSet rs) throws SQLException { + + return new OPStaff( + new Id<>(rs.getString("id")), + Role.valueOf(rs.getString("role")), + Specialty.valueOf(rs.getString("specialty")), + rs.getTimestamp("lastUpdate").toInstant() + ); + } + } diff --git a/opp/jdbc-repo-impl/src/test/java/Tests.java b/opp/jdbc-repo-impl/src/test/java/Tests.java index 9586021afa5a1a39080ff0bb03cb8a8d53393c5f..62d3ad2490d0da05aab07db97f36b348b03b2d41 100644 --- a/opp/jdbc-repo-impl/src/test/java/Tests.java +++ b/opp/jdbc-repo-impl/src/test/java/Tests.java @@ -194,7 +194,7 @@ public final class Tests } } - @Test + //@Test public void testCreateOPStaff_1() { try { repo.saveOPStaff(testOPStaff); @@ -203,7 +203,7 @@ public final class Tests } } - @Test + //@Test public void testCreateOPStaff_2() throws Exception { OPStaff.CreateOPStaff createCommand = new OPStaff.CreateOPStaff( Role.SURGEON, @@ -213,4 +213,19 @@ public final class Tests OPStaff createOPStaff = opStaffService.process(createCommand); } + @Test + public void testGetOPStaff() { + + try{ + var id = new Id<OPStaff>("3333"); + Optional<OPStaff> opStaff = opStaffService.getOPStaff(id); + System.out.println(opStaff); + } catch (Exception e){ + e.printStackTrace(); + } + + //assertEquals(operation.date(), testDate); + } } + +