Skip to content

Commit 881646a

Browse files
committed
start adding links to output schemas
1 parent a4a3bc3 commit 881646a

File tree

1 file changed

+25
-3
lines changed
  • packages/models-library/src/models_library/api_schemas_webserver

1 file changed

+25
-3
lines changed

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
from pathlib import Path
33
from typing import Annotated, Any
44

5+
from aiohttp import web
56
from models_library.api_schemas_storage.storage_schemas import (
67
DEFAULT_NUMBER_OF_PATHS_PER_PAGE,
78
MAX_NUMBER_OF_PATHS_PER_PAGE,
89
)
9-
from pydantic import BaseModel, Field
10+
from pydantic import BaseModel, Field, HttpUrl
1011

1112
from ..api_schemas_rpc_async_jobs.async_jobs import (
1213
AsyncJobGet,
@@ -50,12 +51,33 @@ def to_rpc_schema(self, location_id: LocationID) -> DataExportTaskStartInput:
5051
)
5152

5253

54+
class AsyncJobLinks(OutputSchema):
55+
status_href: HttpUrl
56+
abort_href: HttpUrl
57+
result_href: HttpUrl
58+
59+
5360
class StorageAsyncJobGet(OutputSchema):
5461
job_id: AsyncJobId
62+
links: AsyncJobLinks
5563

5664
@classmethod
57-
def from_rpc_schema(cls, async_job_rpc_get: AsyncJobGet) -> "StorageAsyncJobGet":
58-
return StorageAsyncJobGet(job_id=async_job_rpc_get.job_id)
65+
def from_rpc_schema(
66+
cls, app: web.Application, async_job_rpc_get: AsyncJobGet
67+
) -> "StorageAsyncJobGet":
68+
job_id = f"{async_job_rpc_get.job_id}"
69+
links = AsyncJobLinks(
70+
status_href=HttpUrl(
71+
f"{app.router['get_async_job_status'].url_for(job_id=job_id)}"
72+
),
73+
abort_href=HttpUrl(
74+
f"{app.router['abort_async_job'].url_for(job_id=job_id)}"
75+
),
76+
result_href=HttpUrl(
77+
f"{app.router['get_async_job_result'].url_for(job_id=job_id)}"
78+
),
79+
)
80+
return StorageAsyncJobGet(job_id=async_job_rpc_get.job_id, links=links)
5981

6082

6183
class StorageAsyncJobStatus(OutputSchema):

0 commit comments

Comments
 (0)