Skip to content

Commit

Permalink
CIRCSTORE-509 Create CRUD API for storing circulation settings
Browse files Browse the repository at this point in the history
  • Loading branch information
MagzhanArtykov committed Jun 11, 2024
1 parent 98c40f9 commit 33d2d59
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 51 deletions.
30 changes: 15 additions & 15 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
]
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
]
},
{
Expand Down
3 changes: 2 additions & 1 deletion ramls/circulation-setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 15 additions & 6 deletions ramls/circulation-settings-storage.raml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"

2 changes: 1 addition & 1 deletion ramls/examples/circulation-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
}
}
],
"totalRecords": 0
"totalRecords": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class CirculationSettingsRepository

public CirculationSettingsRepository(Context context, Map<String,
String> okapiHeaders) {

super(postgresClient(context, okapiHeaders), CIRCULATION_SETTINGS_TABLE,
CirculationSetting.class);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/folio/rest/impl/CirculationSettingsAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void getCirculationSettingsStorageCirculationSettings(int offset,
public void getCirculationSettingsStorageCirculationSettingsByCirculationSettingsId(
String circulationSettingsId, String lang, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {

new CirculationSettingsService(vertxContext, okapiHeaders)
.findById(circulationSettingsId)
.onComplete(asyncResultHandler);
Expand All @@ -48,6 +49,7 @@ public void putCirculationSettingsStorageCirculationSettingsByCirculationSetting
String circulationSettingsId, String lang, CirculationSetting entity,
Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler,
Context vertxContext) {

new CirculationSettingsService(vertxContext, okapiHeaders)
.update(circulationSettingsId, entity)
.onComplete(asyncResultHandler);
Expand All @@ -57,6 +59,7 @@ public void putCirculationSettingsStorageCirculationSettingsByCirculationSetting
public void deleteCirculationSettingsStorageCirculationSettingsByCirculationSettingsId(
String circulationSettingsId, String lang, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {

new CirculationSettingsService(vertxContext, okapiHeaders).delete(circulationSettingsId)
.onComplete(asyncResultHandler);
}
Expand Down
34 changes: 15 additions & 19 deletions src/main/java/org/folio/service/CirculationSettingsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -36,39 +39,32 @@ public Future<Response> 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<Response> create(CirculationSetting circulationSetting) {
Promise<Response> 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<Response> findById(String circulationSettingsId) {
return PgUtil.getById(CIRCULATION_SETTINGS_TABLE, CirculationSetting.class,
circulationSettingsId, okapiHeaders, vertxContext,
CirculationSettingsStorage.GetCirculationSettingsStorageCirculationSettingsByCirculationSettingsIdResponse.class);
GetCirculationSettingsStorageCirculationSettingsByCirculationSettingsIdResponse.class);
}

public Future<Response> update(String circulationSettingsId, CirculationSetting circulationSetting) {
Promise<Response> 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<Response> delete(String circulationSettingsId) {
return repository.getById(circulationSettingsId).compose ( circulationSetting -> {
Promise<Response> 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))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 1 addition & 8 deletions src/main/resources/templates/db_scripts/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,7 @@
{
"tableName": "circulation_settings",
"withMetadata": true,
"withAuditing": false,
"uniqueIndex": [
{
"fieldName": "id",
"tOps": "ADD",
"caseSensitive": false
}
]
"withAuditing": false
},
{
"tableName": "request",
Expand Down

0 comments on commit 33d2d59

Please sign in to comment.