diff --git a/backend/pom.xml b/backend/pom.xml index 3ed3ed9..ae6bb4f 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -170,6 +170,15 @@ uk.co.neviyn.Observations.ObservationsApplication + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + diff --git a/backend/src/main/java/uk/co/neviyn/Observations/api/SelectOption.java b/backend/src/main/java/uk/co/neviyn/Observations/api/SelectOption.java new file mode 100644 index 0000000..6bd68e2 --- /dev/null +++ b/backend/src/main/java/uk/co/neviyn/Observations/api/SelectOption.java @@ -0,0 +1,17 @@ +package uk.co.neviyn.Observations.api; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NonNull; + +@Data +public class SelectOption { + @NonNull + @JsonProperty + private String text; + + @NonNull + @JsonProperty + private T value; + +} diff --git a/backend/src/main/java/uk/co/neviyn/Observations/resources/TutorResource.java b/backend/src/main/java/uk/co/neviyn/Observations/resources/TutorResource.java index 32c5774..9837df9 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/resources/TutorResource.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/resources/TutorResource.java @@ -1,14 +1,17 @@ package uk.co.neviyn.Observations.resources; import java.util.List; +import java.util.stream.Collectors; import javax.ws.rs.GET; import javax.ws.rs.Path; +import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import uk.co.neviyn.Observations.api.SelectOption; import uk.co.neviyn.Observations.core.Tutor; import uk.co.neviyn.Observations.dao.TutorDao; @@ -28,4 +31,14 @@ public class TutorResource { return tutors; throw new WebApplicationException("No tutors found!", Response.Status.NOT_FOUND); } + + @Path("/site/{id}") + @GET + public List> tutorsForSite(@PathParam("id")int siteId){ + List tutors = dao.tutorsForSite(siteId); + if(tutors != null && !tutors.isEmpty()){ + return tutors.stream().map(x -> new SelectOption<>(x.getName(), x.getId())).collect(Collectors.toList()); + } + throw new WebApplicationException("No tutors found!", Response.Status.NOT_FOUND); + } }