Fixed adding observations, added listing of tutor observations.
This commit is contained in:
parent
64c828b87e
commit
e4120b1ca3
@ -10,7 +10,7 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import org.jdbi.v3.core.mapper.RowMapper;
|
||||
import org.jdbi.v3.core.statement.StatementContext;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@ -25,10 +25,6 @@ public class Observation {
|
||||
@JsonProperty
|
||||
private int siteId;
|
||||
|
||||
@NonNull
|
||||
@JsonProperty
|
||||
private int tutorManyId;
|
||||
|
||||
@NonNull
|
||||
@JsonProperty
|
||||
private String observed;
|
||||
@ -43,12 +39,11 @@ public class Observation {
|
||||
|
||||
@NonNull
|
||||
@JsonProperty
|
||||
private LocalDate date;
|
||||
private DateTime date;
|
||||
|
||||
public Observation(int siteId, int tutorManyId, String observed, int monitoring, int control, int conservatism,
|
||||
public Observation(int siteId, String observed, int monitoring, int control, int conservatism,
|
||||
int teamwork, int knowledge, String rawData) {
|
||||
this.siteId = siteId;
|
||||
this.tutorManyId = tutorManyId;
|
||||
this.observed = observed;
|
||||
this.monitoring = monitoring;
|
||||
this.control = control;
|
||||
@ -56,15 +51,15 @@ public class Observation {
|
||||
this.teamwork = teamwork;
|
||||
this.knowledge = knowledge;
|
||||
this.rawData = rawData;
|
||||
this.date = LocalDate.now();
|
||||
this.date = DateTime.now();
|
||||
}
|
||||
|
||||
public static class Mapper implements RowMapper<Observation>{
|
||||
|
||||
public Observation map(ResultSet rs, StatementContext ctx) throws SQLException {
|
||||
return new Observation(rs.getInt("id"), rs.getInt("siteId"), rs.getInt("tutorManyId"), rs.getString("observed"),
|
||||
return new Observation(rs.getInt("id"), rs.getInt("siteId"), rs.getString("observed"),
|
||||
rs.getInt("monitoring"), rs.getInt("control"), rs.getInt("conservatism"), rs.getInt("teamwork"),
|
||||
rs.getInt("knowledge"), rs.getString("rawData"), new LocalDate(rs.getDate("date")));
|
||||
rs.getInt("knowledge"), rs.getString("rawData"), new DateTime(rs.getDate("date")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import org.jdbi.v3.sqlobject.customizer.Bind;
|
||||
import org.jdbi.v3.sqlobject.customizer.BindBean;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.DateTime;
|
||||
import uk.co.neviyn.Observations.api.NewObservation;
|
||||
import uk.co.neviyn.Observations.core.Observation;
|
||||
|
||||
@ -25,21 +25,21 @@ 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)")
|
||||
int addObservation(@BindBean NewObservation observation);
|
||||
int addObservation(@BindBean NewObservation observation, @Bind("date") DateTime date);
|
||||
|
||||
@SqlUpdate("INSERT INTO observation_tutor (tutorId, observationId) VALUES (:tutorId, :observationId)")
|
||||
void addObservationTutor(@Bind("observationId")int observationId, @Bind("tutorId")int tutorId);
|
||||
|
||||
@SqlQuery("SELECT * FROM observations WHERE date BETWEEN :startDate AND :endDate")
|
||||
List<Observation> observationsBetweenDates(@Bind("startDate")LocalDate startDate, @Bind("endDate")LocalDate endDate);
|
||||
List<Observation> observationsBetweenDates(@Bind("startDate")DateTime startDate, @Bind("endDate")DateTime endDate);
|
||||
|
||||
@SqlQuery("SELECT * FROM observations LEFT JOIN observation_tutor ON observation_tutor.observationId = observations.id " +
|
||||
"LEFT JOIN tutor observation_tutor.tutorId = tutor.id WHERE tutor.id = :tutorId")
|
||||
"LEFT JOIN tutor ON observation_tutor.tutorId = tutor.id WHERE tutor.id = :tutorId")
|
||||
List<Observation> observationsByTutor(@Bind("tutorId")int tutorId);
|
||||
|
||||
@SqlQuery("SELECT * FROM observations WHERE date BETWEEN :startDate AND :endDate " +
|
||||
"LEFT JOIN observation_tutor ON observation_tutor.observationId = observations.id " +
|
||||
"LEFT JOIN tutor observation_tutor.tutorId = tutor.id WHERE tutor.id = :tutorId")
|
||||
List<Observation> observationsByTutorBetweenDates(@Bind("tutorId")int tutorId, @Bind("startDate")LocalDate startDate,
|
||||
@Bind("endDate")LocalDate endDate);
|
||||
"LEFT JOIN tutor ON observation_tutor.tutorId = tutor.id WHERE tutor.id = :tutorId")
|
||||
List<Observation> observationsByTutorBetweenDates(@Bind("tutorId")int tutorId, @Bind("startDate")DateTime startDate,
|
||||
@Bind("endDate")DateTime endDate);
|
||||
}
|
||||
|
@ -1,15 +1,20 @@
|
||||
package uk.co.neviyn.Observations.resources;
|
||||
|
||||
import java.util.List;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.joda.time.DateTime;
|
||||
import uk.co.neviyn.Observations.api.NewObservation;
|
||||
import uk.co.neviyn.Observations.core.Observation;
|
||||
import uk.co.neviyn.Observations.dao.ObservationDao;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@ -23,10 +28,16 @@ public class ObservationResource {
|
||||
|
||||
@POST
|
||||
public int add(@NotNull @Valid NewObservation observation){
|
||||
int observationId = dao.addObservation(observation);
|
||||
int observationId = dao.addObservation(observation, DateTime.now());
|
||||
for(int tutorId: observation.getTutorIds()){
|
||||
dao.addObservationTutor(observationId, tutorId);
|
||||
}
|
||||
return observationId;
|
||||
}
|
||||
|
||||
@Path("/by/{tutorId}")
|
||||
@GET
|
||||
public List<Observation> observationsBy(@PathParam("tutorId") int tutorId){
|
||||
return dao.observationsByTutor(tutorId);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user