From 9ceac25393d6b7f8e4bcfafe10a018f6319ba4fc Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Sun, 16 Sep 2018 16:20:52 +0100 Subject: [PATCH] Moved Observation time creation to correct class. --- .../main/java/uk/co/neviyn/Observations/core/Observation.java | 1 - .../java/uk/co/neviyn/Observations/dao/ObservationDao.java | 2 ++ .../co/neviyn/Observations/resources/ObservationResource.java | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) 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 862e377..7de6dc5 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 @@ -51,7 +51,6 @@ public class Observation { this.teamwork = teamwork; this.knowledge = knowledge; this.rawData = rawData; - this.date = DateTime.now(); } public static class Mapper implements RowMapper{ 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 1ea8c3e..f3f7ce6 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 @@ -4,6 +4,7 @@ import java.util.List; import org.jdbi.v3.sqlobject.config.RegisterRowMapper; import org.jdbi.v3.sqlobject.customizer.Bind; import org.jdbi.v3.sqlobject.customizer.BindBean; +import org.jdbi.v3.sqlobject.statement.GetGeneratedKeys; import org.jdbi.v3.sqlobject.statement.SqlQuery; import org.jdbi.v3.sqlobject.statement.SqlUpdate; import org.joda.time.DateTime; @@ -25,6 +26,7 @@ public interface ObservationDao { @SqlUpdate("INSERT INTO observations (siteId, observed, monitoring, control, conservatism, teamwork, knowledge, " + "rawData, date) VALUES (:siteId, :observed, :monitoring, :control, :conservatism, :teamwork, :knowledge, " + ":rawData, :date)") + @GetGeneratedKeys int addObservation(@BindBean NewObservation observation, @Bind("date") DateTime date); @SqlUpdate("INSERT INTO observation_tutor (tutorId, observationId) VALUES (:tutorId, :observationId)") diff --git a/backend/src/main/java/uk/co/neviyn/Observations/resources/ObservationResource.java b/backend/src/main/java/uk/co/neviyn/Observations/resources/ObservationResource.java index f05a331..7f88b5d 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/resources/ObservationResource.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/resources/ObservationResource.java @@ -13,6 +13,7 @@ import javax.ws.rs.core.MediaType; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.joda.time.DateTime; +import org.joda.time.LocalDate; import uk.co.neviyn.Observations.api.NewObservation; import uk.co.neviyn.Observations.core.Observation; import uk.co.neviyn.Observations.dao.ObservationDao; @@ -28,7 +29,8 @@ public class ObservationResource { @POST public int add(@NotNull @Valid NewObservation observation){ - int observationId = dao.addObservation(observation, DateTime.now()); + final int observationId = dao.addObservation(observation, LocalDate.now().toDateTimeAtStartOfDay()); + log.info("Created observation with ID " + observationId + " at " + DateTime.now().toString()); for(int tutorId: observation.getTutorIds()){ dao.addObservationTutor(observationId, tutorId); }