Skip to content

Commit 526e5d2

Browse files
committed
draft implementation
1 parent a4eb646 commit 526e5d2

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

services/catalog/src/simcore_service_catalog/api/rpc/_services.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from models_library.products import ProductName
1313
from models_library.rest_pagination import PageOffsetInt
1414
from models_library.rpc_pagination import DEFAULT_NUMBER_OF_ITEMS_PER_PAGE, PageLimitInt
15+
from models_library.services_history import ServiceRelease
1516
from models_library.services_types import ServiceKey, ServiceVersion
1617
from models_library.users import UserID
1718
from pydantic import ValidationError, validate_call
@@ -220,3 +221,23 @@ async def batch_get_my_services(
220221
assert [(sv.key, sv.release.version) for sv in services] == ids # nosec
221222

222223
return services
224+
225+
226+
@router.expose(reraise_if_error_type=(CatalogForbiddenError, ValidationError))
227+
@log_decorator(_logger, level=logging.DEBUG)
228+
@validate_call(config={"arbitrary_types_allowed": True})
229+
async def get_my_service_history(
230+
app: FastAPI,
231+
*,
232+
product_name: ProductName,
233+
user_id: UserID,
234+
service_key: ServiceKey,
235+
) -> list[ServiceRelease]:
236+
assert app.state.engine # nosec
237+
238+
return await services_api.get_service_history(
239+
repo=ServicesRepository(app.state.engine),
240+
product_name=product_name,
241+
user_id=user_id,
242+
service_key=service_key,
243+
)

services/catalog/src/simcore_service_catalog/services/services_api.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,3 +464,41 @@ async def batch_get_my_services(
464464
)
465465

466466
return my_services
467+
468+
469+
async def get_service_history(
470+
repo: ServicesRepository,
471+
*,
472+
product_name: ProductName,
473+
user_id: UserID,
474+
service_key: ServiceKey,
475+
include_compatibility: bool = False,
476+
) -> list[ServiceRelease]:
477+
478+
history = (
479+
await repo.get_service_history(
480+
# NOTE: that the service history might be different for each user
481+
# since access-rights are defined on a k:v basis
482+
product_name=product_name,
483+
user_id=user_id,
484+
key=service_key,
485+
)
486+
or []
487+
)
488+
489+
compatibility_map = {}
490+
if include_compatibility:
491+
msg = "This operation is heavy and for the moment is not necessary"
492+
raise NotImplementedError(msg)
493+
494+
return [
495+
# domain -> domain
496+
ServiceRelease.model_construct(
497+
version=h.version,
498+
version_display=h.version_display,
499+
released=h.created,
500+
retired=h.deprecated,
501+
compatibility=compatibility_map.get(h.version),
502+
)
503+
for h in history
504+
]

0 commit comments

Comments
 (0)