72 lines
1.9 KiB
Java
72 lines
1.9 KiB
Java
package at.technikumwien.movies;
|
|
|
|
import javax.annotation.security.RolesAllowed;
|
|
import javax.inject.Inject;
|
|
import javax.ws.rs.*;
|
|
import javax.ws.rs.core.Context;
|
|
import javax.ws.rs.core.MediaType;
|
|
import javax.ws.rs.core.Response;
|
|
import javax.ws.rs.core.UriInfo;
|
|
import java.net.URI;
|
|
import java.util.List;
|
|
|
|
@Path("/studio")
|
|
@RolesAllowed("MoviesUserRole")
|
|
public class StudioResource {
|
|
@Inject
|
|
private StudiosService studiosService;
|
|
|
|
@Context
|
|
private UriInfo uriInfo;
|
|
|
|
@GET
|
|
@Produces({
|
|
MediaType.APPLICATION_JSON,
|
|
MediaType.APPLICATION_XML
|
|
})
|
|
public List<Studio> retrieveAll() {
|
|
return studiosService.findAllStudios();
|
|
}
|
|
|
|
@GET
|
|
@Produces({
|
|
MediaType.APPLICATION_JSON,
|
|
MediaType.APPLICATION_XML
|
|
})
|
|
@Path("/{id}")
|
|
public Studio retrieve(@PathParam("id") long id) {
|
|
return studiosService.findStudioById(id);
|
|
}
|
|
|
|
@DELETE
|
|
@Path("/{id}")
|
|
public void delete(@PathParam("id") long id) {
|
|
studiosService.removeStudioById(id);
|
|
}
|
|
|
|
@POST
|
|
@Consumes({
|
|
MediaType.APPLICATION_JSON,
|
|
MediaType.APPLICATION_XML
|
|
})
|
|
public Response create(Studio studio) {
|
|
studio.setId(null); // Make sure that a new studio is added, not overwriting existing one
|
|
List<Studio> newStudios = studiosService.saveStudio(List.of(studio));
|
|
|
|
URI location = uriInfo.getAbsolutePathBuilder().path(newStudios.get(0).getId().toString()).build();
|
|
|
|
return Response.created(location).build();
|
|
}
|
|
|
|
@PUT
|
|
@Consumes({
|
|
MediaType.APPLICATION_JSON,
|
|
MediaType.APPLICATION_XML
|
|
})
|
|
@Path("/{id}")
|
|
public void update(@PathParam("id") long id, Studio studio) {
|
|
studio.setId(id); // Make sure that a new studio is added, not overwriting existing one
|
|
studiosService.saveStudio(List.of(studio));
|
|
}
|
|
}
|