@@ -0,0 +1,2504 @@
+package cz.muni.fi.pv243.rest;%0A%0Aimport java.net.URI;%0Aimport java.util.List;%0A%0Aimport javax.inject.Inject;%0Aimport javax.validation.Valid;%0Aimport javax.ws.rs.Consumes;%0Aimport javax.ws.rs.DELETE;%0Aimport javax.ws.rs.GET;%0Aimport javax.ws.rs.POST;%0Aimport javax.ws.rs.PUT;%0Aimport javax.ws.rs.Path;%0Aimport javax.ws.rs.PathParam;%0Aimport javax.ws.rs.Produces;%0Aimport javax.ws.rs.core.Response;%0Aimport javax.ws.rs.core.Response.Status;%0Aimport javax.ws.rs.core.UriBuilder;%0A%0Aimport cz.muni.fi.pv243.service.AbstractService;%0A%0A/**%0A * %0A */%0Apublic abstract class AbstractEndpoint%3CT%3E %7B%0A%0A    @Inject%0A    private AbstractService%3CT%3E service;%0A%0A    @POST%0A    @Consumes(%22application/json%22)%0A    public Response create(@Valid T entity) %7B%0A        if (entity == null) %7B%0A            return Response.status(Status.BAD_REQUEST).build();%0A        %7D%0A        service.create(entity);%0A        URI url = UriBuilder.fromResource(getClass()).path(service.getEntityId(entity).toString()).build();%0A        return Response.created(url).build();%0A    %7D%0A%0A    @DELETE%0A    @Path(%22/%7Bid:%5B0-9%5D%5B0-9%5D*%7D%22)%0A    public Response deleteById(@PathParam(%22id%22) Long id) %7B%0A        T entity = service.findById(id);%0A        if (entity == null) %7B%0A            return Response.status(Status.NOT_FOUND).build();%0A        %7D%0A        service.delete(entity);%0A        return Response.noContent().build();%0A    %7D%0A%0A    @GET%0A    @Path(%22/%7Bid:%5B0-9%5D%5B0-9%5D*%7D%22)%0A    @Produces(%22application/json%22)%0A    public Response findById(@PathParam(%22id%22) Long id) %7B%0A        T entity = service.findById(id);%0A        if (entity == null) %7B%0A            return Response.status(Status.NOT_FOUND).build();%0A        %7D%0A        return Response.ok(entity).build();%0A    %7D%0A%0A    @GET%0A    @Produces(%22application/json%22)%0A    public List%3CT%3E listAll() %7B%0A        final List%3CT%3E results = service.findAll();%0A        return results;%0A    %7D%0A%0A    @PUT%0A    @Path(%22/%7Bid:%5B0-9%5D%5B0-9%5D*%7D%22)%0A    @Consumes(%22application/json%22)%0A    public Response update(@PathParam(%22id%22) Long id, T entity) %7B%0A        if (entity == null) %7B%0A            return Response.status(Status.BAD_REQUEST).build();%0A        %7D%0A        if (id == null) %7B%0A            return Response.status(Status.BAD_REQUEST).build();%0A        %7D%0A        if (!id.equals(service.getEntityId(entity))) %7B%0A            return Response.status(Status.CONFLICT).entity(entity).build();%0A        %7D%0A        if (service.findById(id) == null) %7B%0A            return Response.status(Status.NOT_FOUND).build();%0A        %7D%0A        service.update(entity);%0A%0A        return Response.noContent().build();%0A    %7D%0A%7D%0A

Add abstract base class for REST endpoints