Skip to content

Commit

Permalink
getById
Browse files Browse the repository at this point in the history
  • Loading branch information
ElisKina-dev committed Nov 13, 2023
1 parent c418fe7 commit d0606ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public enum AppErrorCodeEnum {
WORKFLOW_RESOURCE_CANNOT_BE_DELETED_FOR_STATUS("ATMLM_4000024", "The referenced Workflow Resource file can not be deleted in the actual state", NOT_DELETABLE),
WORKFLOW_RESOURCE_CANNOT_BE_UPDATED_FOR_STATUS("ATMLM_4000025", "The referenced Workflow Resource file can not be updated in the actual state", NOT_UPDATABLE),
WORKFLOW_RESOURCE_FILE_CANNOT_BE_DEPLOYED("ATMLM_4000026", "The referenced Workflow Resource file can not be deployed", NOT_DEPLOYABLE_STATUS),
RESOURCE_WITH_SAME_NAME_AND_PATH_ALREADY_SAVED("ATMLM_4000027", "A resource with same file name and path already exists", NOT_UPLOADABLE);
RESOURCE_WITH_SAME_NAME_AND_PATH_ALREADY_SAVED("ATMLM_4000027", "A resource with same file name and path already exists", NOT_UPLOADABLE),
RESOURCE_FILE_DOES_NOT_EXIST("ATMLM_4000028", "The referenced Resource file does not exist", NOT_EXISTING_REFERENCED_ENTITY);



Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package it.gov.pagopa.atmlayer.service.model.resource;

import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.RESOURCE_FILE_DOES_NOT_EXIST;

import io.smallrye.common.annotation.NonBlocking;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.unchecked.Unchecked;
import it.gov.pagopa.atmlayer.service.model.dto.ResourceCreationDto;
import it.gov.pagopa.atmlayer.service.model.entity.ResourceEntity;
import it.gov.pagopa.atmlayer.service.model.exception.AtmLayerException;
import it.gov.pagopa.atmlayer.service.model.mapper.ResourceEntityMapper;
import it.gov.pagopa.atmlayer.service.model.model.ResourceDTO;
import it.gov.pagopa.atmlayer.service.model.service.ResourceEntityService;
Expand All @@ -15,15 +18,17 @@
import jakarta.ws.rs.GET;
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;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;

import jakarta.ws.rs.core.Response;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;

@ApplicationScoped
@Path("/resources")
Expand All @@ -38,7 +43,7 @@ public class ResourceEntityResource {

@GET
@Produces(MediaType.APPLICATION_JSON)
public Uni<List<ResourceDTO>> getAllHtml() {
public Uni<List<ResourceDTO>> getAll() {
return this.resourceEntityService.getAll()
.onItem()
.transform(Unchecked.function(list -> {
Expand All @@ -49,6 +54,21 @@ public Uni<List<ResourceDTO>> getAllHtml() {
}));
}

@GET
@Path("/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
public Uni<ResourceDTO> getById(@PathParam("uuid") UUID uuid){
return this.resourceEntityService.findByUUID(uuid)
.onItem()
.transform(Unchecked.function(x -> {
if (x.isEmpty()) {
throw new AtmLayerException(Response.Status.NOT_FOUND, RESOURCE_FILE_DOES_NOT_EXIST);
}
return resourceEntityMapper.toDTO(x.get());
}));
}


@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
Expand Down

0 comments on commit d0606ea

Please sign in to comment.