From fa7d99f5190fc081ec9c34030159ca7700a28d37 Mon Sep 17 00:00:00 2001 From: Fernando-Granato Date: Wed, 2 Aug 2023 18:07:54 +0200 Subject: [PATCH 01/11] feat(opeanpi):added openapi.yaml --- api-spec/openapi.yaml | 252 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 api-spec/openapi.yaml diff --git a/api-spec/openapi.yaml b/api-spec/openapi.yaml new file mode 100644 index 0000000..98ec382 --- /dev/null +++ b/api-spec/openapi.yaml @@ -0,0 +1,252 @@ +openapi: 3.0.0 +info: + version: 1.0.0 + title: Pagopa eCommerce services for assistence api + description: This microservice that expose eCommerce services for assistence api. +servers: + - url: https://${host} +paths: + /pm/searchTransaction: + post: + parameters: + - in: query + name: pageNumber + schema: + type: integer + required: true + description: "Searched page number" + - in: query + name: pageSize + schema: + type: integer + required: true + description: "Max element per page" + tags: + - PM + operationId: pmSearchTransaction + summary: Search transaction by input parmeters + description: 'GET with body payload - no resources created' + requestBody: + $ref: "#/components/requestBodies/PmSearchTransactionRequest" + responses: + '200': + description: Transactions found + content: + application/json: + schema: + $ref: '#/components/schemas/PmSearchTransactionResponse' + '400': + description: Formally invalid input + content: + application/json: + schema: + $ref: '#/components/schemas/ProblemJson' + '404': + description: Transaction not found + content: + application/json: + schema: + $ref: '#/components/schemas/ProblemJson' + '500': + description: Internal server error + content: + application/json: + schema: + $ref: '#/components/schemas/ProblemJson' +components: + schemas: + ProblemJson: + type: object + properties: + type: + type: string + format: uri + description: |- + An absolute URI that identifies the problem type. When dereferenced, + it SHOULD provide human-readable documentation for the problem type + (e.g., using HTML). + default: about:blank + example: https://example.com/problem/constraint-violation + title: + type: string + description: |- + A short, summary of the problem type. Written in english and readable + for engineers (usually not suited for non technical stakeholders and + not localized); example: Service Unavailable + status: + $ref: '#/components/schemas/HttpStatusCode' + detail: + type: string + description: |- + A human readable explanation specific to this occurrence of the + problem. + example: There was an error processing the request + instance: + type: string + format: uri + description: |- + An absolute URI that identifies the specific occurrence of the problem. + It may or may not yield further information if dereferenced. + HttpStatusCode: + type: integer + format: int32 + description: |- + The HTTP status code generated by the origin server for this occurrence + of the problem. + minimum: 100 + maximum: 600 + exclusiveMaximum: true + example: 200 + PmSearchTransactionRequestFiscalCode: + type: object + description: Search transaction by user fiscal code + properties: + type: + type: string + userFiscalCode: + type: string + minLength: 16 + maxLength: 16 + required: + - type + - userFiscalCode + example: + type: "USER_FISCAL_CODE" + userFiscalCode: "MRGHRN97L02C469W" + PmSearchTransactionRequestEmail: + type: object + description: Search transaction by user fiscal code + properties: + type: + type: string + userEmail: + type: string + pattern: (?:[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\[(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]) + required: + - type + - userEmail + example: + type: "USER_EMAIL" + userEmail: "mario.rossi@pagopa.it" + PmSearchTransactionResponse: + type: object + description: TransactionResponse + properties: + transactions: + type: array + items: + $ref: '#/components/schemas/TrasactionResults' + totalTransactionCount: + type: integer + required: + - transactions + - totalTransactionCount + TrasactionResults: + type: object + description: TransactionResponse + properties: + transactionInfo: + $ref: '#/components/schemas/TransactionInfo' + paymentInfo: + $ref: '#/components/schemas/PaymentInfo' + paymentDetailInfo: + $ref: '#/components/schemas/PaymentDetailInfo' + pspInfo: + $ref: '#/components/schemas/PspInfo' + TransactionInfo: + type: object + description: TransactionResponse + properties: + creationDate: + type: string + format: date-time + description: transaction creation date + status: + type: string + amount: + $ref: '#/components/schemas/AmountEuroCents' + fee: + $ref: '#/components/schemas/AmountEuroCents' + grandTotal: + $ref: '#/components/schemas/AmountEuroCents' + example: + creationDate: "2023-08-02T14:42:54.047" + status: "TO BE DEFINED" + amount: 100 + fee: 10 + grandTotal: 110 + PaymentInfo: + type: object + description: TransactionResponse + properties: + amount: + $ref: '#/components/schemas/AmountEuroCents' + subject: + type: string + origin: + type: string + example: + amount: 100 + subject: "Causale pagamento" + origin: "CHECKOUT" + PaymentDetailInfo: + type: object + description: TransactionResponse + properties: + iuv: + type: string + minLength: 18 + maxLength: 18 + paymentContextCode: + type: string + creditorInstitution: + type: string + amount: + $ref: '#/components/schemas/AmountEuroCents' + paFiscalCode: + type: string + example: + iuv: "302001069073736640" + paymentContextCode: "paymentContextCode" + creditorInstitution: "66666666666" + amount: 99999999 + paFiscalCode: "77777777777" + PspInfo: + type: object + description: TransactionResponse + properties: + pspId: + type: string + businessName: + type: string + idChannel: + type: string + example: + pspId: "EXAMPLEPSP" + businessName: "businessName" + idChannel: "13212880150_02_ONUS" + AmountEuroCents: + description: Amount for payments, in euro cents + type: integer + minimum: 0 + maximum: 99999999 + requestBodies: + PmSearchTransactionRequest: + required: true + content: + application/json: + schema: + oneOf: + - $ref: '#/components/schemas/PmSearchTransactionRequestFiscalCode' + - $ref: '#/components/schemas/PmSearchTransactionRequestEmail' + discriminator: + propertyName: type + mapping: + USER_FISCAL_CODE: "#/components/schemas/PmSearchTransactionRequestFiscalCode" + USER_EMAIL: "#/components/schemas/PmSearchTransactionRequestEmail" + PmSearchTransactionResponse: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/PmSearchTransactionResponse' \ No newline at end of file From 965498a2293fe084f22049880e16c49d2b9e271c Mon Sep 17 00:00:00 2001 From: Fernando-Granato Date: Wed, 2 Aug 2023 18:08:18 +0200 Subject: [PATCH 02/11] feat(build gradle):added generated task for gradle build --- build.gradle.kts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index ea5a6f7..c13a436 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -132,6 +132,43 @@ configure { } } +tasks.register( + "helpdesk", + org.openapitools.generator.gradle.plugin.tasks.GenerateTask::class.java +) { + generatorName.set("spring") + inputSpec.set("$rootDir/api-spec/openapi.yaml") + outputDir.set("$buildDir/generated") + apiPackage.set("it.pagopa.generated.ecommerce.helpdesk.api") + modelPackage.set("it.pagopa.generated.ecommerce.helpdesk.model") + generateApiTests.set(false) + generateApiDocumentation.set(false) + generateApiTests.set(false) + generateModelTests.set(false) + library.set("spring-boot") + modelNameSuffix.set("Dto") + configOptions.set( + mapOf( + "swaggerAnnotations" to "false", + "openApiNullable" to "true", + "interfaceOnly" to "true", + "hideGenerationTimestamp" to "true", + "skipDefaultInterface" to "true", + "useSwaggerUI" to "false", + "reactive" to "true", + "useSpringBoot3" to "true", + "oas3" to "true", + "generateSupportingFiles" to "true", + "enumPropertyNaming" to "UPPERCASE" + ) + ) +} + +tasks.withType { + dependsOn("helpdesk") + kotlinOptions.jvmTarget = "17" +} + tasks.named("jar") { enabled = false } tasks.test { From a4167a76d518e8596a3acba92bb8d1cda429125a Mon Sep 17 00:00:00 2001 From: Pietro Tota Date: Wed, 2 Aug 2023 18:14:12 +0200 Subject: [PATCH 03/11] fix(openapi): make response top level objects required --- api-spec/openapi.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api-spec/openapi.yaml b/api-spec/openapi.yaml index 98ec382..a2d3baf 100644 --- a/api-spec/openapi.yaml +++ b/api-spec/openapi.yaml @@ -153,6 +153,11 @@ components: $ref: '#/components/schemas/PaymentDetailInfo' pspInfo: $ref: '#/components/schemas/PspInfo' + required: + - transactionInfo + - paymentInfo + - paymentDetailInfo + - pspInfo TransactionInfo: type: object description: TransactionResponse From 76744ef023454cade5d717390adde6658671cd6d Mon Sep 17 00:00:00 2001 From: Pietro Tota Date: Thu, 3 Aug 2023 10:11:43 +0200 Subject: [PATCH 04/11] feat(open-api): add eCommerce search transaction api --- api-spec/openapi.yaml | 134 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 129 insertions(+), 5 deletions(-) diff --git a/api-spec/openapi.yaml b/api-spec/openapi.yaml index a2d3baf..5a06a76 100644 --- a/api-spec/openapi.yaml +++ b/api-spec/openapi.yaml @@ -5,6 +5,17 @@ info: description: This microservice that expose eCommerce services for assistence api. servers: - url: https://${host} +tags: + - name: PM + description: Api's for performing transaction search on PM DB + externalDocs: + url: TODO + description: Technical specifications + - name: eCommerce + description: Api's for performing transaction search on ecommerce DB + externalDocs: + url: TODO + description: Technical specifications paths: /pm/searchTransaction: post: @@ -34,7 +45,54 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/PmSearchTransactionResponse' + $ref: '#/components/schemas/SearchTransactionResponse' + '400': + description: Formally invalid input + content: + application/json: + schema: + $ref: '#/components/schemas/ProblemJson' + '404': + description: Transaction not found + content: + application/json: + schema: + $ref: '#/components/schemas/ProblemJson' + '500': + description: Internal server error + content: + application/json: + schema: + $ref: '#/components/schemas/ProblemJson' + /ecommerce/searchTransaction: + post: + parameters: + - in: query + name: pageNumber + schema: + type: integer + required: true + description: "Searched page number" + - in: query + name: pageSize + schema: + type: integer + required: true + description: "Max element per page" + tags: + - eCommerce + operationId: ecommerceSearchTransaction + summary: Search transaction by input parmeters + description: 'GET with body payload - no resources created' + requestBody: + $ref: "#/components/requestBodies/EcommerceSearchTransactionRequest" + responses: + '200': + description: Transactions found + content: + application/json: + schema: + $ref: '#/components/schemas/SearchTransactionResponse' '400': description: Formally invalid input content: @@ -128,20 +186,65 @@ components: example: type: "USER_EMAIL" userEmail: "mario.rossi@pagopa.it" - PmSearchTransactionResponse: + SearchTransactionResponse: type: object description: TransactionResponse properties: transactions: type: array items: - $ref: '#/components/schemas/TrasactionResults' + $ref: '#/components/schemas/TransactionResult' totalTransactionCount: type: integer required: - transactions - totalTransactionCount - TrasactionResults: + EcommerceSearchTransactionRequestRptId: + type: object + description: Search transaction by user fiscal code + properties: + type: + type: string + rptId: + type: string + pattern: ^([0-9]{29})$ + required: + - type + - rptId + example: + type: "RPT_ID" + rptId: "77777777777302011111111111111" + EcommerceSearchTransactionRequestPaymentToken: + type: object + description: Search transaction by payment token + properties: + type: + type: string + paymentToken: + type: string + required: + - type + - paymentToken + example: + type: "PAYMENT_TOKEN" + paymentToken: "paymentToken" + EcommerceSearchTransactionRequestTransactionId: + type: object + description: Search transaction by transaction id + properties: + type: + type: string + transactionId: + type: string + minLength: 32 + maxLength: 32 + required: + - type + - transactionId + example: + type: "TRANSACTION_ID" + transactionId: "c9644451389e47b0a7d8e9d488fcd502" + TransactionResult: type: object description: TransactionResponse properties: @@ -254,4 +357,25 @@ components: content: application/json: schema: - $ref: '#/components/schemas/PmSearchTransactionResponse' \ No newline at end of file + $ref: '#/components/schemas/SearchTransactionResponse' + EcommerceSearchTransactionRequest: + required: true + content: + application/json: + schema: + oneOf: + - $ref: '#/components/schemas/EcommerceSearchTransactionRequestRptId' + - $ref: '#/components/schemas/EcommerceSearchTransactionRequestPaymentToken' + - $ref: '#/components/schemas/EcommerceSearchTransactionRequestTransactionId' + discriminator: + propertyName: type + mapping: + RPT_ID: "#/components/schemas/EcommerceSearchTransactionRequestRptId" + PAYMENT_TOKEN: "#/components/schemas/EcommerceSearchTransactionRequestPaymentToken" + TRANSACTION_ID: "#/components/schemas/EcommerceSearchTransactionRequestTransactionId" + EcommerceSearchTransactionResponse: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/SearchTransactionResponse' \ No newline at end of file From e74c1d36bdb439e24980ab315141989cda6e397f Mon Sep 17 00:00:00 2001 From: Fernando-Granato Date: Thu, 3 Aug 2023 10:56:39 +0200 Subject: [PATCH 05/11] feat(controller): added controller class for ecommerce and pm --- .../controllers/EcommerceController.kt | 32 +++++++++++++++++++ .../helpdesk/controllers/PmController.kt | 32 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/EcommerceController.kt create mode 100644 src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/PmController.kt diff --git a/src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/EcommerceController.kt b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/EcommerceController.kt new file mode 100644 index 0000000..1391944 --- /dev/null +++ b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/EcommerceController.kt @@ -0,0 +1,32 @@ +package it.pagopa.ecommerce.helpdesk.controllers + +import it.pagopa.ecommerce.helpdesk.services.EcommerceService +import it.pagopa.generated.ecommerce.helpdesk.api.EcommerceApi +import it.pagopa.generated.ecommerce.helpdesk.model.EcommerceSearchTransactionRequestDto +import it.pagopa.generated.ecommerce.helpdesk.model.SearchTransactionResponseDto +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.RestController +import org.springframework.web.server.ServerWebExchange +import reactor.core.publisher.Mono + +@RestController +class EcommerceController : EcommerceApi { + + @Autowired private lateinit var ecommerceService: EcommerceService + + private val logger = LoggerFactory.getLogger(this.javaClass) + + override fun ecommerceSearchTransaction( + pageNumber: Int?, + pageSize: Int?, + ecommerceSearchTransactionRequestDto: Mono?, + exchange: ServerWebExchange? + ): Mono> { + logger.info("[HelpDesk controller] ecommerceSearchTransaction") + return ecommerceService + .searchTransaction(pageNumber, pageSize, ecommerceSearchTransactionRequestDto) + .map { ResponseEntity.ok(it) } + } +} diff --git a/src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/PmController.kt b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/PmController.kt new file mode 100644 index 0000000..09e0b98 --- /dev/null +++ b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/PmController.kt @@ -0,0 +1,32 @@ +package it.pagopa.ecommerce.helpdesk.controllers + +import it.pagopa.ecommerce.helpdesk.services.PmService +import it.pagopa.generated.ecommerce.helpdesk.api.PmApi +import it.pagopa.generated.ecommerce.helpdesk.model.PmSearchTransactionRequestDto +import it.pagopa.generated.ecommerce.helpdesk.model.SearchTransactionResponseDto +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.RestController +import org.springframework.web.server.ServerWebExchange +import reactor.core.publisher.Mono + +@RestController +class PmController : PmApi { + + @Autowired private lateinit var pmService: PmService + + private val logger = LoggerFactory.getLogger(this.javaClass) + + override fun pmSearchTransaction( + pageNumber: Int?, + pageSize: Int?, + pmSearchTransactionRequestDto: Mono?, + exchange: ServerWebExchange? + ): Mono> { + logger.info("[HelpDesk controller] pmSearchTransaction") + return pmService + .searchTransaction(pageSize, pageNumber, pmSearchTransactionRequestDto) + .map { ResponseEntity.ok(it) } + } +} From 39d149f87006b03364d04bd37b1ed0c0f59a960a Mon Sep 17 00:00:00 2001 From: Fernando-Granato Date: Thu, 3 Aug 2023 10:56:55 +0200 Subject: [PATCH 06/11] feat(service): added service class for ecommerce and pm --- .../helpdesk/services/EcommerceService.kt | 22 +++++++++++++++++++ .../ecommerce/helpdesk/services/PmService.kt | 22 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/EcommerceService.kt create mode 100644 src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/PmService.kt diff --git a/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/EcommerceService.kt b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/EcommerceService.kt new file mode 100644 index 0000000..c212f20 --- /dev/null +++ b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/EcommerceService.kt @@ -0,0 +1,22 @@ +package it.pagopa.ecommerce.helpdesk.services + +import it.pagopa.generated.ecommerce.helpdesk.model.EcommerceSearchTransactionRequestDto +import it.pagopa.generated.ecommerce.helpdesk.model.SearchTransactionResponseDto +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service +import reactor.core.publisher.Mono + +@Service +class EcommerceService { + + private val logger = LoggerFactory.getLogger(javaClass) + + fun searchTransaction( + pageNumber: Int?, + pageSize: Int?, + ecommerceSearchTransactionRequestDto: Mono? + ): Mono { + logger.info("[helpDesk ecommerce service] searchTransaction method") + return Mono.just(SearchTransactionResponseDto()) + } +} diff --git a/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/PmService.kt b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/PmService.kt new file mode 100644 index 0000000..a23984e --- /dev/null +++ b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/PmService.kt @@ -0,0 +1,22 @@ +package it.pagopa.ecommerce.helpdesk.services + +import it.pagopa.generated.ecommerce.helpdesk.model.PmSearchTransactionRequestDto +import it.pagopa.generated.ecommerce.helpdesk.model.SearchTransactionResponseDto +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service +import reactor.core.publisher.Mono + +@Service +class PmService { + + private val logger = LoggerFactory.getLogger(javaClass) + + fun searchTransaction( + pageNumber: Int?, + pageSize: Int?, + pmSearchTransactionRequestDto: Mono? + ): Mono { + logger.info("[helpDesk pm service] searchTransaction method") + return Mono.just(SearchTransactionResponseDto()) + } +} From 323ba76684c345d3b423c61a1690ae820a3c903e Mon Sep 17 00:00:00 2001 From: Fernando-Granato Date: Thu, 3 Aug 2023 10:57:17 +0200 Subject: [PATCH 07/11] feat(dockerfile): fixed dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b5e6da0..4748e6b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ COPY gradle.properties . COPY eclipse-style.xml eclipse-style.xml COPY src src -#COPY api-spec api-spec +COPY api-spec api-spec RUN ./gradlew build -x test RUN mkdir build/extracted && java -Djarmode=layertools -jar build/libs/*.jar extract --destination build/extracted From 023e42eb2e2f881a51c5214a06266a7e76143d9b Mon Sep 17 00:00:00 2001 From: Pietro Tota Date: Thu, 3 Aug 2023 11:36:08 +0200 Subject: [PATCH 08/11] feat(open-api): add api for helpdesk --- api-spec/openapi.yaml | 136 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 135 insertions(+), 1 deletion(-) diff --git a/api-spec/openapi.yaml b/api-spec/openapi.yaml index 5a06a76..892a496 100644 --- a/api-spec/openapi.yaml +++ b/api-spec/openapi.yaml @@ -16,6 +16,12 @@ tags: externalDocs: url: TODO description: Technical specifications + - name: helpDesk + description: Api's for performing transaction search on ecommerce DB + externalDocs: + url: TODO + description: Technical specifications + paths: /pm/searchTransaction: post: @@ -111,6 +117,53 @@ paths: application/json: schema: $ref: '#/components/schemas/ProblemJson' + /helpdesk/searchTransaction: + post: + parameters: + - in: query + name: pageNumber + schema: + type: integer + required: true + description: "Searched page number" + - in: query + name: pageSize + schema: + type: integer + required: true + description: "Max element per page" + tags: + - helpDesk + operationId: helpDeskSearchTransaction + summary: Search transaction by input parmeters + description: 'GET with body payload - no resources created' + requestBody: + $ref: "#/components/requestBodies/SearchTransactionRequest" + responses: + '200': + description: Transactions found + content: + application/json: + schema: + $ref: '#/components/schemas/SearchTransactionResponse' + '400': + description: Formally invalid input + content: + application/json: + schema: + $ref: '#/components/schemas/ProblemJson' + '404': + description: Transaction not found + content: + application/json: + schema: + $ref: '#/components/schemas/ProblemJson' + '500': + description: Internal server error + content: + application/json: + schema: + $ref: '#/components/schemas/ProblemJson' components: schemas: ProblemJson: @@ -338,6 +391,28 @@ components: type: integer minimum: 0 maximum: 99999999 + PmSearchTransactionRequest: + type: object + oneOf: + - $ref: '#/components/schemas/PmSearchTransactionRequestFiscalCode' + - $ref: '#/components/schemas/PmSearchTransactionRequestEmail' + discriminator: + propertyName: type + mapping: + USER_FISCAL_CODE: "#/components/schemas/PmSearchTransactionRequestFiscalCode" + USER_EMAIL: "#/components/schemas/PmSearchTransactionRequestEmail" + EcommerceSearchTransactionRequest: + type: object + oneOf: + - $ref: '#/components/schemas/EcommerceSearchTransactionRequestRptId' + - $ref: '#/components/schemas/EcommerceSearchTransactionRequestPaymentToken' + - $ref: '#/components/schemas/EcommerceSearchTransactionRequestTransactionId' + discriminator: + propertyName: type + mapping: + RPT_ID: "#/components/schemas/EcommerceSearchTransactionRequestRptId" + PAYMENT_TOKEN: "#/components/schemas/EcommerceSearchTransactionRequestPaymentToken" + TRANSACTION_ID: "#/components/schemas/EcommerceSearchTransactionRequestTransactionId" requestBodies: PmSearchTransactionRequest: required: true @@ -352,6 +427,15 @@ components: mapping: USER_FISCAL_CODE: "#/components/schemas/PmSearchTransactionRequestFiscalCode" USER_EMAIL: "#/components/schemas/PmSearchTransactionRequestEmail" + examples: + search by user fiscal code: + value: + type: USER_FISCAL_CODE + userFiscalCode: "user_fiscal_code" + search by user email: + value: + type: USER_EMAIL + userEmail: "test@test.it" PmSearchTransactionResponse: required: true content: @@ -373,9 +457,59 @@ components: RPT_ID: "#/components/schemas/EcommerceSearchTransactionRequestRptId" PAYMENT_TOKEN: "#/components/schemas/EcommerceSearchTransactionRequestPaymentToken" TRANSACTION_ID: "#/components/schemas/EcommerceSearchTransactionRequestTransactionId" + examples: + search by rpt id: + value: + type: RPT_ID + rptId: "77777777777111111111111111111" + search by payment token: + value: + type: PAYMENT_TOKEN + paymentToken: "paymentToken" + search by transaction id: + value: + type: TRANSACTION_ID + transactionId: "transactionId" EcommerceSearchTransactionResponse: required: true content: application/json: schema: - $ref: '#/components/schemas/SearchTransactionResponse' \ No newline at end of file + $ref: '#/components/schemas/SearchTransactionResponse' + SearchTransactionRequest: + required: true + content: + application/json: + schema: + oneOf: + - $ref: '#/components/schemas/PmSearchTransactionRequest' + - $ref: '#/components/schemas/EcommerceSearchTransactionRequest' + discriminator: + propertyName: type + mapping: + USER_FISCAL_CODE: "#/components/schemas/PmSearchTransactionRequestFiscalCode" + USER_EMAIL: "#/components/schemas/PmSearchTransactionRequestEmail" + RPT_ID: "#/components/schemas/EcommerceSearchTransactionRequestRptId" + PAYMENT_TOKEN: "#/components/schemas/EcommerceSearchTransactionRequestPaymentToken" + TRANSACTION_ID: "#/components/schemas/EcommerceSearchTransactionRequestTransactionId" + examples: + search by user fiscal code: + value: + type: USER_FISCAL_CODE + userFiscalCode: "user_fiscal_code" + search by user email: + value: + type: USER_EMAIL + userEmail: "test@test.it" + search by rpt id: + value: + type: RPT_ID + rptId: "77777777777111111111111111111" + search by payment token: + value: + type: PAYMENT_TOKEN + paymentToken: "paymentToken" + search by transaction id: + value: + type: TRANSACTION_ID + transactionId: "transactionId" \ No newline at end of file From e4d63cf23d6153fd57c46edc912b616e12db0373 Mon Sep 17 00:00:00 2001 From: Pietro Tota Date: Thu, 3 Aug 2023 11:50:40 +0200 Subject: [PATCH 09/11] feat(controllers): add controller for help desk api --- .../controllers/EcommerceController.kt | 13 ++--- .../controllers/HelpdeskController.kt | 46 ++++++++++++++++++ .../helpdesk/controllers/PmController.kt | 13 ++--- .../helpdesk/services/EcommerceService.kt | 47 ++++++++++++++++--- .../ecommerce/helpdesk/services/PmService.kt | 47 ++++++++++++++++--- 5 files changed, 138 insertions(+), 28 deletions(-) create mode 100644 src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/HelpdeskController.kt diff --git a/src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/EcommerceController.kt b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/EcommerceController.kt index 1391944..d8eed35 100644 --- a/src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/EcommerceController.kt +++ b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/EcommerceController.kt @@ -12,17 +12,14 @@ import org.springframework.web.server.ServerWebExchange import reactor.core.publisher.Mono @RestController -class EcommerceController : EcommerceApi { - - @Autowired private lateinit var ecommerceService: EcommerceService - +class EcommerceController(@Autowired val ecommerceService: EcommerceService) : EcommerceApi { private val logger = LoggerFactory.getLogger(this.javaClass) override fun ecommerceSearchTransaction( - pageNumber: Int?, - pageSize: Int?, - ecommerceSearchTransactionRequestDto: Mono?, - exchange: ServerWebExchange? + pageNumber: Int, + pageSize: Int, + ecommerceSearchTransactionRequestDto: Mono, + exchange: ServerWebExchange ): Mono> { logger.info("[HelpDesk controller] ecommerceSearchTransaction") return ecommerceService diff --git a/src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/HelpdeskController.kt b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/HelpdeskController.kt new file mode 100644 index 0000000..08e053b --- /dev/null +++ b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/HelpdeskController.kt @@ -0,0 +1,46 @@ +package it.pagopa.ecommerce.helpdesk.controllers + +import it.pagopa.ecommerce.helpdesk.services.EcommerceService +import it.pagopa.ecommerce.helpdesk.services.PmService +import it.pagopa.generated.ecommerce.helpdesk.api.HelpdeskApi +import it.pagopa.generated.ecommerce.helpdesk.model.* +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.RestController +import org.springframework.web.server.ServerWebExchange +import reactor.core.publisher.Mono + +@RestController +class HelpdeskController( + @Autowired val ecommerceService: EcommerceService, + @Autowired val pmService: PmService +) : HelpdeskApi { + + override fun helpDeskSearchTransaction( + pageNumber: Int, + pageSize: Int, + helpDeskSearchTransactionRequestDto: Mono, + exchange: ServerWebExchange + ): Mono> = + helpDeskSearchTransactionRequestDto.flatMap { + when (it) { + is EcommerceSearchTransactionRequestDto -> + ecommerceService + .searchTransaction( + pageNumber = pageNumber, + pageSize = pageSize, + ecommerceSearchTransactionRequestDto = Mono.just(it) + ) + .map { response -> ResponseEntity.ok(response) } + is PmSearchTransactionRequestDto -> + pmService + .searchTransaction( + pageNumber = pageNumber, + pageSize = pageSize, + pmSearchTransactionRequestDto = Mono.just(it) + ) + .map { response -> ResponseEntity.ok(response) } + else -> Mono.error(RuntimeException("Unknown search criteria")) + } + } +} diff --git a/src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/PmController.kt b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/PmController.kt index 09e0b98..c0ff26b 100644 --- a/src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/PmController.kt +++ b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/controllers/PmController.kt @@ -12,17 +12,14 @@ import org.springframework.web.server.ServerWebExchange import reactor.core.publisher.Mono @RestController -class PmController : PmApi { - - @Autowired private lateinit var pmService: PmService - +class PmController(@Autowired val pmService: PmService) : PmApi { private val logger = LoggerFactory.getLogger(this.javaClass) override fun pmSearchTransaction( - pageNumber: Int?, - pageSize: Int?, - pmSearchTransactionRequestDto: Mono?, - exchange: ServerWebExchange? + pageNumber: Int, + pageSize: Int, + pmSearchTransactionRequestDto: Mono, + exchange: ServerWebExchange ): Mono> { logger.info("[HelpDesk controller] pmSearchTransaction") return pmService diff --git a/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/EcommerceService.kt b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/EcommerceService.kt index c212f20..09c714b 100644 --- a/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/EcommerceService.kt +++ b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/EcommerceService.kt @@ -1,7 +1,7 @@ package it.pagopa.ecommerce.helpdesk.services -import it.pagopa.generated.ecommerce.helpdesk.model.EcommerceSearchTransactionRequestDto -import it.pagopa.generated.ecommerce.helpdesk.model.SearchTransactionResponseDto +import it.pagopa.generated.ecommerce.helpdesk.model.* +import java.time.OffsetDateTime import org.slf4j.LoggerFactory import org.springframework.stereotype.Service import reactor.core.publisher.Mono @@ -12,11 +12,46 @@ class EcommerceService { private val logger = LoggerFactory.getLogger(javaClass) fun searchTransaction( - pageNumber: Int?, - pageSize: Int?, - ecommerceSearchTransactionRequestDto: Mono? + pageNumber: Int, + pageSize: Int, + ecommerceSearchTransactionRequestDto: Mono ): Mono { logger.info("[helpDesk ecommerce service] searchTransaction method") - return Mono.just(SearchTransactionResponseDto()) + return ecommerceSearchTransactionRequestDto + .doOnNext { logger.info("Search type: ${it.type}") } + .map { + SearchTransactionResponseDto() + .totalTransactionCount(1) + .transactions( + listOf( + TransactionResultDto() + .transactionInfo( + TransactionInfoDto() + .amount(100) + .fee(100) + .creationDate(OffsetDateTime.now()) + .status("TEST") + .grandTotal(200) + ) + .paymentDetailInfo( + PaymentDetailInfoDto() + .paymentContextCode("paymentContextCode") + .amount(100) + .iuv("IUV") + .creditorInstitution("creditor institution") + .paFiscalCode("77777777777") + ) + .paymentInfo( + PaymentInfoDto().amount(100).origin("origin").subject("subject") + ) + .pspInfo( + PspInfoDto() + .pspId("pspId") + .businessName("business name") + .idChannel("id channel") + ) + ) + ) + } } } diff --git a/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/PmService.kt b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/PmService.kt index a23984e..cac258a 100644 --- a/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/PmService.kt +++ b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/PmService.kt @@ -1,7 +1,7 @@ package it.pagopa.ecommerce.helpdesk.services -import it.pagopa.generated.ecommerce.helpdesk.model.PmSearchTransactionRequestDto -import it.pagopa.generated.ecommerce.helpdesk.model.SearchTransactionResponseDto +import it.pagopa.generated.ecommerce.helpdesk.model.* +import java.time.OffsetDateTime import org.slf4j.LoggerFactory import org.springframework.stereotype.Service import reactor.core.publisher.Mono @@ -12,11 +12,46 @@ class PmService { private val logger = LoggerFactory.getLogger(javaClass) fun searchTransaction( - pageNumber: Int?, - pageSize: Int?, - pmSearchTransactionRequestDto: Mono? + pageNumber: Int, + pageSize: Int, + pmSearchTransactionRequestDto: Mono ): Mono { logger.info("[helpDesk pm service] searchTransaction method") - return Mono.just(SearchTransactionResponseDto()) + return pmSearchTransactionRequestDto + .doOnNext { logger.info("Search type: ${it.type}") } + .map { + SearchTransactionResponseDto() + .totalTransactionCount(1) + .transactions( + listOf( + TransactionResultDto() + .transactionInfo( + TransactionInfoDto() + .amount(100) + .fee(100) + .creationDate(OffsetDateTime.now()) + .status("TEST") + .grandTotal(200) + ) + .paymentDetailInfo( + PaymentDetailInfoDto() + .paymentContextCode("paymentContextCode") + .amount(100) + .iuv("IUV") + .creditorInstitution("creditor institution") + .paFiscalCode("77777777777") + ) + .paymentInfo( + PaymentInfoDto().amount(100).origin("origin").subject("subject") + ) + .pspInfo( + PspInfoDto() + .pspId("pspId") + .businessName("business name") + .idChannel("id channel") + ) + ) + ) + } } } From ea87ea54562639a17f65f6ec3c1fedbbf3065878 Mon Sep 17 00:00:00 2001 From: Pietro Tota Date: Thu, 3 Aug 2023 13:02:52 +0200 Subject: [PATCH 10/11] feat(open-api): add default values for pagination parameters --- api-spec/openapi.yaml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/api-spec/openapi.yaml b/api-spec/openapi.yaml index 892a496..4e28cce 100644 --- a/api-spec/openapi.yaml +++ b/api-spec/openapi.yaml @@ -30,12 +30,14 @@ paths: name: pageNumber schema: type: integer + default: 0 required: true - description: "Searched page number" + description: "Searched page number, starting from 0" - in: query name: pageSize schema: type: integer + default: 10 required: true description: "Max element per page" tags: @@ -77,12 +79,14 @@ paths: name: pageNumber schema: type: integer + default: 0 required: true - description: "Searched page number" + description: "Searched page number, starting from 0" - in: query name: pageSize schema: type: integer + default: 10 required: true description: "Max element per page" tags: @@ -124,12 +128,14 @@ paths: name: pageNumber schema: type: integer + default: 0 required: true - description: "Searched page number" + description: "Searched page number, starting from 0" - in: query name: pageSize schema: type: integer + default: 10 required: true description: "Max element per page" tags: From 8b496f44ca22cb721effafe73d9a3e582970aa7f Mon Sep 17 00:00:00 2001 From: Pietro Tota Date: Thu, 3 Aug 2023 13:32:52 +0200 Subject: [PATCH 11/11] feat(open-api): add page details into response --- api-spec/openapi.yaml | 30 +++++++++- .../helpdesk/services/EcommerceService.kt | 57 ++++++++++++++++++- .../ecommerce/helpdesk/services/PmService.kt | 57 ++++++++++++++++++- 3 files changed, 139 insertions(+), 5 deletions(-) diff --git a/api-spec/openapi.yaml b/api-spec/openapi.yaml index 4e28cce..6df8121 100644 --- a/api-spec/openapi.yaml +++ b/api-spec/openapi.yaml @@ -253,11 +253,11 @@ components: type: array items: $ref: '#/components/schemas/TransactionResult' - totalTransactionCount: - type: integer + page: + $ref: '#/components/schemas/PageInfo' required: - transactions - - totalTransactionCount + - page EcommerceSearchTransactionRequestRptId: type: object description: Search transaction by user fiscal code @@ -315,11 +315,14 @@ components: $ref: '#/components/schemas/PaymentDetailInfo' pspInfo: $ref: '#/components/schemas/PspInfo' + product: + $ref: '#/components/schemas/Product' required: - transactionInfo - paymentInfo - paymentDetailInfo - pspInfo + - product TransactionInfo: type: object description: TransactionResponse @@ -397,6 +400,27 @@ components: type: integer minimum: 0 maximum: 99999999 + PageInfo: + description: Informations about the returned query page + type: object + properties: + current: + type: integer + description: Current returned page index (0-based) + total: + type: integer + description: Total pages for the query (based on requested page size) + results: + type: integer + description: Transactions returned into the current page + required: + - current + - results + - total + Product: + type: string + enum: ["PM", "ECOMMERCE"] + description: Product from which transaction belongs PmSearchTransactionRequest: type: object oneOf: diff --git a/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/EcommerceService.kt b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/EcommerceService.kt index 09c714b..21dc39b 100644 --- a/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/EcommerceService.kt +++ b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/EcommerceService.kt @@ -21,10 +21,65 @@ class EcommerceService { .doOnNext { logger.info("Search type: ${it.type}") } .map { SearchTransactionResponseDto() - .totalTransactionCount(1) + .page(PageInfoDto().current(0).results(3).total(1)) .transactions( listOf( TransactionResultDto() + .product(ProductDto.ECOMMERCE) + .transactionInfo( + TransactionInfoDto() + .amount(100) + .fee(100) + .creationDate(OffsetDateTime.now()) + .status("TEST") + .grandTotal(200) + ) + .paymentDetailInfo( + PaymentDetailInfoDto() + .paymentContextCode("paymentContextCode") + .amount(100) + .iuv("IUV") + .creditorInstitution("creditor institution") + .paFiscalCode("77777777777") + ) + .paymentInfo( + PaymentInfoDto().amount(100).origin("origin").subject("subject") + ) + .pspInfo( + PspInfoDto() + .pspId("pspId") + .businessName("business name") + .idChannel("id channel") + ), + TransactionResultDto() + .product(ProductDto.ECOMMERCE) + .transactionInfo( + TransactionInfoDto() + .amount(100) + .fee(100) + .creationDate(OffsetDateTime.now()) + .status("TEST") + .grandTotal(200) + ) + .paymentDetailInfo( + PaymentDetailInfoDto() + .paymentContextCode("paymentContextCode") + .amount(100) + .iuv("IUV") + .creditorInstitution("creditor institution") + .paFiscalCode("77777777777") + ) + .paymentInfo( + PaymentInfoDto().amount(100).origin("origin").subject("subject") + ) + .pspInfo( + PspInfoDto() + .pspId("pspId") + .businessName("business name") + .idChannel("id channel") + ), + TransactionResultDto() + .product(ProductDto.ECOMMERCE) .transactionInfo( TransactionInfoDto() .amount(100) diff --git a/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/PmService.kt b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/PmService.kt index cac258a..aebf1a4 100644 --- a/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/PmService.kt +++ b/src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/PmService.kt @@ -21,10 +21,65 @@ class PmService { .doOnNext { logger.info("Search type: ${it.type}") } .map { SearchTransactionResponseDto() - .totalTransactionCount(1) + .page(PageInfoDto().current(0).results(3).total(1)) .transactions( listOf( TransactionResultDto() + .product(ProductDto.PM) + .transactionInfo( + TransactionInfoDto() + .amount(100) + .fee(100) + .creationDate(OffsetDateTime.now()) + .status("TEST") + .grandTotal(200) + ) + .paymentDetailInfo( + PaymentDetailInfoDto() + .paymentContextCode("paymentContextCode") + .amount(100) + .iuv("IUV") + .creditorInstitution("creditor institution") + .paFiscalCode("77777777777") + ) + .paymentInfo( + PaymentInfoDto().amount(100).origin("origin").subject("subject") + ) + .pspInfo( + PspInfoDto() + .pspId("pspId") + .businessName("business name") + .idChannel("id channel") + ), + TransactionResultDto() + .product(ProductDto.PM) + .transactionInfo( + TransactionInfoDto() + .amount(100) + .fee(100) + .creationDate(OffsetDateTime.now()) + .status("TEST") + .grandTotal(200) + ) + .paymentDetailInfo( + PaymentDetailInfoDto() + .paymentContextCode("paymentContextCode") + .amount(100) + .iuv("IUV") + .creditorInstitution("creditor institution") + .paFiscalCode("77777777777") + ) + .paymentInfo( + PaymentInfoDto().amount(100).origin("origin").subject("subject") + ) + .pspInfo( + PspInfoDto() + .pspId("pspId") + .businessName("business name") + .idChannel("id channel") + ), + TransactionResultDto() + .product(ProductDto.PM) .transactionInfo( TransactionInfoDto() .amount(100)