package io.upit.jaxrs.resources;

import com.google.inject.Inject;
import com.google.inject.persist.Transactional;
import io.upit.UpitServiceException;
import io.upit.dal.models.Paste;
import io.upit.guice.security.PreAuthorize;
import io.upit.jaxrs.exceptions.ResourceException;
import io.upit.services.PasteService;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

@Path("paste")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class PasteResource extends AbstractResource<Paste, Long> {

    private final PasteService pasteService;

    @Inject
    public PasteResource(PasteService pasteService) {
        super(Paste.class, pasteService);
        this.pasteService = pasteService;
    }


    @POST
    @Transactional
    @PreAuthorize
    public Paste create(Paste resource) {
        try {
            return pasteService.create(resource);
        } catch (UpitServiceException e) {
            throw new ResourceException("Failed creating resource " + PasteResource.class.getName(), e);
        }
    }

    @PUT
    @Transactional
    @PreAuthorize
    public Paste update(Paste resource) {
        return super.update(resource);
    }

    @DELETE
    @Transactional
    @PreAuthorize
    public Paste delete(Paste resource) {
        return super.delete(resource);
    }

    @DELETE
    @Path("{id}")
    @Transactional
    @PreAuthorize
    public Paste deleteById(@PathParam("id") Long id) {
        return super.deleteById(id);
    }

    @GET
    @Path("{id}")
    @Transactional
    @PreAuthorize
    public Paste getById(@PathParam("id") Long id) {
        return super.getById(id);
    }


    @GET
    @Path("/hash/{idHash}")
    @PreAuthorize
    public Paste getByIdHash(@PathParam("idHash") String hash) {
        return pasteService.getByIdHash(hash);
    }

}

@@ -71,212 +71,32 @@
 ort 
-com.google.inject.persist.Transactional;%0Aimport io.upit.UpitServiceException;%0Aimport io.upit.dal.models.Paste;%0Aimport io.upit.guice.security.PreAuthorize;%0Aimport io.upit.jaxrs.exceptions.ResourceException
+io.upit.dal.models.Paste
 ;%0Aim
@@ -556,924 +556,8 @@
  %7D%0A%0A
-%0A    @POST%0A    @Transactional%0A    @PreAuthorize%0A    public Paste create(Paste resource) %7B%0A        try %7B%0A            return pasteService.create(resource);%0A        %7D catch (UpitServiceException e) %7B%0A            throw new ResourceException(%22Failed creating resource %22 + PasteResource.class.getName(), e);%0A        %7D%0A    %7D%0A%0A    @PUT%0A    @Transactional%0A    @PreAuthorize%0A    public Paste update(Paste resource) %7B%0A        return super.update(resource);%0A    %7D%0A%0A    @DELETE%0A    @Transactional%0A    @PreAuthorize%0A    public Paste delete(Paste resource) %7B%0A        return super.delete(resource);%0A    %7D%0A%0A    @DELETE%0A    @Path(%22%7Bid%7D%22)%0A    @Transactional%0A    @PreAuthorize%0A    public Paste deleteById(@PathParam(%22id%22) Long id) %7B%0A        return super.deleteById(id);%0A    %7D%0A%0A    @GET%0A    @Path(%22%7Bid%7D%22)%0A    @Transactional%0A    @PreAuthorize%0A    public Paste getById(@PathParam(%22id%22) Long id) %7B%0A        return super.getById(id);%0A    %7D%0A%0A%0A
     
@@ -593,26 +593,8 @@
 %7D%22)%0A
-    @PreAuthorize%0A
     

Remove uneeded PasteResource impls