From 7b24ac738864c8ffdf72d3dbe2887b8d4221b832 Mon Sep 17 00:00:00 2001 From: alexanderkurash Date: Fri, 16 Feb 2024 13:40:38 +0200 Subject: [PATCH] MODTLR-19 Add schema, mapping --- .../org/folio/client/feign/DcbClient.java | 9 ++++-- src/main/resources/swagger.api/ecs-tlr.yaml | 2 ++ .../schemas/transactionStatusResponse.yaml | 4 +++ .../java/org/folio/client/DcbClientTest.java | 28 +++++++++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/swagger.api/schemas/transactionStatusResponse.yaml diff --git a/src/main/java/org/folio/client/feign/DcbClient.java b/src/main/java/org/folio/client/feign/DcbClient.java index 55a6a1b4..552dd453 100644 --- a/src/main/java/org/folio/client/feign/DcbClient.java +++ b/src/main/java/org/folio/client/feign/DcbClient.java @@ -2,9 +2,13 @@ import org.folio.domain.dto.DcbTransaction; import org.folio.domain.dto.TransactionStatus; +import org.folio.domain.dto.TransactionStatusResponse; import org.folio.spring.config.FeignClientConfiguration; import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; @FeignClient(name = "dcb", url = "${folio.okapi-url}", configuration = FeignClientConfiguration.class) public interface DcbClient { @@ -12,7 +16,8 @@ public interface DcbClient { @PostMapping("/ecs-tlr-transactions") DcbTransaction createDcbTransaction(DcbTransaction dcbTransaction); - @PostMapping("/transactions") - DcbTransaction changeDcbTransactionStatus(String transactionId, TransactionStatus newStatus); + @PutMapping("/transactions/{dcbTransactionId}/status") + TransactionStatusResponse changeDcbTransactionStatus(@PathVariable String dcbTransactionId, + @RequestBody TransactionStatus newStatus); } diff --git a/src/main/resources/swagger.api/ecs-tlr.yaml b/src/main/resources/swagger.api/ecs-tlr.yaml index 02cc7153..83a1d7be 100644 --- a/src/main/resources/swagger.api/ecs-tlr.yaml +++ b/src/main/resources/swagger.api/ecs-tlr.yaml @@ -77,6 +77,8 @@ components: $ref: 'schemas/dcbTransaction.yaml#/DcbTransaction' transactionStatus: $ref: 'schemas/transactionStatus.yaml#/TransactionStatus' + transactionStatusResponse: + $ref: 'schemas/transactionStatusResponse.yaml#/TransactionStatusResponse' errorResponse: $ref: 'schemas/errors.json' request: diff --git a/src/main/resources/swagger.api/schemas/transactionStatusResponse.yaml b/src/main/resources/swagger.api/schemas/transactionStatusResponse.yaml new file mode 100644 index 00000000..84941250 --- /dev/null +++ b/src/main/resources/swagger.api/schemas/transactionStatusResponse.yaml @@ -0,0 +1,4 @@ +TransactionStatusResponse: + allOf: + - $ref: 'transactionStatus.yaml#/TransactionStatus' + - $ref: 'dcbTransaction.yaml#/DcbTransaction' diff --git a/src/test/java/org/folio/client/DcbClientTest.java b/src/test/java/org/folio/client/DcbClientTest.java index 8fe91fbf..7c7766ab 100644 --- a/src/test/java/org/folio/client/DcbClientTest.java +++ b/src/test/java/org/folio/client/DcbClientTest.java @@ -8,6 +8,8 @@ import org.folio.client.feign.DcbClient; import org.folio.domain.dto.DcbTransaction; +import org.folio.domain.dto.TransactionStatus; +import org.folio.domain.dto.TransactionStatusResponse; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -30,4 +32,30 @@ void canCreateDcbTransaction() { assertEquals(response.getRole(), DcbTransaction.RoleEnum.BORROWER); assertEquals(response.getRequestId(), requestId); } + + @Test + void canChangeDcbTransactionStatus() { + String requestId = UUID.randomUUID().toString(); + String transactionId = UUID.randomUUID().toString(); + TransactionStatus initialStatus = new TransactionStatus() + .status(TransactionStatus.StatusEnum.AWAITING_PICKUP); + TransactionStatus targetStatus = new TransactionStatus() + .status(TransactionStatus.StatusEnum.CANCELLED) + .message("test message"); + DcbTransaction dcbTransaction = new DcbTransaction() + .role(DcbTransaction.RoleEnum.BORROWER) + .requestId(requestId); + TransactionStatusResponse transactionStatusResponse = new TransactionStatusResponse() + .status(TransactionStatusResponse.StatusEnum.CANCELLED) + .message("test message") + .item(dcbTransaction.getItem()) + .patron(dcbTransaction.getPatron()) + .pickup(dcbTransaction.getPickup()) + .requestId(requestId); + when(dcbClient.changeDcbTransactionStatus(transactionId, targetStatus)) + .thenReturn(transactionStatusResponse); + var response = dcbClient.changeDcbTransactionStatus(transactionId, targetStatus); + assertNotNull(response); + assertEquals(response.getStatus(), TransactionStatusResponse.StatusEnum.CANCELLED); + } }