Skip to content

Commit

Permalink
CIRC-2111 Fix delete method
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkurash committed Jun 19, 2024
1 parent 6fa6d43 commit 7744cf3
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.folio.circulation.resources;

import static org.folio.circulation.infrastructure.storage.CirculationSettingsRepository.RECORDS_PROPERTY_NAME;
import static org.folio.circulation.support.json.JsonPropertyFetcher.getProperty;
import static org.folio.circulation.support.results.MappingFunctions.toFixedValue;

import java.lang.invoke.MethodHandles;
import java.util.UUID;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -15,6 +17,7 @@
import org.folio.circulation.support.http.server.WebContext;

import io.vertx.core.http.HttpClient;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;

public class CirculationSettingsResource extends CollectionResource {
Expand All @@ -31,7 +34,9 @@ void create(RoutingContext routingContext) {
final var circulationSettingsRepository = new CirculationSettingsRepository(clients);

final var incomingRepresentation = routingContext.body().asJsonObject();
setRandomIdIfMissing(incomingRepresentation);
final var circulationSetting = CirculationSetting.from(incomingRepresentation);
log.debug("replace:: Creating circulation setting: {}", circulationSetting);

circulationSettingsRepository.create(circulationSetting)
.thenApply(r -> r.map(CirculationSetting::getRepresentation))
Expand All @@ -47,6 +52,7 @@ void replace(RoutingContext routingContext) {

final var incomingRepresentation = routingContext.body().asJsonObject();
final var circulationSetting = CirculationSetting.from(incomingRepresentation);
log.debug("replace:: Replacing circulation setting : {}", circulationSetting);

circulationSettingsRepository.update(circulationSetting)
.thenApply(r -> r.map(CirculationSetting::getRepresentation))
Expand Down Expand Up @@ -75,8 +81,9 @@ void delete(RoutingContext routingContext) {
final var clients = Clients.create(context, client);

String id = routingContext.request().getParam("id");
log.debug("delete:: Deleting circulation setting ID: {}", id);

clients.loansStorage().delete(id)
clients.circulationSettingsStorageClient().delete(id)
.thenApply(r -> r.map(toFixedValue(NoContentResponse::noContent)))
.thenAccept(context::writeResultToHttpResponse);
}
Expand Down Expand Up @@ -106,4 +113,11 @@ void empty(RoutingContext routingContext) {
.thenApply(r -> r.map(toFixedValue(NoContentResponse::noContent)))
.thenAccept(context::writeResultToHttpResponse);
}

private void setRandomIdIfMissing(JsonObject representation) {
final var providedId = getProperty(representation, "id");
if (providedId == null) {
representation.put("id", UUID.randomUUID().toString());
}
}
}

0 comments on commit 7744cf3

Please sign in to comment.