Skip to content

Commit

Permalink
✨: add total_matches to GET "/api/datasets"
Browse files Browse the repository at this point in the history
Co-authored-by: Arash Kadkhodaei <[email protected]>
  • Loading branch information
itisAliRH and arash77 committed Aug 2, 2024
1 parent a42b739 commit 6806709
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
5 changes: 4 additions & 1 deletion lib/galaxy/webapps/galaxy/api/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class FastAPIDatasets:
)
def index(
self,
response: Response,
trans=DependsOnTrans,
history_id: Optional[DecodedDatabaseIdField] = Query(
default=None,
Expand All @@ -151,7 +152,9 @@ def index(
serialization_params: SerializationParams = Depends(query_serialization_params),
filter_query_params: FilterQueryParams = Depends(get_filter_query_params),
) -> List[AnyHistoryContentItem]:
return self.service.index(trans, history_id, serialization_params, filter_query_params)
entries, total_matches = self.service.index(trans, history_id, serialization_params, filter_query_params)
response.headers["total_matches"] = str(total_matches)
return entries

@router.get(
"/api/datasets/{dataset_id}/storage",
Expand Down
22 changes: 15 additions & 7 deletions lib/galaxy/webapps/galaxy/services/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def index(
history_id: Optional[DecodedDatabaseIdField],
serialization_params: SerializationParams,
filter_query_params: FilterQueryParams,
) -> List[AnyHistoryContentItem]:
) -> Tuple[List[AnyHistoryContentItem], int]:
"""
Search datasets or collections using a query system and returns a list
containing summary of dataset or dataset_collection information.
Expand All @@ -345,12 +345,20 @@ def index(
order_by=order_by,
user_id=user.id,
)
return [
self.serializer_by_type[content.history_content_type].serialize_to_view(
content, user=user, trans=trans, encode_id=False, **serialization_params.model_dump()
)
for content in contents
]
total_matches = self.history_contents_manager.contents_count(
container=container,
filters=filters,
user_id=user.id,
)
return (
[
self.serializer_by_type[content.history_content_type].serialize_to_view(
content, user=user, trans=trans, encode_id=False, **serialization_params.model_dump()
)
for content in contents
],
total_matches,
)

def show(
self,
Expand Down

0 comments on commit 6806709

Please sign in to comment.