Added average stats per site endpoint.

This commit is contained in:
neviyn 2018-09-19 14:51:58 +01:00
parent b4c6773713
commit 294bf679a6

View File

@ -1,19 +1,5 @@
package uk.co.neviyn.Observations.resources;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
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 io.dropwizard.hibernate.UnitOfWork;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -30,6 +16,14 @@ import uk.co.neviyn.Observations.dao.ObservationDao;
import uk.co.neviyn.Observations.dao.SiteDao;
import uk.co.neviyn.Observations.dao.TutorDao;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@RequiredArgsConstructor
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ -77,6 +71,17 @@ public class ObservationResource {
@Path("/average/all/chartjs")
@GET
public AverageStatsChartJs averageStatsChartJs(){
return new AverageStatsChartJs(dao.averageStatsForAll());
return new AverageStatsChartJs(averageObservationScores());
}
@Path("/average/{id}")
public List<AverageStats> averageObservationScoresForSite(@PathParam("id") long siteId) {
Site site = siteDao.get(siteId);
return dao.averageStatsForSite(site);
}
@Path("/average/{id}/chartjs")
public AverageStatsChartJs averageObservationScoresForSiteChartJs(@PathParam("id") long siteId) {
return new AverageStatsChartJs(averageObservationScoresForSite(siteId));
}
}