diff --git a/backend/src/main/java/uk/co/neviyn/Observations/api/NewObservation.java b/backend/src/main/java/uk/co/neviyn/Observations/api/NewObservation.java index 2adc9ae..c05f63e 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/api/NewObservation.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/api/NewObservation.java @@ -20,7 +20,7 @@ public class NewObservation { @NonNull @JsonProperty - private String observed; + private String observed, type; @NonNull @JsonProperty diff --git a/backend/src/main/java/uk/co/neviyn/Observations/core/Observation.java b/backend/src/main/java/uk/co/neviyn/Observations/core/Observation.java index 7de6dc5..e6f204b 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/core/Observation.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/core/Observation.java @@ -14,7 +14,6 @@ import org.joda.time.DateTime; @Data @NoArgsConstructor -@AllArgsConstructor(access = AccessLevel.PROTECTED) public class Observation { @NonNull @@ -29,6 +28,10 @@ public class Observation { @JsonProperty private String observed; + @NonNull + @JsonProperty + private TrainingType type; + @NonNull @JsonProperty private int monitoring, control, conservatism, teamwork, knowledge; @@ -53,10 +56,25 @@ public class Observation { this.rawData = rawData; } + private Observation(int id, int siteId, String observed, String type, int monitoring, int control, int conservatism, + int teamwork, int knowledge, String rawData, DateTime date) { + this.id = id; + this.siteId = siteId; + this.observed = observed; + this.type = TrainingType.valueOf(type.toUpperCase()); + this.monitoring = monitoring; + this.control = control; + this.conservatism = conservatism; + this.teamwork = teamwork; + this.knowledge = knowledge; + this.rawData = rawData; + this.date = date; + } + public static class Mapper implements RowMapper{ public Observation map(ResultSet rs, StatementContext ctx) throws SQLException { - return new Observation(rs.getInt("id"), rs.getInt("siteId"), rs.getString("observed"), + return new Observation(rs.getInt("id"), rs.getInt("siteId"), rs.getString("observed"), rs.getString("type"), rs.getInt("monitoring"), rs.getInt("control"), rs.getInt("conservatism"), rs.getInt("teamwork"), rs.getInt("knowledge"), rs.getString("rawData"), new DateTime(rs.getDate("date"))); } diff --git a/backend/src/main/java/uk/co/neviyn/Observations/core/TrainingType.java b/backend/src/main/java/uk/co/neviyn/Observations/core/TrainingType.java new file mode 100644 index 0000000..1672015 --- /dev/null +++ b/backend/src/main/java/uk/co/neviyn/Observations/core/TrainingType.java @@ -0,0 +1,5 @@ +package uk.co.neviyn.Observations.core; + +public enum TrainingType { + INITIAL, CONTINUING +} diff --git a/backend/src/main/java/uk/co/neviyn/Observations/dao/ObservationDao.java b/backend/src/main/java/uk/co/neviyn/Observations/dao/ObservationDao.java index 23d68c6..9901aab 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/dao/ObservationDao.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/dao/ObservationDao.java @@ -16,16 +16,16 @@ import uk.co.neviyn.Observations.core.Observation; public interface ObservationDao { @SqlUpdate("CREATE TABLE IF NOT EXISTS observations (id INTEGER PRIMARY KEY, siteId INTEGER, " + - "observed TEXT, monitoring INTEGER, control INTEGER, conservatism INTEGER, teamwork INTEGER, knowledge INTEGER, " + - "rawData TEXT, date DATE)") + "observed TEXT, type TEXT, monitoring INTEGER, control INTEGER, conservatism INTEGER, teamwork INTEGER, " + + "knowledge INTEGER, rawData TEXT, date DATE)") void createObservationTable(); @SqlUpdate("CREATE TABLE IF NOT EXISTS observation_tutor (tutorId INT NOT NULL, observationId INT NOT NULL, " + "FOREIGN KEY (tutorID) REFERENCES tutor(id), FOREIGN KEY (observationId) REFERENCES observations(id))") void createObservationTutorTable(); - @SqlUpdate("INSERT INTO observations (siteId, observed, monitoring, control, conservatism, teamwork, knowledge, " + - "rawData, date) VALUES (:siteId, :observed, :monitoring, :control, :conservatism, :teamwork, :knowledge, " + + @SqlUpdate("INSERT INTO observations (siteId, observed, type, monitoring, control, conservatism, teamwork, knowledge, " + + "rawData, date) VALUES (:siteId, :observed, :type, :monitoring, :control, :conservatism, :teamwork, :knowledge, " + ":rawData, :date)") @GetGeneratedKeys int addObservation(@BindBean NewObservation observation, @Bind("date") DateTime date);