All checks were successful
Build, test and publish / verify (push) Successful in 7m31s
85 lines
3.0 KiB
Java
85 lines
3.0 KiB
Java
package nl.agilecc.agiledancers.rest;
|
|
|
|
import jakarta.inject.Inject;
|
|
import jakarta.validation.Valid;
|
|
import jakarta.validation.constraints.NotNull;
|
|
import jakarta.ws.rs.Consumes;
|
|
import jakarta.ws.rs.DELETE;
|
|
import jakarta.ws.rs.GET;
|
|
import jakarta.ws.rs.POST;
|
|
import jakarta.ws.rs.PUT;
|
|
import jakarta.ws.rs.Path;
|
|
import jakarta.ws.rs.PathParam;
|
|
import jakarta.ws.rs.Produces;
|
|
import jakarta.ws.rs.core.Context;
|
|
import jakarta.ws.rs.core.MediaType;
|
|
import jakarta.ws.rs.core.Response;
|
|
import jakarta.ws.rs.core.UriInfo;
|
|
import java.util.List;
|
|
import nl.agilecc.agiledancers.model.DanceSchool;
|
|
import nl.agilecc.agiledancers.rest.apimodel.SchoolRequest;
|
|
import nl.agilecc.agiledancers.rest.apimodel.SchoolView;
|
|
import nl.agilecc.agiledancers.rest.mapping.DomainViewMapper;
|
|
import nl.agilecc.agiledancers.service.SchoolManagementService;
|
|
|
|
@SchoolTransactionBoundary
|
|
@Path("/api/dance-schools")
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
public class DanceSchoolResource {
|
|
private @Inject DomainViewMapper views;
|
|
|
|
private @Inject SchoolManagementService service;
|
|
|
|
private @Inject nl.agilecc.agiledancers.service.ShowSchedules schedules;
|
|
|
|
@GET
|
|
@Path("/{id}/data")
|
|
public nl.agilecc.agiledancers.rest.apimodel.SchoolDataView data(final @PathParam("id") long id) {
|
|
final DanceSchool school = service.school(id);
|
|
return new nl.agilecc.agiledancers.rest.apimodel.SchoolDataView(
|
|
views.school(school),
|
|
school.getDancers().stream().map(views::dancer).toList(),
|
|
school.getDanceGroups().stream().map(views::group).toList(),
|
|
school.getShows().stream()
|
|
.map((final nl.agilecc.agiledancers.model.Show show) ->
|
|
views.show(show, schedules.violations(id, show.getId())))
|
|
.toList(),
|
|
school.getCoaches().stream().map(views::coach).toList());
|
|
}
|
|
|
|
@GET
|
|
public List<SchoolView> list() {
|
|
return service.schools().stream().map(views::school).toList();
|
|
}
|
|
|
|
@GET
|
|
@Path("/{id}")
|
|
public SchoolView get(final @PathParam("id") long id) {
|
|
return views.school(service.school(id));
|
|
}
|
|
|
|
@POST
|
|
public Response create(final @NotNull @Valid SchoolRequest request, final @Context UriInfo uriInfo) {
|
|
final DanceSchool entity = service.createSchool(request.name());
|
|
return Response.created(uriInfo.getAbsolutePathBuilder()
|
|
.path(entity.getId().toString())
|
|
.build())
|
|
.entity(views.school(entity))
|
|
.build();
|
|
}
|
|
|
|
@PUT
|
|
@Path("/{id}")
|
|
public SchoolView update(final @PathParam("id") long id, final @NotNull @Valid SchoolRequest request) {
|
|
return views.school(service.updateSchool(id, request.name()));
|
|
}
|
|
|
|
@DELETE
|
|
@Path("/{id}")
|
|
public Response delete(final @PathParam("id") long id) {
|
|
service.deleteSchool(id);
|
|
return Response.noContent().build();
|
|
}
|
|
}
|