98 lines
3.2 KiB
Java
98 lines
3.2 KiB
Java
package org.kar.karusic.api;
|
|
|
|
import java.io.InputStream;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
|
|
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
|
import org.glassfish.jersey.media.multipart.FormDataParam;
|
|
import org.kar.archidata.annotation.AsyncType;
|
|
import org.kar.archidata.annotation.FormDataOptional;
|
|
import org.kar.archidata.annotation.TypeScriptProgress;
|
|
import org.kar.archidata.dataAccess.DataAccess;
|
|
import org.kar.archidata.dataAccess.addOn.AddOnDataJson;
|
|
import org.kar.archidata.dataAccess.options.CheckFunction;
|
|
import org.kar.archidata.tools.DataTools;
|
|
import org.kar.karusic.model.Artist;
|
|
import org.kar.karusic.model.Artist.ArtistChecker;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import jakarta.annotation.security.RolesAllowed;
|
|
import jakarta.ws.rs.Consumes;
|
|
import jakarta.ws.rs.DELETE;
|
|
import jakarta.ws.rs.GET;
|
|
import jakarta.ws.rs.PATCH;
|
|
import jakarta.ws.rs.POST;
|
|
import jakarta.ws.rs.Path;
|
|
import jakarta.ws.rs.PathParam;
|
|
import jakarta.ws.rs.Produces;
|
|
import jakarta.ws.rs.core.MediaType;
|
|
|
|
@Path("/artist")
|
|
@Produces({ MediaType.APPLICATION_JSON })
|
|
public class ArtistResource {
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(ArtistResource.class);
|
|
static final ArtistChecker CHECKER = new ArtistChecker();
|
|
|
|
@GET
|
|
@Path("{id}")
|
|
@RolesAllowed("USER")
|
|
public static Artist get(@PathParam("id") final Long id) throws Exception {
|
|
return DataAccess.get(Artist.class, id);
|
|
}
|
|
|
|
@GET
|
|
@RolesAllowed("USER")
|
|
public List<Artist> gets() throws Exception {
|
|
return DataAccess.gets(Artist.class);
|
|
}
|
|
|
|
@POST
|
|
@RolesAllowed("ADMIN")
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
public Artist post(final Artist data) throws Exception {
|
|
return DataAccess.insert(data, new CheckFunction(CHECKER));
|
|
}
|
|
|
|
@PATCH
|
|
@Path("{id}")
|
|
@RolesAllowed("ADMIN")
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
public Artist patch(@PathParam("id") final Long id, @AsyncType(Artist.class) final String jsonRequest) throws Exception {
|
|
DataAccess.updateWithJson(Artist.class, id, jsonRequest, new CheckFunction(CHECKER));
|
|
return DataAccess.get(Artist.class, id);
|
|
}
|
|
|
|
@DELETE
|
|
@Path("{id}")
|
|
@RolesAllowed("ADMIN")
|
|
public void remove(@PathParam("id") final Long id) throws Exception {
|
|
DataAccess.delete(Artist.class, id);
|
|
}
|
|
|
|
@POST
|
|
@Path("{id}/cover")
|
|
@RolesAllowed("ADMIN")
|
|
@Consumes({ MediaType.MULTIPART_FORM_DATA })
|
|
@TypeScriptProgress
|
|
public Artist uploadCover(@PathParam("id") final Long id, @FormDataOptional @FormDataParam("uri") final String uri, @FormDataOptional @FormDataParam("file") final InputStream fileInputStream,
|
|
@FormDataOptional @FormDataParam("file") final FormDataContentDisposition fileMetaData) throws Exception {
|
|
if (uri != null) {
|
|
DataTools.uploadCoverFromUri(Artist.class, id, uri);
|
|
} else {
|
|
DataTools.uploadCover(Artist.class, id, fileInputStream, fileMetaData);
|
|
}
|
|
return DataAccess.get(Artist.class, id);
|
|
}
|
|
|
|
@DELETE
|
|
@Path("{id}/cover/{coverId}")
|
|
@RolesAllowed("ADMIN")
|
|
public Artist removeCover(@PathParam("id") final Long id, @PathParam("coverId") final UUID coverId) throws Exception {
|
|
LOGGER.error("klmlmkmlkmlklmklmk");
|
|
AddOnDataJson.removeLink(Artist.class, id, "covers", coverId);
|
|
return DataAccess.get(Artist.class, id);
|
|
}
|
|
}
|