-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
collections: added task to compute num of records #1853
Merged
alejandromumo
merged 2 commits into
inveniosoftware:master
from
alejandromumo:add_collections_tasks
Oct 31, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using
self
here, even if it is a classmethod, instead of hardcoding?Otherwise, it is probably better to define
validate_query
as a static method, given that I can't override it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created an issue: #1867