diff --git a/app/src/main/resources/swagger/api-docs.json b/app/src/main/resources/swagger/api-docs.json index 1930b82f..8164c044 100644 --- a/app/src/main/resources/swagger/api-docs.json +++ b/app/src/main/resources/swagger/api-docs.json @@ -1279,22 +1279,13 @@ } ] } }, - "/v2/institutions/company/{companyTaxCode}/verify-manager" : { - "get" : { + "/v2/institutions/company/verify-manager" : { + "post" : { "tags" : [ "institutions" ], "summary" : "verifyManager", "description" : "The service allows to verify the legal representative on external registries and retrieve the company name", - "operationId" : "verifyManagerUsingGET", + "operationId" : "verifyManagerUsingPOST", "parameters" : [ { - "name" : "companyTaxCode", - "in" : "path", - "description" : "Institution's taxCode", - "required" : true, - "style" : "simple", - "schema" : { - "type" : "string" - } - }, { "name" : "name", "in" : "query", "required" : false, @@ -1303,6 +1294,15 @@ "type" : "string" } } ], + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/VerifyManagerRequest" + } + } + } + }, "responses" : { "200" : { "description" : "OK", @@ -1344,6 +1344,16 @@ } } }, + "409" : { + "description" : "Conflict", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, "500" : { "description" : "Internal Server Error", "content" : { @@ -4743,6 +4753,16 @@ } } }, + "VerifyManagerRequest" : { + "title" : "VerifyManagerRequest", + "type" : "object", + "properties" : { + "companyTaxCode" : { + "type" : "string", + "description" : "Institution's taxCode" + } + } + }, "VerifyManagerResponse" : { "title" : "VerifyManagerResponse", "type" : "object", diff --git a/web/src/main/java/it/pagopa/selfcare/onboarding/web/controller/InstitutionV2Controller.java b/web/src/main/java/it/pagopa/selfcare/onboarding/web/controller/InstitutionV2Controller.java index ec4109ae..132000b4 100644 --- a/web/src/main/java/it/pagopa/selfcare/onboarding/web/controller/InstitutionV2Controller.java +++ b/web/src/main/java/it/pagopa/selfcare/onboarding/web/controller/InstitutionV2Controller.java @@ -133,19 +133,18 @@ public VerifyAggregatesResponse verifyAggregatesCsv(@RequestParam("aggregates") return response; } - @GetMapping(value = "/company/{companyTaxCode}/verify-manager") + @PostMapping(value = "/company/verify-manager") @ResponseStatus(HttpStatus.OK) @ApiOperation(value = "", notes = "${swagger.onboarding.institutions.api.onboarding.verifyManager}") public VerifyManagerResponse verifyManager( - @ApiParam("${swagger.onboarding.institutions.model.taxCode}") - @PathVariable("companyTaxCode") String companyTaxCode, + @RequestBody @Valid VerifyManagerRequest request, Principal principal ) { log.trace("verifyManager start"); JwtAuthenticationToken jwtAuthenticationToken = (JwtAuthenticationToken) principal; SelfCareUser selfCareUser = (SelfCareUser) jwtAuthenticationToken.getPrincipal(); - VerifyManagerResponse response = onboardingResourceMapper.toManagerVerification(institutionService.verifyManager(selfCareUser.getFiscalCode(), companyTaxCode)); + VerifyManagerResponse response = onboardingResourceMapper.toManagerVerification(institutionService.verifyManager(selfCareUser.getFiscalCode(), request.getCompanyTaxCode())); log.trace("verifyManager end"); return response; } diff --git a/web/src/main/java/it/pagopa/selfcare/onboarding/web/model/VerifyManagerRequest.java b/web/src/main/java/it/pagopa/selfcare/onboarding/web/model/VerifyManagerRequest.java new file mode 100644 index 00000000..5ce4e592 --- /dev/null +++ b/web/src/main/java/it/pagopa/selfcare/onboarding/web/model/VerifyManagerRequest.java @@ -0,0 +1,15 @@ +package it.pagopa.selfcare.onboarding.web.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +@Data +public class VerifyManagerRequest { + @ApiModelProperty(value = "${swagger.onboarding.institutions.model.taxCode}") + @JsonProperty(required = true) + @NotBlank + private String companyTaxCode; +} diff --git a/web/src/test/java/it/pagopa/selfcare/onboarding/web/controller/InstitutionV2ControllerTest.java b/web/src/test/java/it/pagopa/selfcare/onboarding/web/controller/InstitutionV2ControllerTest.java index 4057e631..161d18ee 100644 --- a/web/src/test/java/it/pagopa/selfcare/onboarding/web/controller/InstitutionV2ControllerTest.java +++ b/web/src/test/java/it/pagopa/selfcare/onboarding/web/controller/InstitutionV2ControllerTest.java @@ -204,6 +204,9 @@ void verifyManager_success() throws Exception { .build(); Mockito.when(mockPrincipal.getPrincipal()).thenReturn(selfCareUser); + VerifyManagerRequest verifyManagerRequest = new VerifyManagerRequest(); + verifyManagerRequest.setCompanyTaxCode("taxCode"); + ManagerVerification managerVerification = new ManagerVerification(); managerVerification.setOrigin("INFOCAMERE"); managerVerification.setCompanyName("CompanyName"); @@ -211,7 +214,8 @@ void verifyManager_success() throws Exception { // when MvcResult result = mvc.perform(MockMvcRequestBuilders - .get(BASE_URL + "/company/validCompanyTaxCode/verify-manager") + .post(BASE_URL + "/company/verify-manager") + .content(objectMapper.writeValueAsString(verifyManagerRequest)) .principal(mockPrincipal) .contentType(APPLICATION_JSON_VALUE) .accept(APPLICATION_JSON_VALUE)) @@ -227,6 +231,27 @@ void verifyManager_success() throws Exception { verifyNoMoreInteractions(institutionServiceMock); } + @Test + void verifyManager_invalidRequest() throws Exception { + // given + JwtAuthenticationToken mockPrincipal = Mockito.mock(JwtAuthenticationToken.class); + SelfCareUser selfCareUser = SelfCareUser.builder("example") + .fiscalCode("fiscalCode") + .build(); + Mockito.when(mockPrincipal.getPrincipal()).thenReturn(selfCareUser); + + VerifyManagerRequest request = new VerifyManagerRequest(); + + // when + mvc.perform(MockMvcRequestBuilders + .post(BASE_URL + "/company/verify-manager") + .principal(mockPrincipal) + .content(objectMapper.writeValueAsString(request)) + .contentType(APPLICATION_JSON_VALUE) + .accept(APPLICATION_JSON_VALUE)) + .andExpect(status().isBadRequest()); + } + @Test void getActiveOnboarding_success() throws Exception { // given