Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SELC-6156] Added new DocumentController #635

Merged
merged 10 commits into from
Dec 13, 2024
74 changes: 74 additions & 0 deletions apps/onboarding-ms/src/main/docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
} ],
"tags" : [ {
"name" : "Aggregates Controller"
}, {
"name" : "Document Controller"
}, {
"name" : "Onboarding"
}, {
Expand Down Expand Up @@ -207,6 +209,78 @@
} ]
}
},
"/v1/documents" : {
"get" : {
"tags" : [ "internal-v1" ],
"summary" : "Retrieves the list of files on the azure storage on the given path",
"description" : "Fetches a list of files associated with the specified path on the storage.",
"operationId" : "getFiles",
"responses" : {
"200" : {
"description" : "OK",
"content" : {
"application/json" : {
"schema" : {
"type" : "array",
"items" : {
"type" : "string"
}
}
}
}
},
"401" : {
"description" : "Not Authorized"
},
"403" : {
"description" : "Not Allowed"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
},
"/v1/documents/{path}" : {
"get" : {
"tags" : [ "internal-v1" ],
"summary" : "Retrieves the list of files on the azure storage on the given path",
"description" : "Fetches a list of files associated with the specified path on the storage.",
"operationId" : "getFiles",
"parameters" : [ {
"name" : "path",
"in" : "path",
"required" : true,
"schema" : {
"type" : "string"
}
} ],
"responses" : {
"200" : {
"description" : "OK",
"content" : {
"application/json" : {
"schema" : {
"type" : "array",
"items" : {
"type" : "string"
}
}
}
}
},
"401" : {
"description" : "Not Authorized"
},
"403" : {
"description" : "Not Allowed"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
},
"/v1/onboarding" : {
"get" : {
"tags" : [ "Onboarding Controller" ],
Expand Down
53 changes: 53 additions & 0 deletions apps/onboarding-ms/src/main/docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ servers:
description: Auto generated value
tags:
- name: Aggregates Controller
- name: Document Controller
- name: Onboarding
- name: Onboarding Controller
- name: billing-portal
Expand Down Expand Up @@ -152,6 +153,58 @@ paths:
description: Not Allowed
security:
- SecurityScheme: []
/v1/documents:
get:
tags:
- internal-v1
summary: Retrieves the list of files on the azure storage on the given path
description: Fetches a list of files associated with the specified path on the
storage.
operationId: getFiles
responses:
"200":
description: OK
content:
application/json:
schema:
type: array
items:
type: string
"401":
description: Not Authorized
"403":
description: Not Allowed
security:
- SecurityScheme: []
/v1/documents/{path}:
get:
tags:
- internal-v1
summary: Retrieves the list of files on the azure storage on the given path
description: Fetches a list of files associated with the specified path on the
storage.
operationId: getFiles
parameters:
- name: path
in: path
required: true
schema:
type: string
responses:
"200":
description: OK
content:
application/json:
schema:
type: array
items:
type: string
"401":
description: Not Authorized
"403":
description: Not Allowed
security:
- SecurityScheme: []
/v1/onboarding:
get:
tags:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package it.pagopa.selfcare.onboarding.controller;


import io.quarkus.security.Authenticated;
import io.smallrye.mutiny.Uni;
import it.pagopa.selfcare.azurestorage.AzureBlobClient;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;

@Authenticated
@Path("/v1/documents")
@Tag(name = "Document Controller")
@AllArgsConstructor
@Slf4j
public class DocumentController {

@Inject
AzureBlobClient blobClient;

/**
* Retrieves the list of files by the path on the blob
*
* @return List of files on the storage * Code: 200, Message: successful operation * Code: 400, Message: Invalid ID supplied * Code: 404, Message:
* Path not found
*/

@Operation(
summary = "Retrieves the list of files on the azure storage on the given path",
description = "Fetches a list of files associated with the specified path on the storage."
)
@GET
@Tag(name = "internal-v1")
@Produces(MediaType.APPLICATION_JSON)
public Uni<List<String>> getFiles() {
return Uni.createFrom().item(blobClient.getFiles());
}

/**
* Retrieves the list of files by the path on the blob
*
* @param path path of the folder into azure storage
* @return List of files on the storage * Code: 200, Message: successful operation * Code: 400, Message: Invalid ID supplied * Code: 404, Message:
* Path not found
*/

@Operation(
summary = "Retrieves the list of files on the azure storage on the given path",
description = "Fetches a list of files associated with the specified path on the storage."
)
@GET
@Tag(name = "internal-v1")
@Path("/{path}")
@Produces(MediaType.APPLICATION_JSON)
public Uni<List<String>> getFiles(@PathParam(value = "path") String path) {
return Uni.createFrom().item(blobClient.getFiles(path));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package it.pagopa.selfcare.onboarding.controller;

import static io.restassured.RestAssured.given;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;

import io.quarkus.test.InjectMock;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.common.http.TestHTTPEndpoint;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.mongodb.MongoTestResource;
import io.quarkus.test.security.TestSecurity;
import io.restassured.http.ContentType;
import it.pagopa.selfcare.azurestorage.AzureBlobClient;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

@QuarkusTest
@TestHTTPEndpoint(DocumentController.class)
@QuarkusTestResource(MongoTestResource.class)
class DocumentControllerTest {

@InjectMock
AzureBlobClient blobClient;

@Test
@TestSecurity(user = "userJwt")
void getFiles_ByPath_OK() {
// given
final String path = "/test/test";
List<String> result = new ArrayList<>();

// when
when(blobClient.getFiles(anyString())).thenReturn(result);

given()
.when()
.contentType(ContentType.JSON)
.pathParam("path", path)
.get("{path}")
.then()
.statusCode(200);

// then
Mockito.verify(blobClient, times(1)).getFiles(anyString());

}

@Test
@TestSecurity(user = "userJwt")
void getFiles_OK() {
// given
List<String> result = new ArrayList<>();

// when
when(blobClient.getFiles()).thenReturn(result);

given()
.when()
.contentType(ContentType.JSON)
.get()
.then()
.statusCode(200);

// then
Mockito.verify(blobClient, times(1)).getFiles();

}

}
Loading