diff --git a/src/main/java/org/folio/client/feign/DcbClient.java b/src/main/java/org/folio/client/feign/DcbClient.java index 9d5d52e1..868ad109 100644 --- a/src/main/java/org/folio/client/feign/DcbClient.java +++ b/src/main/java/org/folio/client/feign/DcbClient.java @@ -1,11 +1,14 @@ package org.folio.client.feign; 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.GetMapping; 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) @@ -15,4 +18,11 @@ public interface DcbClient { TransactionStatusResponse createDcbTransaction(@PathVariable String dcbTransactionId, @RequestBody DcbTransaction dcbTransaction); + @GetMapping("/transactions/{dcbTransactionId}/status") + TransactionStatusResponse getDcbTransactionStatus(@PathVariable String dcbTransactionId); + + @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 05a63f00..274ecfb9 100644 --- a/src/main/resources/swagger.api/ecs-tlr.yaml +++ b/src/main/resources/swagger.api/ecs-tlr.yaml @@ -78,7 +78,7 @@ components: transactionStatus: $ref: 'schemas/transactionStatus.yaml#/TransactionStatus' transactionStatusResponse: - $ref: 'schemas/transactionStatusResponse.yaml#/TransactionStatusResponse' + $ref: 'schemas/transactionStatusResponse.yaml#/TransactionStatusResponse' errorResponse: $ref: 'schemas/errors.json' request: diff --git a/src/test/java/org/folio/client/DcbClientTest.java b/src/test/java/org/folio/client/DcbClientTest.java index a362fcb2..fa6ec1cc 100644 --- a/src/test/java/org/folio/client/DcbClientTest.java +++ b/src/test/java/org/folio/client/DcbClientTest.java @@ -8,6 +8,7 @@ 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; @@ -40,4 +41,44 @@ void canCreateDcbTransaction() { assertEquals(TransactionStatusResponse.RoleEnum.BORROWER, response.getRole()); assertEquals(requestId, response.getRequestId()); } + + @Test + void canGetDcbTransactionStatus() { + String requestId = UUID.randomUUID().toString(); + String transactionId = UUID.randomUUID().toString(); + DcbTransaction dcbTransaction = new DcbTransaction() + .role(DcbTransaction.RoleEnum.BORROWER) + .requestId(requestId); + TransactionStatusResponse transactionStatusResponse = new TransactionStatusResponse() + .status(TransactionStatusResponse.StatusEnum.CANCELLED) + .message("test message") + .item(dcbTransaction.getItem()) + .requestId(requestId); + when(dcbClient.getDcbTransactionStatus(transactionId)).thenReturn(transactionStatusResponse); + var response = dcbClient.getDcbTransactionStatus(transactionId); + assertNotNull(response); + assertEquals(TransactionStatusResponse.StatusEnum.CANCELLED, response.getStatus()); + } + + @Test + void canChangeDcbTransactionStatus() { + String requestId = UUID.randomUUID().toString(); + String transactionId = UUID.randomUUID().toString(); + 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()) + .requestId(requestId); + when(dcbClient.changeDcbTransactionStatus(transactionId, targetStatus)) + .thenReturn(transactionStatusResponse); + var response = dcbClient.changeDcbTransactionStatus(transactionId, targetStatus); + assertNotNull(response); + assertEquals(TransactionStatusResponse.StatusEnum.CANCELLED, response.getStatus()); + } }