Skip to content

Commit

Permalink
[PPANTT-129] feat: Add API to retrieve creditor institution segregati…
Browse files Browse the repository at this point in the history
…on codes (#61)

* [PPANTT-129] move method to utility class

* [PPANTT-129] added API to retrieve all segregation codes associated to broker stations

* [PPANTT-129] added unit tests

* [PPANTT-129] updated openapi

* [PPANTT-129] removed unused imports
  • Loading branch information
gioelemella authored Sep 24, 2024
1 parent e15c789 commit 9ce4191
Show file tree
Hide file tree
Showing 14 changed files with 458 additions and 109 deletions.
162 changes: 161 additions & 1 deletion openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,133 @@
}
]
},
"/brokers/{broker-tax-code}/creditor-institutions/segregation-codes": {
"get": {
"tags": [
"Brokers"
],
"summary": "Get segregation codes grouped by creditor institutions associated to broker's station",
"operationId": "getCreditorInstitutionsSegregationCodeAssociatedToBroker",
"parameters": [
{
"name": "broker-tax-code",
"in": "path",
"description": "Broker tax code",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"headers": {
"X-Request-Id": {
"description": "This header identifies the call",
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CreditorInstitutionStationSegregationCodesList"
}
}
}
},
"400": {
"description": "Bad Request",
"headers": {
"X-Request-Id": {
"description": "This header identifies the call",
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemJson"
}
}
}
},
"401": {
"description": "Unauthorized",
"headers": {
"X-Request-Id": {
"description": "This header identifies the call",
"schema": {
"type": "string"
}
}
}
},
"403": {
"description": "Forbidden",
"headers": {
"X-Request-Id": {
"description": "This header identifies the call",
"schema": {
"type": "string"
}
}
}
},
"429": {
"description": "Too many requests",
"headers": {
"X-Request-Id": {
"description": "This header identifies the call",
"schema": {
"type": "string"
}
}
}
},
"500": {
"description": "Service unavailable",
"headers": {
"X-Request-Id": {
"description": "This header identifies the call",
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemJson"
}
}
}
}
},
"security": [
{
"ApiKey": []
},
{
"Authorization": []
}
]
},
"parameters": [
{
"name": "X-Request-Id",
"in": "header",
"description": "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.",
"schema": {
"type": "string"
}
}
]
},
"/brokers/{broker-tax-code}/stations": {
"get": {
"tags": [
Expand Down Expand Up @@ -2745,6 +2872,39 @@
"$ref": "#/components/schemas/PageInfo"
}
}
},
"CreditorInstitutionStationSegregationCodes": {
"required": [
"ci_tax_code",
"segregation_code_list"
],
"type": "object",
"properties": {
"ci_tax_code": {
"type": "string",
"description": "The tax code of the creditor institution",
"example": "02438750586"
},
"segregation_code_list": {
"type": "array",
"description": "List of segregation code used by the creditor institution in a broker station",
"items": {
"type": "string",
"description": "List of segregation code used by the creditor institution in a broker station"
}
}
}
},
"CreditorInstitutionStationSegregationCodesList": {
"type": "object",
"properties": {
"ci_station_segregation_codes": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CreditorInstitutionStationSegregationCodes"
}
}
}
}
},
"securitySchemes": {
Expand All @@ -2762,4 +2922,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import it.gov.pagopa.apiconfig.selfcareintegration.model.channel.ChannelDetails;
import it.gov.pagopa.apiconfig.selfcareintegration.model.creditorinstitution.CreditorInstitutionDetail;
import it.gov.pagopa.apiconfig.selfcareintegration.model.creditorinstitution.CreditorInstitutionInfo;
import it.gov.pagopa.apiconfig.selfcareintegration.model.creditorinstitution.CIStationRelation;
import it.gov.pagopa.apiconfig.selfcareintegration.model.creditorinstitution.ICIStationRelation;
import it.gov.pagopa.apiconfig.selfcareintegration.model.iban.IbanDetails;
import it.gov.pagopa.apiconfig.selfcareintegration.model.iban.IbanEnhanced;
import it.gov.pagopa.apiconfig.starter.entity.Canali;
Expand Down Expand Up @@ -34,6 +36,8 @@ ModelMapper modelMapper() {

mapper.createTypeMap(Pa.class, CreditorInstitutionInfo.class).setConverter(new ConvertPaToCreditorInstitutionInfo());
mapper.createTypeMap(IbanMaster.class, IbanEnhanced.class).setConverter(new ConvertIbanMasterToIbanDetailsTemp());
mapper.createTypeMap(ICIStationRelation.class, CIStationRelation.class)
.setConverter(new ConvertICIStationRelationToCIStationRelation());

return mapper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import it.gov.pagopa.apiconfig.selfcareintegration.model.ProblemJson;
import it.gov.pagopa.apiconfig.selfcareintegration.model.creditorinstitution.CreditorInstitutionDetails;
import it.gov.pagopa.apiconfig.selfcareintegration.model.creditorinstitution.CreditorInstitutionStationSegregationCodesList;
import it.gov.pagopa.apiconfig.selfcareintegration.model.station.StationDetailsList;
import it.gov.pagopa.apiconfig.selfcareintegration.service.BrokersService;
import org.springframework.data.domain.PageRequest;
Expand Down Expand Up @@ -49,49 +50,18 @@ public BrokerController(BrokersService brokersService) {
*/
@Operation(
summary = "Get broker's station list",
security = {
@SecurityRequirement(name = "ApiKey"),
@SecurityRequirement(name = "Authorization")
},
tags = {
"Brokers",
})
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "OK",
content =
@Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = StationDetailsList.class))),
@ApiResponse(
responseCode = "401",
description = "Unauthorized",
content = @Content(schema = @Schema())),
@ApiResponse(
responseCode = "403",
description = "Forbidden",
content = @Content(schema = @Schema())),
@ApiResponse(
responseCode = "404",
description = "Not Found",
content = @Content(schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(
responseCode = "429",
description = "Too many requests",
content = @Content(schema = @Schema())),
@ApiResponse(
responseCode = "500",
description = "Service unavailable",
content =
@Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = ProblemJson.class)))
})
@GetMapping(
value = "/{broker-tax-code}/stations",
produces = {MediaType.APPLICATION_JSON_VALUE})
security = {@SecurityRequirement(name = "ApiKey"), @SecurityRequirement(name = "Authorization")})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = StationDetailsList.class))),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "429", description = "Too many requests", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "500", description = "Service unavailable",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class)))
})
@GetMapping(value = "/{broker-tax-code}/stations", produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<StationDetailsList> getStationsDetailsFromBroker(
@Parameter(description = "The broker's tax code.", required = true)
@PathVariable("broker-tax-code")
Expand All @@ -101,9 +71,7 @@ public ResponseEntity<StationDetailsList> getStationsDetailsFromBroker(
@Parameter(description = "The creditor institution's tax code.") @RequestParam(required = false)
String ciTaxCode,
@Valid
@Parameter(
description = "The number of elements to be included in the page.",
required = true)
@Parameter(description = "The number of elements to be included in the page.", required = true)
@RequestParam(required = false, defaultValue = "10")
@Positive
@Max(999)
Expand All @@ -119,49 +87,21 @@ public ResponseEntity<StationDetailsList> getStationsDetailsFromBroker(
);
}


@Operation(
summary = "Get creditor institutions associated to broker by station",
security = {
@SecurityRequirement(name = "ApiKey"),
@SecurityRequirement(name = "Authorization")
},
tags = {
"Brokers",
})
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "OK",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = CreditorInstitutionDetails.class))),
@ApiResponse(
responseCode = "400",
description = "Bad Request",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(
responseCode = "401",
description = "Unauthorized",
content = @Content(schema = @Schema())),
@ApiResponse(
responseCode = "403",
description = "Forbidden",
content = @Content(schema = @Schema())),
@ApiResponse(
responseCode = "429",
description = "Too many requests",
content = @Content(schema = @Schema())),
@ApiResponse(
responseCode = "500",
description = "Service unavailable",
content =
@Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = ProblemJson.class)))
})
@GetMapping(
value = "/{broker-tax-code}/creditor-institutions",
produces = {MediaType.APPLICATION_JSON_VALUE})
security = {@SecurityRequirement(name = "ApiKey"), @SecurityRequirement(name = "Authorization")})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = CreditorInstitutionDetails.class))),
@ApiResponse(responseCode = "400", description = "Bad Request",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "429", description = "Too many requests", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "500", description = "Service unavailable",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class)))
})
@GetMapping(value = "/{broker-tax-code}/creditor-institutions", produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<CreditorInstitutionDetails> getCreditorInstitutionsAssociatedToBroker(
@Parameter(description = "Number of elements on one page. Default = 50")
@Positive @RequestParam(required = false, defaultValue = "50")
Expand All @@ -174,7 +114,29 @@ public ResponseEntity<CreditorInstitutionDetails> getCreditorInstitutionsAssocia
String brokerCode,
@Parameter(description = "Filter by enabled station")
@RequestParam(required = false, name = "enabled")
Boolean enabled) {
Boolean enabled
) {
return ResponseEntity.ok(brokersService.getCreditorInstitutionsAssociatedToBroker(brokerCode, enabled, PageRequest.of(page, limit)));
}

@Operation(
summary = "Get segregation codes grouped by creditor institutions associated to broker's station",
security = {@SecurityRequirement(name = "ApiKey"), @SecurityRequirement(name = "Authorization")})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = CreditorInstitutionStationSegregationCodesList.class))),
@ApiResponse(responseCode = "400", description = "Bad Request",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "429", description = "Too many requests", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "500", description = "Service unavailable",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class)))
})
@GetMapping(value = "/{broker-tax-code}/creditor-institutions/segregation-codes", produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<CreditorInstitutionStationSegregationCodesList> getCreditorInstitutionsSegregationCodeAssociatedToBroker(
@Parameter(description = "Broker tax code") @PathVariable("broker-tax-code") String brokerTaxCode
) {
return ResponseEntity.ok(this.brokersService.getCreditorInstitutionsSegregationCodeAssociatedToBroker(brokerTaxCode));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package it.gov.pagopa.apiconfig.selfcareintegration.mapper;

import it.gov.pagopa.apiconfig.selfcareintegration.model.creditorinstitution.CIStationRelation;
import it.gov.pagopa.apiconfig.selfcareintegration.model.creditorinstitution.ICIStationRelation;
import it.gov.pagopa.apiconfig.selfcareintegration.util.Utility;
import org.modelmapper.Converter;
import org.modelmapper.spi.MappingContext;

/**
* Converter class, define how to map the {@link ICIStationRelation} entity into the {@link CIStationRelation} model
*/
public class ConvertICIStationRelationToCIStationRelation implements Converter<ICIStationRelation, CIStationRelation> {

@Override
public CIStationRelation convert(MappingContext<ICIStationRelation, CIStationRelation> context) {
ICIStationRelation source = context.getSource();

return CIStationRelation.builder()
.ciTaxCode(source.getIdDominio())
.segregationCode(Utility.getDoubleDigitCode(source.getSegregazione()))
.build();
}
}
Loading

0 comments on commit 9ce4191

Please sign in to comment.