diff --git a/src/main/java/it/pagopa/swclient/mil/idpay/resource/TransactionsResource.java b/src/main/java/it/pagopa/swclient/mil/idpay/resource/TransactionsResource.java index 451c59e..eb181b6 100644 --- a/src/main/java/it/pagopa/swclient/mil/idpay/resource/TransactionsResource.java +++ b/src/main/java/it/pagopa/swclient/mil/idpay/resource/TransactionsResource.java @@ -10,7 +10,6 @@ import it.pagopa.swclient.mil.idpay.bean.VerifyCie; import it.pagopa.swclient.mil.idpay.service.TransactionsService; import jakarta.annotation.security.RolesAllowed; -import jakarta.inject.Inject; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Pattern; @@ -24,8 +23,12 @@ @Path("/transactions") public class TransactionsResource { - @Inject - TransactionsService transactionsService; + + private final TransactionsService transactionsService; + + public TransactionsResource(TransactionsService transactionsService) { + this.transactionsService = transactionsService; + } /** * The value of the Max-Retries header to be sent in response to the createTransaction API @@ -118,10 +121,14 @@ public Uni cancelTransaction(@Valid @BeanParam CommonHeader headers, */ AcqMerchMapper.map(headers); - return transactionsService.cancelTransaction(headers, transactionId).chain(() -> - Uni.createFrom().item( - Response.status(Status.NO_CONTENT).build()) - ); + return transactionsService.cancelTransaction(headers, transactionId).chain(res -> { + Log.debugf("TransactionsResource -> TransactionsService -> cancelTransaction - Response %s", res); + + return Uni.createFrom().item( + Response.status(Response.Status.OK) + .entity(res) + .build()); + }); } private URI getTransactionURI(String milTransactionId) { diff --git a/src/main/java/it/pagopa/swclient/mil/idpay/service/TransactionsService.java b/src/main/java/it/pagopa/swclient/mil/idpay/service/TransactionsService.java index e334f09..c0b37f2 100644 --- a/src/main/java/it/pagopa/swclient/mil/idpay/service/TransactionsService.java +++ b/src/main/java/it/pagopa/swclient/mil/idpay/service/TransactionsService.java @@ -25,7 +25,10 @@ import it.pagopa.swclient.mil.idpay.dao.IdpayTransactionEntity; import it.pagopa.swclient.mil.idpay.dao.IdpayTransactionRepository; import jakarta.enterprise.context.ApplicationScoped; -import jakarta.ws.rs.*; +import jakarta.ws.rs.BadRequestException; +import jakarta.ws.rs.InternalServerErrorException; +import jakarta.ws.rs.NotFoundException; +import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.core.Response; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.eclipse.microprofile.rest.client.inject.RestClient; @@ -275,6 +278,7 @@ protected Transaction createTransactionFromIdpayTransactionEntity(IdpayTransacti transaction.setCoveredAmount(entity.idpayTransaction.getCoveredAmount()); transaction.setStatus(entity.idpayTransaction.getStatus()); transaction.setSecondFactor(secondFactor); + transaction.setLastUpdate(entity.idpayTransaction.getLastUpdate()); return transaction; } @@ -353,7 +357,7 @@ protected IdpayTransactionEntity updateIdpayTransactionEntity(CommonHeader heade return trEntity; } - public Uni cancelTransaction(CommonHeader headers, String transactionId) { + public Uni cancelTransaction(CommonHeader headers, String transactionId) { Log.debugf("TransactionsService -> cancelTransaction - Input parameters: %s, %s", headers, transactionId); @@ -394,7 +398,7 @@ public Uni cancelTransaction(CommonHeader headers, String transactionId) { return updEntity; }) - .chain(() -> Uni.createFrom().voidItem()); + .chain(result -> Uni.createFrom().item(createTransactionFromIdpayTransactionEntity(result, null, null, false))); }) ); }); diff --git a/src/main/resources/META-INF/openapi.yaml b/src/main/resources/META-INF/openapi.yaml index e960e5a..100a7c4 100644 --- a/src/main/resources/META-INF/openapi.yaml +++ b/src/main/resources/META-INF/openapi.yaml @@ -162,8 +162,8 @@ paths: operationId: cancelTransaction summary: Cancels an IDPay transaction responses: - "204": - description: Transaction cancelled successfully + "200": + $ref: '#/components/responses/Transaction' "400": $ref: '#/components/responses/Error' "401": @@ -511,6 +511,13 @@ components: type: string pattern: "^[0-9a-zA-Z]{8}$" example: "12345678" + + TransactionLastUpdate: + description: Timestamp of last update of the transaction + type: string + format: date-time + maxLength: 19 + example: "2024-04-04T12:45:33" TransactionLocation: description: URL of the transaction @@ -752,6 +759,8 @@ components: $ref: '#/components/schemas/InitiativeId' timestamp: $ref: '#/components/schemas/TransactionTimestamp' + lastUpdate: + $ref: '#/components/schemas/TransactionLastUpdate' goodsCost: $ref: '#/components/schemas/GoodsCost' trxCode: @@ -775,6 +784,7 @@ components: milTransactionId: "ccadc1c4-3913-431e-a569-6cf2ce60946c" initiativeId: "649c50b5a03f655e6543af06" timestamp: "2023-09-11T12:45:33" + lastUpdate: "2024-04-04T15:18:25" goodsCost: 50054 trxCode: "rwkmek1x" coveredAmount: 10012 diff --git a/src/test/java/it/pagopa/swclient/mil/idpay/TransactionsResourceTest.java b/src/test/java/it/pagopa/swclient/mil/idpay/TransactionsResourceTest.java index 1e3f9f7..0b270e9 100644 --- a/src/test/java/it/pagopa/swclient/mil/idpay/TransactionsResourceTest.java +++ b/src/test/java/it/pagopa/swclient/mil/idpay/TransactionsResourceTest.java @@ -744,7 +744,7 @@ void deleteTransactionTest_OKAborted() { .extract() .response(); - Assertions.assertEquals(204, response.statusCode()); + Assertions.assertEquals(200, response.statusCode()); } @@ -788,7 +788,7 @@ void deleteTransactionTest_OKCancelled() { .response(); syncTrxStatus.setStatus(TransactionStatus.CREATED); - Assertions.assertEquals(204, response.statusCode()); + Assertions.assertEquals(200, response.statusCode()); } @@ -999,7 +999,7 @@ void deleteTransactionTest_KOUpdate() { .extract() .response(); - Assertions.assertEquals(204, response.statusCode()); + Assertions.assertEquals(200, response.statusCode()); } @@ -1081,7 +1081,7 @@ void deleteTransactionTest_KOCertAndOK_Aborted() { .extract() .response(); - Assertions.assertEquals(204, response.statusCode()); + Assertions.assertEquals(200, response.statusCode()); } diff --git a/src/test/postman/postman_collection.json b/src/test/postman/postman_collection.json index 02cf802..8fb7f19 100644 --- a/src/test/postman/postman_collection.json +++ b/src/test/postman/postman_collection.json @@ -1046,8 +1046,8 @@ "console.log(\"RESPONSE:\");\r", "console.log(responseBody);\r", "\r", - "pm.test(\"Status code is 204\", function () {\r", - " pm.response.to.have.status(204);\r", + "pm.test(\"Status code is 200\", function () {\r", + " pm.response.to.have.status(200);\r", "});" ], "type": "text/javascript"