Skip to content

Instantly share code, notes, and snippets.

@igeligel
Created October 19, 2016 20:05
Show Gist options
  • Save igeligel/8c5b3f41a283a05285676248eba933ea to your computer and use it in GitHub Desktop.
Save igeligel/8c5b3f41a283a05285676248eba933ea to your computer and use it in GitHub Desktop.
package de.ostfalia.groupfour.controllers;
import de.ostfalia.groupfour.models.Actor;
import de.ostfalia.groupfour.services.ActorService;
import javax.inject.Inject;
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;
@Path("/actor")
public class ActorResource {
@Inject
ActorService actorService;
@GET
@Path("/{actorId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Actor getActor(@PathParam("actorId") int actorId) {
return actorService.findById(actorId);
}
@POST
@Path("/")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Actor postActor(Actor actor) {
actorService.persist(actor);
return actor;
}
@PUT
@Path("/")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Actor putActor(Actor actor) {
actorService.persist(actor);
return actor;
}
@DELETE
@Path("/{actorId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Actor deleteActor(@PathParam("actorId") int actorId) {
return actorService.delete(actorId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment