Skip to content

Commit

Permalink
items: Add call number validation to ItemSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshamarora1 authored and kpsherva committed Jun 25, 2024
1 parent 65a6bb2 commit 0b32a02
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cds_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ def query_params_modifier(extra_params):
"text/csv": "cds_ils.series.serializers:csv_v1_search",
}
RECORDS_REST_ENDPOINTS[SERIES_PID_TYPE]["search_query_parser"] = query_params_modifier
RECORDS_REST_ENDPOINTS[ITEM_PID_TYPE]["record_loaders"] = {
"application/json": "cds_ils.items.loaders:item_loader"
}
RECORDS_REST_ENDPOINTS[ITEM_PID_TYPE][
"list_permission_factory_imp"
] = authenticated_user_permission
Expand Down
8 changes: 8 additions & 0 deletions cds_ils/items/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2024 CERN.
#
# CDS-ILS is free software; you can redistribute it and/or modify it under
# the terms of the MIT License; see LICENSE file for more details.

"""CDS-ILS items module."""
36 changes: 36 additions & 0 deletions cds_ils/items/loaders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2024 CERN.
#
# CDS-ILS is free software; you can redistribute it and/or modify it under
# the terms of the MIT License; see LICENSE file for more details.

"""CDS-ILS items loaders."""

from invenio_app_ils.items.loaders.jsonschemas.items import (
ItemSchemaV1 as ILSItemSchemaV1,
)
from invenio_app_ils.records.loaders import ils_marshmallow_loader
from invenio_app_ils.records.loaders.schemas.identifiers import IdentifierSchema
from marshmallow import ValidationError, fields


def validate_call_number_exists(identifiers):
"""Check if Call number exists."""
for identifier in identifiers:
if identifier["scheme"] == "CALL_NUMBER":
return
raise ValidationError("The Call number identifier field is mandatory.")


class ItemSchemaV1(ILSItemSchemaV1):
"""Item schema."""

identifiers = fields.List(
fields.Nested(IdentifierSchema),
required=True,
validate=validate_call_number_exists,
)


item_loader = ils_marshmallow_loader(ItemSchemaV1)
1 change: 1 addition & 0 deletions ui/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export const config = {
"document_pid",
"circulation_restriction",
"medium",
"identifiers",
],
},
editorUiSchema: {
Expand Down

0 comments on commit 0b32a02

Please sign in to comment.