|
1 | | -import logging |
| 1 | +from typing import Annotated |
2 | 2 |
|
3 | | -from aiohttp import web |
4 | | -from aiohttp.web import RouteTableDef |
5 | | -from common_library.json_serialization import json_dumps |
6 | | -from models_library.api_schemas_storage import FileMetaDataGet |
7 | | -from models_library.utils.fastapi_encoders import jsonable_encoder |
8 | | -from servicelib.aiohttp.requests_validation import ( |
9 | | - parse_request_path_parameters_as, |
10 | | - parse_request_query_parameters_as, |
11 | | -) |
12 | | - |
13 | | -# Exclusive for simcore-s3 storage ----------------------- |
14 | | -from ..._meta import API_VTAG |
15 | | -from ...dsm import get_dsm_provider |
16 | | -from ...models import ( |
17 | | - FileMetaData, |
18 | | - FilesMetadataDatasetPathParams, |
19 | | - FilesMetadataDatasetQueryParams, |
20 | | - LocationPathParams, |
21 | | - StorageQueryParamsBase, |
22 | | -) |
| 3 | +from fastapi import APIRouter, Depends |
| 4 | +from models_library.api_schemas_storage import DatasetMetaDataGet, FileMetaDataGet |
| 5 | +from models_library.generics import Envelope |
| 6 | +from simcore_service_storage._meta import API_VTAG |
| 7 | +from simcore_service_storage.models import FilesMetadataDatasetPathParams |
23 | 8 |
|
24 | | -_logger = logging.getLogger(__name__) |
| 9 | +from api.specs.storage._locations import LocationPathParams, StorageQueryParamsBase |
25 | 10 |
|
26 | | -routes = RouteTableDef() |
| 11 | +router = APIRouter( |
| 12 | + prefix=f"/{API_VTAG}", |
| 13 | + tags=[ |
| 14 | + "datasets", |
| 15 | + ], |
| 16 | +) |
27 | 17 |
|
28 | 18 |
|
29 | | -@routes.get( |
30 | | - f"/{API_VTAG}/locations/{{location_id}}/datasets", name="list_datasets_metadata" |
| 19 | +@router.get( |
| 20 | + "/locations/{location_id}/datasets", |
| 21 | + response_model=Envelope[list[DatasetMetaDataGet]], |
31 | 22 | ) |
32 | | -async def list_datasets_metadata(request: web.Request) -> web.Response: |
33 | | - query_params: StorageQueryParamsBase = parse_request_query_parameters_as( |
34 | | - StorageQueryParamsBase, request |
35 | | - ) |
36 | | - path_params = parse_request_path_parameters_as(LocationPathParams, request) |
37 | | - _logger.debug( |
38 | | - "received call to list_datasets_metadata with %s", |
39 | | - f"{path_params=}, {query_params=}", |
40 | | - ) |
41 | | - |
42 | | - dsm = get_dsm_provider(request.app).get(path_params.location_id) |
43 | | - return web.json_response( |
44 | | - {"data": await dsm.list_datasets(query_params.user_id)}, dumps=json_dumps |
45 | | - ) |
| 23 | +async def list_datasets_metadata( |
| 24 | + _query: Annotated[StorageQueryParamsBase, Depends()], |
| 25 | + _path: Annotated[LocationPathParams, Depends()], |
| 26 | +): |
| 27 | + ... |
46 | 28 |
|
47 | 29 |
|
48 | | -@routes.get( |
49 | | - f"/{API_VTAG}/locations/{{location_id}}/datasets/{{dataset_id}}/metadata", |
50 | | - name="list_dataset_files_metadata", |
| 30 | +@router.get( |
| 31 | + "/locations/{location_id}/datasets/{dataset_id}/metadata", |
| 32 | + response_model=Envelope[list[FileMetaDataGet]], |
51 | 33 | ) |
52 | | -async def list_dataset_files_metadata(request: web.Request) -> web.Response: |
53 | | - query_params: FilesMetadataDatasetQueryParams = parse_request_query_parameters_as( |
54 | | - FilesMetadataDatasetQueryParams, request |
55 | | - ) |
56 | | - path_params = parse_request_path_parameters_as( |
57 | | - FilesMetadataDatasetPathParams, request |
58 | | - ) |
59 | | - _logger.debug( |
60 | | - "received call to list_dataset_files_metadata with %s", |
61 | | - f"{path_params=}, {query_params=}", |
62 | | - ) |
63 | | - dsm = get_dsm_provider(request.app).get(path_params.location_id) |
64 | | - data: list[FileMetaData] = await dsm.list_files_in_dataset( |
65 | | - user_id=query_params.user_id, |
66 | | - dataset_id=path_params.dataset_id, |
67 | | - expand_dirs=query_params.expand_dirs, |
68 | | - ) |
69 | | - return web.json_response( |
70 | | - {"data": [jsonable_encoder(FileMetaDataGet(**d.model_dump())) for d in data]}, |
71 | | - dumps=json_dumps, |
72 | | - ) |
| 34 | +async def list_dataset_files_metadata( |
| 35 | + _query: Annotated[FilesMetadataDatasetPathParams, Depends()], |
| 36 | + _path: Annotated[LocationPathParams, Depends()], |
| 37 | +): |
| 38 | + ... |
0 commit comments