Moved Observation time creation to correct class.
This commit is contained in:
parent
b6d40b7e28
commit
9ceac25393
@ -51,7 +51,6 @@ public class Observation {
|
|||||||
this.teamwork = teamwork;
|
this.teamwork = teamwork;
|
||||||
this.knowledge = knowledge;
|
this.knowledge = knowledge;
|
||||||
this.rawData = rawData;
|
this.rawData = rawData;
|
||||||
this.date = DateTime.now();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Mapper implements RowMapper<Observation>{
|
public static class Mapper implements RowMapper<Observation>{
|
||||||
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||||||
import org.jdbi.v3.sqlobject.config.RegisterRowMapper;
|
import org.jdbi.v3.sqlobject.config.RegisterRowMapper;
|
||||||
import org.jdbi.v3.sqlobject.customizer.Bind;
|
import org.jdbi.v3.sqlobject.customizer.Bind;
|
||||||
import org.jdbi.v3.sqlobject.customizer.BindBean;
|
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.SqlQuery;
|
||||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
@ -25,6 +26,7 @@ public interface ObservationDao {
|
|||||||
@SqlUpdate("INSERT INTO observations (siteId, observed, monitoring, control, conservatism, teamwork, knowledge, " +
|
@SqlUpdate("INSERT INTO observations (siteId, observed, monitoring, control, conservatism, teamwork, knowledge, " +
|
||||||
"rawData, date) VALUES (:siteId, :observed, :monitoring, :control, :conservatism, :teamwork, :knowledge, " +
|
"rawData, date) VALUES (:siteId, :observed, :monitoring, :control, :conservatism, :teamwork, :knowledge, " +
|
||||||
":rawData, :date)")
|
":rawData, :date)")
|
||||||
|
@GetGeneratedKeys
|
||||||
int addObservation(@BindBean NewObservation observation, @Bind("date") DateTime date);
|
int addObservation(@BindBean NewObservation observation, @Bind("date") DateTime date);
|
||||||
|
|
||||||
@SqlUpdate("INSERT INTO observation_tutor (tutorId, observationId) VALUES (:tutorId, :observationId)")
|
@SqlUpdate("INSERT INTO observation_tutor (tutorId, observationId) VALUES (:tutorId, :observationId)")
|
||||||
|
@ -13,6 +13,7 @@ import javax.ws.rs.core.MediaType;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
import uk.co.neviyn.Observations.api.NewObservation;
|
import uk.co.neviyn.Observations.api.NewObservation;
|
||||||
import uk.co.neviyn.Observations.core.Observation;
|
import uk.co.neviyn.Observations.core.Observation;
|
||||||
import uk.co.neviyn.Observations.dao.ObservationDao;
|
import uk.co.neviyn.Observations.dao.ObservationDao;
|
||||||
@ -28,7 +29,8 @@ public class ObservationResource {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
public int add(@NotNull @Valid NewObservation observation){
|
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()){
|
for(int tutorId: observation.getTutorIds()){
|
||||||
dao.addObservationTutor(observationId, tutorId);
|
dao.addObservationTutor(observationId, tutorId);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user