Skip to content
Snippets Groups Projects
Commit 578d7603 authored by Andre Hartig's avatar Andre Hartig
Browse files

restructure of code.

parent acd6d903
No related branches found
No related tags found
No related merge requests found
Showing
with 402 additions and 519 deletions
import com.fasterxml.jackson.annotation.JsonProperty;
public record Address(
@JsonProperty String street,
@JsonProperty String house,
@JsonProperty String postalCode,
@JsonProperty String city
String street,
String house,
String postalCode,
String city
) {
}
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import java.io.IOException;
@JsonSerialize(using = Id.Serializer.class)
public record Id<T>(String value)
{
@Override public String toString(){ return value; }
public static class Serializer<T> extends StdSerializer<Id<T>>
{
public Serializer(){
this(null);
}
public Serializer(Class<Id<T>> cl){
super(cl);
}
@Override
public void serialize(
Id<T> id,
JsonGenerator json,
SerializerProvider provider
)
throws IOException {
json.writeString(id.value());
}
@Override
public String toString(){
return value;
}
}
......@@ -13,13 +13,13 @@ public class OPStaffServiceImpl implements OPStaffService{
@Override
public OPStaff process(OPStaff.Command cmd) throws Exception {
return switch (cmd){
case OPStaff.CreateOPStaff cr -> createOPStaffimpl(cr);
case OPStaff.UpdateOPStaff up -> updateOPStaffimpl(up);
case OPStaff.DeleteOPStaff del -> deleteOPStaffimpl(del);
case OPStaff.CreateOPStaff cr -> create(cr);
case OPStaff.UpdateOPStaff up -> update(up);
case OPStaff.DeleteOPStaff del -> delete(del);
};
}
public OPStaff createOPStaffimpl(OPStaff.CreateOPStaff cr) throws Exception {
public OPStaff create(OPStaff.CreateOPStaff cr) throws Exception {
OPStaff opStaff =
new OPStaff(
repo.opStaffId(),
......@@ -27,12 +27,12 @@ public class OPStaffServiceImpl implements OPStaffService{
cr.specialty(),
Instant.now());
repo.saveOPStaff(opStaff);
repo.save(opStaff);
return opStaff;
}
public OPStaff updateOPStaffimpl(OPStaff.UpdateOPStaff up) throws Exception{
public OPStaff update(OPStaff.UpdateOPStaff up) throws Exception{
OPStaff currentOPStaff = repo.findOPStaff(up.id()).get();
OPStaff opStaff =
......@@ -42,18 +42,14 @@ public class OPStaffServiceImpl implements OPStaffService{
up.specialty().orElse((currentOPStaff.specialty())),
Instant.now()
);
repo.saveOPStaff(opStaff);
repo.save(opStaff);
return opStaff;
}
public OPStaff deleteOPStaffimpl(OPStaff.DeleteOPStaff del) throws Exception{
public OPStaff delete(OPStaff.DeleteOPStaff del) throws Exception{
OPStaff opStaff = repo.findOPStaff(del.id()).get();
repo.deleteOPStaff(del.id());
return opStaff;
return repo.deleteOPStaff(del.id());
}
......
public enum ObjectModification {
CREATE,
UPDATE,
DELETE
}
......@@ -15,7 +15,7 @@ public record Operation(
LocalDate date,
LocalTime startTime,
LocalTime endTime,
Id<Patient> patientId,
Id<OperationTeam> operationTeamId,
Instant lastUpdate
) {
......@@ -48,7 +48,7 @@ public record Operation(
LocalDate date,
LocalTime startTime,
LocalTime endTime,
Id<Patient> patientId,
Id<OperationTeam> operationTeamId
) implements Command {}
......@@ -57,8 +57,8 @@ public record Operation(
Optional<LocalDate> date,
Optional<LocalTime> startTime,
Optional<LocalTime> endTime,
Id<OperationTeam> operationTeamId
Optional<Id<Patient>> patientId,
Optional<Id<OperationTeam>> operationTeamId
) implements Command {}
public static record Delete(
......
......@@ -40,6 +40,7 @@ public class OperationServiceImpl implements OperationService {
cr.date(),
cr.startTime(),
cr.endTime(),
cr.patientId(),
cr.operationTeamId(),
Instant.now());
......@@ -58,7 +59,8 @@ public class OperationServiceImpl implements OperationService {
up.date().orElse(currentOperation.date()),
up.startTime().orElse(currentOperation.startTime()),
up.endTime().orElse(currentOperation.endTime()),
up.operationTeamId(), //TODO
up.patientId().orElse(currentOperation.patientId()),
up.operationTeamId().orElse(currentOperation.operationTeamId()),
Instant.now());
repo.save(operation);
......@@ -68,10 +70,6 @@ public class OperationServiceImpl implements OperationService {
public Operation delete(Operation.Delete del) throws Exception {
Operation operation = repo.findOperation(del.id()).get();
repo.deleteOperation(del.id());
return operation;
return repo.deleteOperation(del.id());
}
}
import java.time.Instant;
import java.util.List;
public record OperationTeam(
Id<OperationTeam> operationTeamId,
Id<OperationTeam> id,
String teamName,
Instant lastUpdate
) {
......
......@@ -15,24 +15,22 @@ public class OperationTeamImpl implements OperationTeamService{
@Override
public OperationTeam process(OperationTeam.Command cmd) throws Exception {
return switch(cmd){
case OperationTeam.CreateTeam cr -> createOperationTeamimpl(cr);
case OperationTeam.DeleteTeam del -> deleteOperationTeamimpl(del);
case OperationTeam.CreateTeam cr -> create(cr);
case OperationTeam.DeleteTeam del -> delete(del);
};
}
@Override
public Optional<OperationTeam> getOperationTeam(Id<OperationTeam> operationTeamId) throws SQLException {
return repo.getOperationTeamImp(operationTeamId); //repo.findOperationTeam(operationTeamId);
return repo.findOperationTeam(operationTeamId);
}
private OperationTeam deleteOperationTeamimpl(OperationTeam.DeleteTeam del) throws SQLException {
private OperationTeam delete(OperationTeam.DeleteTeam del) throws SQLException {
OperationTeam operationTeam = repo.deleteOperationTeam(del.operationTeamId());
return operationTeam;
return repo.deleteOperationTeam(del.operationTeamId());
}
private OperationTeam createOperationTeamimpl(OperationTeam.CreateTeam cr) {
private OperationTeam create(OperationTeam.CreateTeam cr) {
OperationTeam operationTeam =
new OperationTeam(
repo.operationTeamId(),
......@@ -45,7 +43,7 @@ public class OperationTeamImpl implements OperationTeamService{
@Override
public List<OperationTeam> getOperationTeams() throws SQLException {
return repo.getOperationTeamsImp();
return repo.findOperationTeams();
}
......
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.LocalDate;
public record Patient (
Id<Patient> id,
Gender gender,
String givenName,
String familyName,
LocalDate birthDate,
Address address,
String healthInsurance
Id<Patient> id
) {
}
......@@ -45,7 +45,7 @@ public interface Repository {
* Deletes the Operation with the matching id.
* @param id the id of the Operation to delete
*/
void deleteOperation(Id<Operation> id) throws SQLException;
Operation deleteOperation(Id<Operation> id) throws SQLException;
/**
* Returns a new generated ID in the opstaff-SQLTable
......@@ -56,10 +56,10 @@ public interface Repository {
/**
* Saves the OPStaff into the database.
* @param
* @param opStaff the OPStaff to save into the database
* @throws Exception while saving
*/
void saveOPStaff(OPStaff opStaff) throws Exception;
void save(OPStaff opStaff) throws Exception;
/**
* Reads an OPStaff from the OPStaff-SQLTable with the given ID.
......@@ -73,26 +73,28 @@ public interface Repository {
List<OPStaff> findOPStaffs();
void deleteOPStaff(Id<OPStaff> id) throws SQLException;
OPStaff deleteOPStaff(Id<OPStaff> id) throws SQLException;
Id<OperationTeam> operationTeamId();
void saveOperationTeam(OperationTeam operationTeam) throws Exception;
void save(OperationTeam operationTeam) throws Exception;
Optional<OperationTeam> findOperationTeam(Id<OperationTeam> id);
List<OperationTeam> findOperationTeams() throws SQLException;
OperationTeam deleteOperationTeam(Id<OperationTeam> id) throws SQLException;
Optional<OperationTeam> getOperationTeamImp(Id<OperationTeam> id) throws SQLException;
List<OperationTeam> getOperationTeamsImp() throws SQLException;
Id<TeamMember> teamMemberId();
void saveTeamMember(TeamMember teamMember) throws Exception;
void saveTeamMember(TeamMember TeamMember) throws Exception;
List<OPStaff> getOperationTeamOPStaffImpl(Id<OperationTeam> operationTeamId);
}
import java.time.Instant;
public record TeamMember (
public record TeamMember(
Id<TeamMember> teamMemberId,
......
This diff is collapsed.
......@@ -17,6 +17,8 @@ public final class Tests
private static Repository repo = null;
private static Patient testPatient = null;
private static Operation testOperation = null;
private static OperationService opService;
......@@ -42,12 +44,23 @@ public final class Tests
repo = JDBCRepository.instance();
testPatient = new Patient(
new Id<>("9999")
);
testOperationTeam = new OperationTeam(
new Id<>("31"),
("AmCoolsten"),
Instant.now()
);
testOperation = new Operation(
new Id<>("1111"),
LocalDate.of(2024, 05, 24),
LocalTime.of(13, 35, 00),
LocalTime.of(14, 00, 00),
new Id<>("31313131"),
testPatient.id(),
testOperationTeam.id(),
Instant.now());
opService = new OperationServiceImpl(repo);
......@@ -60,19 +73,12 @@ public final class Tests
opStaffService = new OPStaffServiceImpl(repo);
testOperationTeam = new OperationTeam(
new Id<>("31"),
("AmCoolsten"),
Instant.now()
);
operationTeamService = new OperationTeamImpl(repo) {
};
testTeamMember = new TeamMember(
new Id<>("TeamMember2"),
testOperationTeam.operationTeamId(),
testOperationTeam.id(),
testOPStaff.id(),
Instant.now()
);
......@@ -81,10 +87,11 @@ public final class Tests
}
//@Test
@Test
public void testRepoOperationSave(){
try {
repo.save(testOperationTeam);
repo.save(testOperation);
} catch (Exception e){
e.printStackTrace();
......@@ -95,10 +102,11 @@ public final class Tests
);
}
//@Test
@Test
public void testRepoOperationUpdate() {
try {
repo.save(testOperationTeam);
repo.save(testOperation);
} catch (Exception e){
e.printStackTrace();
......@@ -109,6 +117,7 @@ public final class Tests
LocalDate.of(1999, 01, 01),
testOperation.startTime(),
testOperation.endTime(),
testOperation.patientId(),
testOperation.operationTeamId(),
Instant.now()
);
......@@ -127,13 +136,15 @@ public final class Tests
//@Test
public void testRepoOperationDelete() {
try {
repo.save(testOperationTeam);
repo.save(testOperation);
} catch (Exception e){
e.printStackTrace();
}
try {
repo.deleteOperation(testOperation.id());
//repo.deleteOperationTeam(testOperationTeam.id());
repo.deleteOperation(testOperation.id());
} catch (SQLException e) {
throw new RuntimeException(e);
}
......@@ -146,6 +157,7 @@ public final class Tests
LocalDate.of(2025, 05, 11),
LocalTime.of(10, 30, 00),
LocalTime.of(11, 00, 00),
new Id<Patient>("8888"),
new Id<OperationTeam>("31313131")
);
......@@ -166,7 +178,8 @@ public final class Tests
Optional.of(LocalDate.of(1999, 01, 01)),
Optional.empty(),
Optional.empty(),
new Id<OperationTeam>("31")
Optional.empty(),
Optional.empty()
);
opService.getOperation(testOperation.id());
......@@ -228,7 +241,7 @@ public final class Tests
//@Test
public void testCreateOPStaff_1() {
try {
repo.saveOPStaff(testOPStaff);
repo.save(testOPStaff);
} catch (Exception e){
e.printStackTrace();
}
......@@ -303,7 +316,7 @@ public final class Tests
public void testCreateOperationTeam() throws Exception{
try {
repo.saveOperationTeam(testOperationTeam);
repo.save(testOperationTeam);
} catch (Exception e){
e.printStackTrace();
}
......
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