Site filtered tutor list now returns a format suitable for a https://bootstrap-vue.js.org/docs/components/form-checkbox

This commit is contained in:
neviyn 2018-09-16 17:22:13 +01:00
parent a83de7d688
commit 2e1a0ace06
3 changed files with 39 additions and 0 deletions

View File

@ -170,6 +170,15 @@
<mainClass>uk.co.neviyn.Observations.ObservationsApplication</mainClass> <mainClass>uk.co.neviyn.Observations.ObservationsApplication</mainClass>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@ -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<T> {
@NonNull
@JsonProperty
private String text;
@NonNull
@JsonProperty
private T value;
}

View File

@ -1,14 +1,17 @@
package uk.co.neviyn.Observations.resources; package uk.co.neviyn.Observations.resources;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException; import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import uk.co.neviyn.Observations.api.SelectOption;
import uk.co.neviyn.Observations.core.Tutor; import uk.co.neviyn.Observations.core.Tutor;
import uk.co.neviyn.Observations.dao.TutorDao; import uk.co.neviyn.Observations.dao.TutorDao;
@ -28,4 +31,14 @@ public class TutorResource {
return tutors; return tutors;
throw new WebApplicationException("No tutors found!", Response.Status.NOT_FOUND); throw new WebApplicationException("No tutors found!", Response.Status.NOT_FOUND);
} }
@Path("/site/{id}")
@GET
public List<SelectOption<Integer>> tutorsForSite(@PathParam("id")int siteId){
List<Tutor> 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);
}
} }