-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
collections: move records search into service
* Added resource for collections * Moved records search from community records to collections service
- Loading branch information
1 parent
9e56947
commit 27eeac6
Showing
18 changed files
with
135 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2024 CERN. | ||
# | ||
# Invenio-RDM is free software; you can redistribute it and/or modify | ||
# it under the terms of the MIT License; see LICENSE file for more details. | ||
"""Collection resource module.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2024 CERN. | ||
# | ||
# Invenio-RDM is free software; you can redistribute it and/or modify | ||
# it under the terms of the MIT License; see LICENSE file for more details. | ||
"""Collection resource config.""" | ||
|
||
from flask_resources import ( | ||
HTTPJSONException, | ||
JSONSerializer, | ||
ResourceConfig, | ||
ResponseHandler, | ||
create_error_handler, | ||
) | ||
from invenio_records_resources.resources.records.args import SearchRequestArgsSchema | ||
from invenio_records_resources.resources.records.headers import etag_headers | ||
from marshmallow.fields import Integer | ||
|
||
from invenio_rdm_records.resources.serializers import UIJSONSerializer | ||
|
||
from ..errors import CollectionNotFound | ||
|
||
|
||
class CollectionsResourceConfig(ResourceConfig): | ||
"""Configuration for the Collection resource.""" | ||
|
||
blueprint_name = "collections" | ||
url_prefix = "/collections" | ||
|
||
routes = { | ||
"search-records": "/<id>/records", | ||
} | ||
|
||
request_view_args = {"id": Integer()} | ||
request_search_args = SearchRequestArgsSchema | ||
error_handlers = { | ||
CollectionNotFound: create_error_handler( | ||
HTTPJSONException( | ||
code=404, | ||
description="Collection was not found.", | ||
) | ||
), | ||
} | ||
response_handlers = { | ||
"application/json": ResponseHandler(JSONSerializer(), headers=etag_headers), | ||
"application/vnd.inveniordm.v1+json": ResponseHandler( | ||
UIJSONSerializer(), headers=etag_headers | ||
), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2024 CERN. | ||
# | ||
# Invenio-RDM is free software; you can redistribute it and/or modify | ||
# it under the terms of the MIT License; see LICENSE file for more details. | ||
"""Collection resource.""" | ||
|
||
from flask import g | ||
from flask_resources import Resource, resource_requestctx, response_handler, route | ||
from invenio_records_resources.resources.records.resource import ( | ||
request_search_args, | ||
request_view_args, | ||
) | ||
|
||
|
||
class CollectionsResource(Resource): | ||
"""Collection resource.""" | ||
|
||
def __init__(self, config, service): | ||
"""Instantiate the resource.""" | ||
super().__init__(config) | ||
self.service = service | ||
|
||
def create_url_rules(self): | ||
"""Create the URL rules for the record resource.""" | ||
routes = self.config.routes | ||
return [ | ||
route("GET", routes["search-records"], self.search_records), | ||
] | ||
|
||
@request_view_args | ||
@request_search_args | ||
@response_handler(many=True) | ||
def search_records(self): | ||
"""Search records in a collection.""" | ||
id_ = resource_requestctx.view_args["id"] | ||
records = self.service.search_collection_records( | ||
g.identity, | ||
id_, | ||
params=resource_requestctx.args, | ||
) | ||
return records.to_dict(), 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2024 CERN. | ||
# | ||
# Invenio-RDM is free software; you can redistribute it and/or modify | ||
# it under the terms of the MIT License; see LICENSE file for more details. | ||
"""Collection service module.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters