Skip to content

Commit

Permalink
feat: Updated lastUpdate after cancelTransaction [MCIL-101, MCIL-102,…
Browse files Browse the repository at this point in the history
… MCIL-103] (#37)
  • Loading branch information
RiccardoGiuliani committed Apr 5, 2024
1 parent dac97e6 commit 1be5421
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -118,10 +121,14 @@ public Uni<Response> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -353,7 +357,7 @@ protected IdpayTransactionEntity updateIdpayTransactionEntity(CommonHeader heade
return trEntity;
}

public Uni<Void> cancelTransaction(CommonHeader headers, String transactionId) {
public Uni<Transaction> cancelTransaction(CommonHeader headers, String transactionId) {

Log.debugf("TransactionsService -> cancelTransaction - Input parameters: %s, %s", headers, transactionId);

Expand Down Expand Up @@ -394,7 +398,7 @@ public Uni<Void> cancelTransaction(CommonHeader headers, String transactionId) {

return updEntity;
})
.chain(() -> Uni.createFrom().voidItem());
.chain(result -> Uni.createFrom().item(createTransactionFromIdpayTransactionEntity(result, null, null, false)));
})
);
});
Expand Down
14 changes: 12 additions & 2 deletions src/main/resources/META-INF/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ void deleteTransactionTest_OKAborted() {
.extract()
.response();

Assertions.assertEquals(204, response.statusCode());
Assertions.assertEquals(200, response.statusCode());

}

Expand Down Expand Up @@ -788,7 +788,7 @@ void deleteTransactionTest_OKCancelled() {
.response();

syncTrxStatus.setStatus(TransactionStatus.CREATED);
Assertions.assertEquals(204, response.statusCode());
Assertions.assertEquals(200, response.statusCode());

}

Expand Down Expand Up @@ -999,7 +999,7 @@ void deleteTransactionTest_KOUpdate() {
.extract()
.response();

Assertions.assertEquals(204, response.statusCode());
Assertions.assertEquals(200, response.statusCode());

}

Expand Down Expand Up @@ -1081,7 +1081,7 @@ void deleteTransactionTest_KOCertAndOK_Aborted() {
.extract()
.response();

Assertions.assertEquals(204, response.statusCode());
Assertions.assertEquals(200, response.statusCode());

}

Expand Down
4 changes: 2 additions & 2 deletions src/test/postman/postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 1be5421

Please sign in to comment.