package lv.ctco.cukesrest.gadgets;

import com.google.inject.Inject;
import lv.ctco.cukesrest.common.RestUtils;
import lv.ctco.cukesrest.gadgets.dto.GadgetData;
import lv.ctco.cukesrest.gadgets.dto.GadgetDto;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Collection;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

@SuppressWarnings("SameReturnValue")
@Path(GadgetResource.API)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class GadgetResource {

    protected static final String API = "/gadgets";

    @Inject
    DummyGadgetService service;
    @Inject
    RestUtils rest;

    @GET
    public Response searchGadgets() {
        Collection<GadgetDto> gadgets = service.searchGadgets();
        return rest.ok(new GadgetData(gadgets));
    }

    @GET
    @Path("{id}")
    public Response getGadget(@PathParam("id") Integer id) {
        GadgetDto gadget = service.getGadget(id);
        if (gadget == null) {
            return rest.notFound();
        }
        return rest.ok(gadget);
    }

    @POST
    public Response addGadget(GadgetDto gadget) {
        Integer id = service.addGadget(gadget);
        if (id == null) {
            return rest.badRequest("Could not add new Gadget");
        }
        return rest.created(id, API);
    }

    @PUT
    @Path("{id}")
    public Response updateGadget(@PathParam("id") Integer id, GadgetDto gadget) {
        boolean result = service.updateGadget(id, gadget);
        if (!result) {
            return rest.badRequest("Could not update Gadget with ID: " + id);
        }
        return rest.ok();
    }

    @DELETE
    @Path("{id}")
    public Response removeGadget(@PathParam("id") Integer id) {
        boolean result = service.removeGadget(id);
        if (!result) {
            return rest.notFound();
        }
        return rest.ok();
    }

    @GET
    @Path("{first}/{second}")
    public Response getGadgetsDelayed(@PathParam("first") Integer first, @PathParam("second") Integer second) {

        GadgetDto gadget = service.getGadget(first);
        if (gadget == null) {
            return rest.notFound();
        }
        return rest.ok(gadget);
    }
}

@@ -226,200 +226,9 @@
 .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
+*
 ;%0Aim
@@ -326,80 +326,8 @@
 ion;
-%0Aimport java.util.Random;%0Aimport java.util.concurrent.ThreadLocalRandom;
 %0A%0A@S
@@ -1859,327 +1859,7 @@
    %7D
-%0A%0A    @GET%0A    @Path(%22%7Bfirst%7D/%7Bsecond%7D%22)%0A    public Response getGadgetsDelayed(@PathParam(%22first%22) Integer first, @PathParam(%22second%22) Integer second) %7B%0A%0A        GadgetDto gadget = service.getGadget(first);%0A        if (gadget == null) %7B%0A            return rest.notFound();%0A        %7D%0A        return rest.ok(gadget);%0A    %7D
 %0A%7D%0A

Test method removal