Search in sources :

Example 1 with ClaimItemReturnedRequest

use of org.folio.circulation.domain.ClaimItemReturnedRequest in project mod-circulation by folio-org.

the class ClaimItemReturnedResource method createRequest.

private Result<ClaimItemReturnedRequest> createRequest(RoutingContext routingContext) {
    final String loanId = routingContext.pathParam("id");
    final JsonObject body = routingContext.getBodyAsJson();
    final ClaimItemReturnedRequest request = ClaimItemReturnedRequest.from(loanId, body);
    if (request.getItemClaimedReturnedDateTime() == null) {
        return failed(singleValidationError("Item claimed returned date is a required field", ITEM_CLAIMED_RETURNED_DATE, null));
    }
    return succeeded(ClaimItemReturnedRequest.from(loanId, body));
}
Also used : ClaimItemReturnedRequest(org.folio.circulation.domain.ClaimItemReturnedRequest) JsonObject(io.vertx.core.json.JsonObject)

Example 2 with ClaimItemReturnedRequest

use of org.folio.circulation.domain.ClaimItemReturnedRequest in project mod-circulation by folio-org.

the class ClaimItemReturnedResource method processClaimItemReturned.

private CompletableFuture<Result<Loan>> processClaimItemReturned(RoutingContext routingContext, ClaimItemReturnedRequest request) {
    final Clients clients = Clients.create(new WebContext(routingContext), client);
    final var itemRepository = new ItemRepository(clients);
    final var userRepository = new UserRepository(clients);
    final var loanRepository = new LoanRepository(clients, itemRepository, userRepository);
    final ChangeItemStatusService changeItemStatusService = new ChangeItemStatusService(loanRepository, new StoreLoanAndItem(loanRepository, itemRepository));
    return changeItemStatusService.getOpenLoan(request).thenApply(loan -> declareLoanClaimedReturned(loan, request)).thenCompose(changeItemStatusService::updateLoanAndItem);
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) WebContext(org.folio.circulation.support.http.server.WebContext) Loan(org.folio.circulation.domain.Loan) Router(io.vertx.ext.web.Router) ITEM_CLAIMED_RETURNED_DATE(org.folio.circulation.domain.ClaimItemReturnedRequest.ITEM_CLAIMED_RETURNED_DATE) MappingFunctions.toFixedValue(org.folio.circulation.support.results.MappingFunctions.toFixedValue) CompletableFuture(java.util.concurrent.CompletableFuture) ValidationErrorFailure.singleValidationError(org.folio.circulation.support.ValidationErrorFailure.singleValidationError) RoutingContext(io.vertx.ext.web.RoutingContext) Result(org.folio.circulation.support.results.Result) EventPublisher(org.folio.circulation.services.EventPublisher) RouteRegistration(org.folio.circulation.support.RouteRegistration) StoreLoanAndItem(org.folio.circulation.StoreLoanAndItem) ClaimItemReturnedRequest(org.folio.circulation.domain.ClaimItemReturnedRequest) JsonObject(io.vertx.core.json.JsonObject) ChangeItemStatusService(org.folio.circulation.services.ChangeItemStatusService) Result.failed(org.folio.circulation.support.results.Result.failed) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) HttpClient(io.vertx.core.http.HttpClient) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) StoreLoanAndItem(org.folio.circulation.StoreLoanAndItem) WebContext(org.folio.circulation.support.http.server.WebContext) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) ChangeItemStatusService(org.folio.circulation.services.ChangeItemStatusService) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)2 ClaimItemReturnedRequest (org.folio.circulation.domain.ClaimItemReturnedRequest)2 HttpClient (io.vertx.core.http.HttpClient)1 Router (io.vertx.ext.web.Router)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 StoreLoanAndItem (org.folio.circulation.StoreLoanAndItem)1 ITEM_CLAIMED_RETURNED_DATE (org.folio.circulation.domain.ClaimItemReturnedRequest.ITEM_CLAIMED_RETURNED_DATE)1 Loan (org.folio.circulation.domain.Loan)1 ItemRepository (org.folio.circulation.infrastructure.storage.inventory.ItemRepository)1 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)1 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)1 ChangeItemStatusService (org.folio.circulation.services.ChangeItemStatusService)1 EventPublisher (org.folio.circulation.services.EventPublisher)1 Clients (org.folio.circulation.support.Clients)1 RouteRegistration (org.folio.circulation.support.RouteRegistration)1 ValidationErrorFailure.singleValidationError (org.folio.circulation.support.ValidationErrorFailure.singleValidationError)1 NoContentResponse (org.folio.circulation.support.http.server.NoContentResponse)1 WebContext (org.folio.circulation.support.http.server.WebContext)1 MappingFunctions.toFixedValue (org.folio.circulation.support.results.MappingFunctions.toFixedValue)1