|
15 | 15 | from typing_extensions import TypeAlias |
16 | 16 |
|
17 | 17 | from aiida_restapi.common.pagination import PaginatedResults |
18 | | -from aiida_restapi.common.query import QueryParams, query_params |
| 18 | +from aiida_restapi.common.query import QueryParams |
19 | 19 | from aiida_restapi.config import API_CONFIG |
20 | 20 | from aiida_restapi.models.node import NodeModelRegistry |
21 | 21 | from aiida_restapi.repository.node import NodeLinks, NodeRepository |
@@ -182,14 +182,27 @@ async def get_nodes_download_formats() -> dict[str, t.Any]: |
182 | 182 | ) |
183 | 183 | @with_dbenv() |
184 | 184 | async def get_nodes( |
185 | | - queries: t.Annotated[QueryParams, Depends(query_params)], |
| 185 | + query_params: t.Annotated[ |
| 186 | + QueryParams, |
| 187 | + Query( |
| 188 | + default_factory=QueryParams, |
| 189 | + description='Query parameters for filtering, sorting, and pagination.', |
| 190 | + ), |
| 191 | + ], |
186 | 192 | ) -> PaginatedResults[orm.Node.Model]: |
187 | 193 | """Get AiiDA nodes with optional filtering, sorting, and/or pagination. |
188 | 194 |
|
189 | | - :param queries: The query parameters, including filters, order_by, page_size, and page. |
| 195 | + :param query_params: The query parameters, including filters, order_by, page_size, and page. |
190 | 196 | :return: The paginated results, including total count, current page, page size, and list of node models. |
| 197 | + :raises HTTPException: 422 if the query parameters are invalid, |
| 198 | + 500 for other failures during retrieval. |
191 | 199 | """ |
192 | | - return repository.get_entities(queries) |
| 200 | + try: |
| 201 | + return repository.get_entities(query_params) |
| 202 | + except ValueError as exception: |
| 203 | + raise HTTPException(status_code=422, detail=str(exception)) from exception |
| 204 | + except Exception as exception: |
| 205 | + raise HTTPException(status_code=500, detail=str(exception)) from exception |
193 | 206 |
|
194 | 207 |
|
195 | 208 | class NodeType(pdt.BaseModel): |
@@ -311,22 +324,28 @@ async def get_node_extras(uuid: str) -> dict[str, t.Any]: |
311 | 324 | @with_dbenv() |
312 | 325 | async def get_node_links( |
313 | 326 | uuid: str, |
314 | | - queries: t.Annotated[QueryParams, Depends(query_params)], |
| 327 | + query_params: t.Annotated[ |
| 328 | + QueryParams, |
| 329 | + Query( |
| 330 | + default_factory=QueryParams, |
| 331 | + description='Query parameters for filtering, sorting, and pagination.', |
| 332 | + ), |
| 333 | + ], |
315 | 334 | direction: t.Literal['incoming', 'outgoing'] = Query( |
316 | 335 | description='Specify whether to retrieve incoming or outgoing links.', |
317 | 336 | ), |
318 | 337 | ) -> PaginatedResults[NodeLinks]: |
319 | 338 | """Get the incoming or outgoing links of a node. |
320 | 339 |
|
321 | 340 | :param uuid: The uuid of the node to retrieve the incoming links for. |
322 | | - :param queries: The query parameters, including filters, order_by, page_size, and page. |
| 341 | + :param query_params: The query parameters, including filters, order_by, page_size, and page. |
323 | 342 | :param direction: Specify whether to retrieve incoming or outgoing links. |
324 | 343 | :return: The paginated requested linked nodes. |
325 | 344 | :raises HTTPException: 404 if the node with the given uuid does not exist, |
326 | 345 | 500 for other failures during retrieval. |
327 | 346 | """ |
328 | 347 | try: |
329 | | - return repository.get_node_links(uuid, queries, direction=direction) |
| 348 | + return repository.get_node_links(uuid, query_params, direction=direction) |
330 | 349 | except NotExistent as exception: |
331 | 350 | raise HTTPException(status_code=404, detail=str(exception)) from exception |
332 | 351 | except Exception as exception: |
|
0 commit comments