From 33d2d5919678cda90a9f5da9a29dd485e6bbb6cc Mon Sep 17 00:00:00 2001 From: MagzhanArtykov Date: Tue, 11 Jun 2024 19:00:01 +0500 Subject: [PATCH] CIRCSTORE-509 Create CRUD API for storing circulation settings --- descriptors/ModuleDescriptor-template.json | 30 ++++++++-------- ramls/circulation-setting.json | 3 +- ramls/circulation-settings-storage.raml | 21 ++++++++---- ramls/examples/circulation-settings.json | 2 +- .../CirculationSettingsRepository.java | 1 + .../rest/impl/CirculationSettingsAPI.java | 3 ++ .../service/CirculationSettingsService.java | 34 ++++++++----------- .../topic/CirculationStorageKafkaTopic.java | 2 +- .../templates/db_scripts/schema.json | 9 +---- 9 files changed, 54 insertions(+), 51 deletions(-) diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index 2df3bfb6..0b121584 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -112,32 +112,32 @@ "methods": ["GET"], "pathPattern": "/circulation-settings-storage/circulation-settings", "permissionsRequired": [ - "circulation-settings-storage.circulation-settings.collection.get" + "circulation-storage.circulation-settings.collection.get" ] }, { "methods": ["GET"], "pathPattern": "/circulation-settings-storage/circulation-settings/{id}", "permissionsRequired": [ - "circulation-settings-storage.circulation-settings.item.get" + "circulation-storage.circulation-settings.item.get" ] }, { "methods": ["PUT"], "pathPattern": "/circulation-settings-storage/circulation-settings/{id}", "permissionsRequired": [ - "circulation-settings-storage.circulation-settings.item.put" + "circulation-storage.circulation-settings.item.put" ] }, { "methods": ["POST"], "pathPattern": "/circulation-settings-storage/circulation-settings", "permissionsRequired": [ - "circulation-settings-storage.circulation-settings.item.post" + "circulation-storage.circulation-settings.item.post" ] }, { "methods": ["DELETE"], "pathPattern": "/circulation-settings-storage/circulation-settings/{id}", "permissionsRequired": [ - "circulation-settings-storage.circulation-settings.item.delete" + "circulation-storage.circulation-settings.item.delete" ] } ] @@ -1009,27 +1009,27 @@ "description": "Get expired session patron ids collection from storage" }, { - "permissionName": "circulation-settings-storage.circulation-settings.collection.get", + "permissionName": "circulation-storage.circulation-settings.collection.get", "displayName": "Circulation storage - get circulation settings collection", "description": "Get circulation settings collection from storage" }, { - "permissionName": "circulation-settings-storage.circulation-settings.item.get", + "permissionName": "circulation-storage.circulation-settings.item.get", "displayName": "Circulation storage - get circulation setting by id", "description": "Get circulation setting by id from storage" }, { - "permissionName": "circulation-settings-storage.circulation-settings.item.post", + "permissionName": "circulation-storage.circulation-settings.item.post", "displayName": "Circulation storage - create circulation setting", "description": "Create circulation setting in storage" }, { - "permissionName": "circulation-settings-storage.circulation-settings.item.put", + "permissionName": "circulation-storage.circulation-settings.item.put", "displayName": "Circulation storage - update circulation setting by id", "description": "Update circulation setting by id" }, { - "permissionName": "circulation-settings-storage.circulation-settings.item.delete", + "permissionName": "circulation-storage.circulation-settings.item.delete", "displayName": "Circulation storage - delete circulation setting by id", "description": "Delete circulation setting by id" }, @@ -1125,11 +1125,11 @@ "checkout-lock-storage.checkout-locks.item.delete", "checkout-lock-storage.checkout-locks.item.get", "checkout-lock-storage.checkout-locks.collection.get", - "circulation-settings-storage.circulation-settings.collection.get", - "circulation-settings-storage.circulation-settings.item.get", - "circulation-settings-storage.circulation-settings.item.post", - "circulation-settings-storage.circulation-settings.item.put", - "circulation-settings-storage.circulation-settings.item.delete" + "circulation-storage.circulation-settings.collection.get", + "circulation-storage.circulation-settings.item.get", + "circulation-storage.circulation-settings.item.post", + "circulation-storage.circulation-settings.item.put", + "circulation-storage.circulation-settings.item.delete" ] }, { diff --git a/ramls/circulation-setting.json b/ramls/circulation-setting.json index 503ffa46..0907442e 100644 --- a/ramls/circulation-setting.json +++ b/ramls/circulation-setting.json @@ -6,7 +6,8 @@ "properties": { "id": { "description": "ID of the circulation setting", - "type": "string" + "type": "string", + "$ref": "raml-util/schemas/uuid.schema" }, "name": { "description": "Circulation setting name", diff --git a/ramls/circulation-settings-storage.raml b/ramls/circulation-settings-storage.raml index 6fa22d1d..7f87a73e 100644 --- a/ramls/circulation-settings-storage.raml +++ b/ramls/circulation-settings-storage.raml @@ -75,8 +75,11 @@ resourceTypes: body: application/json: type: circulation-setting - 501: - description: "Not implemented yet" + 500: + description: "Internal server error" + body: + text/plain: + example: "Internal server error" put: is: [ validate ] body: @@ -85,13 +88,19 @@ resourceTypes: responses: 204: description: "Circulation settings have been saved." - 501: - description: "Not implemented yet" + 500: + description: "Internal server error" + body: + text/plain: + example: "Internal server error" delete: is: [ validate ] responses: 204: description: "Circulation settings deleted" - 501: - description: "Not implemented yet" + 500: + description: "Internal server error" + body: + text/plain: + example: "Internal server error" diff --git a/ramls/examples/circulation-settings.json b/ramls/examples/circulation-settings.json index 4a842766..b9b7a9c8 100644 --- a/ramls/examples/circulation-settings.json +++ b/ramls/examples/circulation-settings.json @@ -8,5 +8,5 @@ } } ], - "totalRecords": 0 + "totalRecords": 1 } diff --git a/src/main/java/org/folio/persist/CirculationSettingsRepository.java b/src/main/java/org/folio/persist/CirculationSettingsRepository.java index ea1629bd..fd0f9757 100644 --- a/src/main/java/org/folio/persist/CirculationSettingsRepository.java +++ b/src/main/java/org/folio/persist/CirculationSettingsRepository.java @@ -14,6 +14,7 @@ public class CirculationSettingsRepository public CirculationSettingsRepository(Context context, Map okapiHeaders) { + super(postgresClient(context, okapiHeaders), CIRCULATION_SETTINGS_TABLE, CirculationSetting.class); } diff --git a/src/main/java/org/folio/rest/impl/CirculationSettingsAPI.java b/src/main/java/org/folio/rest/impl/CirculationSettingsAPI.java index 7ff9b35d..5e675229 100644 --- a/src/main/java/org/folio/rest/impl/CirculationSettingsAPI.java +++ b/src/main/java/org/folio/rest/impl/CirculationSettingsAPI.java @@ -38,6 +38,7 @@ public void getCirculationSettingsStorageCirculationSettings(int offset, public void getCirculationSettingsStorageCirculationSettingsByCirculationSettingsId( String circulationSettingsId, String lang, Map okapiHeaders, Handler> asyncResultHandler, Context vertxContext) { + new CirculationSettingsService(vertxContext, okapiHeaders) .findById(circulationSettingsId) .onComplete(asyncResultHandler); @@ -48,6 +49,7 @@ public void putCirculationSettingsStorageCirculationSettingsByCirculationSetting String circulationSettingsId, String lang, CirculationSetting entity, Map okapiHeaders, Handler> asyncResultHandler, Context vertxContext) { + new CirculationSettingsService(vertxContext, okapiHeaders) .update(circulationSettingsId, entity) .onComplete(asyncResultHandler); @@ -57,6 +59,7 @@ public void putCirculationSettingsStorageCirculationSettingsByCirculationSetting public void deleteCirculationSettingsStorageCirculationSettingsByCirculationSettingsId( String circulationSettingsId, String lang, Map okapiHeaders, Handler> asyncResultHandler, Context vertxContext) { + new CirculationSettingsService(vertxContext, okapiHeaders).delete(circulationSettingsId) .onComplete(asyncResultHandler); } diff --git a/src/main/java/org/folio/service/CirculationSettingsService.java b/src/main/java/org/folio/service/CirculationSettingsService.java index 13def34a..a0c95007 100644 --- a/src/main/java/org/folio/service/CirculationSettingsService.java +++ b/src/main/java/org/folio/service/CirculationSettingsService.java @@ -10,13 +10,16 @@ import org.folio.persist.CirculationSettingsRepository; import org.folio.rest.jaxrs.model.CirculationSetting; import org.folio.rest.jaxrs.model.CirculationSettings; -import org.folio.rest.jaxrs.resource.CirculationSettingsStorage; +import org.folio.rest.jaxrs.resource.CirculationSettingsStorage.DeleteCirculationSettingsStorageCirculationSettingsByCirculationSettingsIdResponse; +import org.folio.rest.jaxrs.resource.CirculationSettingsStorage.GetCirculationSettingsStorageCirculationSettingsByCirculationSettingsIdResponse; +import org.folio.rest.jaxrs.resource.CirculationSettingsStorage.GetCirculationSettingsStorageCirculationSettingsResponse; +import org.folio.rest.jaxrs.resource.CirculationSettingsStorage.PostCirculationSettingsStorageCirculationSettingsResponse; +import org.folio.rest.jaxrs.resource.CirculationSettingsStorage.PutCirculationSettingsStorageCirculationSettingsByCirculationSettingsIdResponse; import org.folio.rest.persist.PgUtil; import org.folio.service.event.EntityChangedEventPublisher; import io.vertx.core.Context; import io.vertx.core.Future; -import io.vertx.core.Promise; public class CirculationSettingsService { @@ -36,39 +39,32 @@ public Future getAll(int offset, int limit, String query) { return PgUtil.get(CIRCULATION_SETTINGS_TABLE, CirculationSetting.class, CirculationSettings.class, query, offset, limit, okapiHeaders, vertxContext, - CirculationSettingsStorage.GetCirculationSettingsStorageCirculationSettingsResponse.class); + GetCirculationSettingsStorageCirculationSettingsResponse.class); } public Future create(CirculationSetting circulationSetting) { - Promise createResult = Promise.promise(); - PgUtil.post(CIRCULATION_SETTINGS_TABLE, circulationSetting, okapiHeaders, vertxContext, - CirculationSettingsStorage.PostCirculationSettingsStorageCirculationSettingsResponse.class, createResult); - return createResult.future() + return PgUtil.post(CIRCULATION_SETTINGS_TABLE, circulationSetting, okapiHeaders, vertxContext, + PostCirculationSettingsStorageCirculationSettingsResponse.class) .compose(eventPublisher.publishCreated()); } public Future findById(String circulationSettingsId) { return PgUtil.getById(CIRCULATION_SETTINGS_TABLE, CirculationSetting.class, circulationSettingsId, okapiHeaders, vertxContext, - CirculationSettingsStorage.GetCirculationSettingsStorageCirculationSettingsByCirculationSettingsIdResponse.class); + GetCirculationSettingsStorageCirculationSettingsByCirculationSettingsIdResponse.class); } public Future update(String circulationSettingsId, CirculationSetting circulationSetting) { - Promise updateResult = Promise.promise(); - PgUtil.put(CIRCULATION_SETTINGS_TABLE, circulationSetting, circulationSettingsId, okapiHeaders, vertxContext, - CirculationSettingsStorage.PutCirculationSettingsStorageCirculationSettingsByCirculationSettingsIdResponse.class, updateResult); - return updateResult.future() + return PgUtil.put(CIRCULATION_SETTINGS_TABLE, circulationSetting, circulationSettingsId, okapiHeaders, vertxContext, + PutCirculationSettingsStorageCirculationSettingsByCirculationSettingsIdResponse.class) .compose(eventPublisher.publishUpdated(circulationSetting)); } public Future delete(String circulationSettingsId) { - return repository.getById(circulationSettingsId).compose ( circulationSetting -> { - Promise deleteResult = Promise.promise(); - PgUtil.deleteById(CIRCULATION_SETTINGS_TABLE, circulationSettingsId, okapiHeaders, vertxContext, - CirculationSettingsStorage.DeleteCirculationSettingsStorageCirculationSettingsByCirculationSettingsIdResponse.class, deleteResult); - return deleteResult.future() - .compose(eventPublisher.publishRemoved(circulationSetting)); - } + return repository.getById(circulationSettingsId).compose ( + circulationSetting -> PgUtil.deleteById(CIRCULATION_SETTINGS_TABLE, circulationSettingsId, okapiHeaders, vertxContext, + DeleteCirculationSettingsStorageCirculationSettingsByCirculationSettingsIdResponse.class) + .compose(eventPublisher.publishRemoved(circulationSetting)) ); } } diff --git a/src/main/java/org/folio/support/kafka/topic/CirculationStorageKafkaTopic.java b/src/main/java/org/folio/support/kafka/topic/CirculationStorageKafkaTopic.java index 8d480b07..0f4ec85b 100644 --- a/src/main/java/org/folio/support/kafka/topic/CirculationStorageKafkaTopic.java +++ b/src/main/java/org/folio/support/kafka/topic/CirculationStorageKafkaTopic.java @@ -4,7 +4,7 @@ public enum CirculationStorageKafkaTopic implements KafkaTopic { REQUEST("request", 10), - CIRCULATION_SETTINGS("circulation_settings", 10), + CIRCULATION_SETTINGS("circulation-settings", 10), LOAN("loan", 10), CHECK_IN("check-in", 10), RULES("rules", 10); diff --git a/src/main/resources/templates/db_scripts/schema.json b/src/main/resources/templates/db_scripts/schema.json index 8992d484..5ad43489 100644 --- a/src/main/resources/templates/db_scripts/schema.json +++ b/src/main/resources/templates/db_scripts/schema.json @@ -154,14 +154,7 @@ { "tableName": "circulation_settings", "withMetadata": true, - "withAuditing": false, - "uniqueIndex": [ - { - "fieldName": "id", - "tOps": "ADD", - "caseSensitive": false - } - ] + "withAuditing": false }, { "tableName": "request",