Skip to content

Commit ccff359

Browse files
committed
@pcrespov streamline to_rpc_schema methods
1 parent c3758bd commit ccff359

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

packages/models-library/src/models_library/api_schemas_storage/rpc/data_export_async_jobs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ class DataExportTaskStartInput(BaseModel):
1616
### Exceptions
1717

1818

19-
class StorageRpcErrors(OsparcErrorMixin, RuntimeError):
19+
class StorageRpcError(OsparcErrorMixin, RuntimeError):
2020
pass
2121

2222

23-
class InvalidFileIdentifierError(StorageRpcErrors):
23+
class InvalidFileIdentifierError(StorageRpcError):
2424
msg_template: str = "Could not find the file {file_id}"
2525

2626

27-
class AccessRightError(StorageRpcErrors):
27+
class AccessRightError(StorageRpcError):
2828
msg_template: str = "User {user_id} does not have access to file {file_id}"
2929

3030

31-
class DataExportError(StorageRpcErrors):
31+
class DataExportError(StorageRpcError):
3232
msg_template: str = "Could not complete data export job with id {job_id}"

packages/models-library/src/models_library/api_schemas_webserver/storage.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
from pathlib import Path
33
from typing import Any
44

5-
from pydantic import BaseModel
6-
75
from ..api_schemas_rpc_async_jobs.async_jobs import (
86
AsyncJobGet,
97
AsyncJobId,
@@ -14,38 +12,37 @@
1412
from ..progress_bar import ProgressReport
1513
from ..projects_nodes_io import LocationID
1614
from ..users import UserID
15+
from ._base import InputSchema, OutputSchema
1716

1817

19-
class DataExportPost(BaseModel):
18+
class DataExportPost(InputSchema):
2019
paths: list[Path]
2120

22-
def to_storage_model(
21+
def to_rpc_schema(
2322
self, user_id: UserID, location_id: LocationID
2423
) -> DataExportTaskStartInput:
2524
return DataExportTaskStartInput(
2625
paths=self.paths, user_id=user_id, location_id=location_id
2726
)
2827

2928

30-
class StorageAsyncJobGet(BaseModel):
29+
class StorageAsyncJobGet(OutputSchema):
3130
job_id: AsyncJobId
3231

3332
@classmethod
34-
def from_async_job_rpc_get(
35-
cls, async_job_rpc_get: AsyncJobGet
36-
) -> "StorageAsyncJobGet":
33+
def from_rpc_schema(cls, async_job_rpc_get: AsyncJobGet) -> "StorageAsyncJobGet":
3734
return StorageAsyncJobGet(job_id=async_job_rpc_get.job_id)
3835

3936

40-
class StorageAsyncJobStatus(BaseModel):
37+
class StorageAsyncJobStatus(OutputSchema):
4138
job_id: AsyncJobId
4239
progress: ProgressReport
4340
done: bool
4441
started: datetime
4542
stopped: datetime | None
4643

4744
@classmethod
48-
def from_async_job_rpc_status(
45+
def from_rpc_schema(
4946
cls, async_job_rpc_status: AsyncJobStatus
5047
) -> "StorageAsyncJobStatus":
5148
return StorageAsyncJobStatus(
@@ -57,12 +54,12 @@ def from_async_job_rpc_status(
5754
)
5855

5956

60-
class StorageAsyncJobResult(BaseModel):
57+
class StorageAsyncJobResult(OutputSchema):
6158
result: Any | None
6259
error: Any | None
6360

6461
@classmethod
65-
def from_async_job_rpc_result(
62+
def from_rpc_schema(
6663
cls, async_job_rpc_result: AsyncJobResult
6764
) -> "StorageAsyncJobResult":
6865
return StorageAsyncJobResult(

services/web/server/src/simcore_service_webserver/storage/_rest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,12 @@ class _PathParams(BaseModel):
402402
)
403403
async_job_rpc_get = await start_data_export(
404404
rabbitmq_rpc_client=rabbitmq_rpc_client,
405-
paths=data_export_post.to_storage_model(
405+
paths=data_export_post.to_rpc_schema(
406406
user_id=_req_ctx.user_id, location_id=_path_params.location_id
407407
),
408408
)
409409
return create_data_response(
410-
StorageAsyncJobGet.from_async_job_rpc_get(async_job_rpc_get),
410+
StorageAsyncJobGet.from_rpc_schema(async_job_rpc_get),
411411
status=status.HTTP_202_ACCEPTED,
412412
)
413413

@@ -429,7 +429,7 @@ async def get_async_job_status(request: web.Request) -> web.Response:
429429
job_id=async_job_get.job_id,
430430
)
431431
return create_data_response(
432-
StorageAsyncJobStatus.from_async_job_rpc_status(async_job_rpc_status),
432+
StorageAsyncJobStatus.from_rpc_schema(async_job_rpc_status),
433433
status=status.HTTP_200_OK,
434434
)
435435

@@ -472,6 +472,6 @@ async def get_async_job_result(request: web.Request) -> web.Response:
472472
job_id=async_job_get.job_id,
473473
)
474474
return create_data_response(
475-
StorageAsyncJobResult.from_async_job_rpc_result(async_job_rpc_result),
475+
StorageAsyncJobResult.from_rpc_schema(async_job_rpc_result),
476476
status=status.HTTP_200_OK,
477477
)

0 commit comments

Comments
 (0)