package br.gov.mj.sislegis.app.rest;
import br.gov.mj.sislegis.app.model.TipoEncaminhamento;
import br.gov.mj.sislegis.app.service.TipoEncaminhamentoService;
import javax.inject.Inject;
import javax.persistence.OptimisticLockException;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import java.util.List;
/**
*
*/
@Path("/tiposencaminhamentos")
public class TipoEncaminhamentoEndpoint {
@Inject
private TipoEncaminhamentoService service;
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response create(TipoEncaminhamento entity) {
service.save(entity);
return Response.created(
UriBuilder.fromResource(TipoEncaminhamentoEndpoint.class)
.path(String.valueOf(entity.getId())).build()).build();
}
@DELETE
@Path("/{id:[0-9][0-9]*}")
public Response deleteById(@PathParam("id") Long id) {
service.deleteById(id);
return Response.noContent().build();
}
@GET
@Path("/{id:[0-9][0-9]*}")
@Produces(MediaType.APPLICATION_JSON)
public Response findById(@PathParam("id") Long id) {
return Response.ok(service.findById(id)).build();
}
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<TipoEncaminhamento> listAll(
@QueryParam("start") Integer startPosition,
@QueryParam("max") Integer maxResult) {
return service.listAll();
}
@PUT
@Path("/{id:[0-9][0-9]*}")
@Consumes(MediaType.APPLICATION_JSON)
public Response update(TipoEncaminhamento entity) {
try {
entity = service.save(entity);
} catch (OptimisticLockException e) {
return Response.status(Response.Status.CONFLICT)
.entity(e.getEntity()).build();
}
return Response.noContent().build();
}
}