Skip to content

Commit 8afa2ec

Browse files
committed
product repo
1 parent b9ae957 commit 8afa2ec

File tree

5 files changed

+38
-4
lines changed

5 files changed

+38
-4
lines changed

services/web/server/src/simcore_service_webserver/products/_api.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from decimal import Decimal
2+
from itertools import product
23
from pathlib import Path
3-
from typing import cast
4+
from typing import Any, cast
45

56
import aiofiles
67
from aiohttp import web
@@ -12,7 +13,11 @@
1213
from ._db import ProductRepository
1314
from ._events import APP_PRODUCTS_TEMPLATES_DIR_KEY
1415
from ._model import Product
15-
from .errors import BelowMinimumPaymentError, ProductPriceNotDefinedError
16+
from .errors import (
17+
BelowMinimumPaymentError,
18+
ProductNotFoundError,
19+
ProductPriceNotDefinedError,
20+
)
1621

1722

1823
def get_product_name(request: web.Request) -> str:
@@ -56,6 +61,16 @@ async def get_current_product_credit_price_info(
5661
)
5762

5863

64+
async def get_product_ui(
65+
repo: ProductRepository, product_name: ProductName
66+
) -> dict[str, Any]:
67+
ui = await repo.get_product_ui(product_name=product_name)
68+
if ui is not None:
69+
return ui
70+
71+
raise ProductNotFoundError(product_name=product_name)
72+
73+
5974
async def get_credit_amount(
6075
app: web.Application,
6176
*,

services/web/server/src/simcore_service_webserver/products/_db.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
from decimal import Decimal
3-
from typing import AsyncIterator, NamedTuple
3+
from typing import Any, AsyncIterator, NamedTuple
44

55
import sqlalchemy as sa
66
from aiopg.sa.connection import SAConnection
@@ -151,3 +151,11 @@ async def get_product_template_content(
151151
.where(products.c.name == product_name)
152152
)
153153
return f"{content}" if content else None
154+
155+
async def get_product_ui(self, product_name: ProductName) -> dict[str, Any] | None:
156+
async with self.engine.acquire() as conn:
157+
result = await conn.execute(
158+
sa.select(products.c.ui).where(products.c.name == product_name)
159+
)
160+
row: RowProxy | None = await result.first()
161+
return dict(**row.ui) if row else None

services/web/server/src/simcore_service_webserver/products/_handlers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pydantic import Field
1414
from servicelib.aiohttp.requests_validation import parse_request_path_parameters_as
1515
from servicelib.request_keys import RQT_USERID_KEY
16+
from simcore_service_webserver.products._db import ProductRepository
1617

1718
from .._constants import RQ_PRODUCT_KEY
1819
from .._meta import API_VTAG as VTAG
@@ -86,7 +87,11 @@ async def _get_current_product_ui(request: web.Request):
8687
req_ctx = _ProductsRequestContext.model_validate(request)
8788
product_name = req_ctx.product_name
8889

89-
data = ProductUIGet(product_name=product_name, ui={})
90+
ui = await api.get_product_ui(
91+
ProductRepository.create_from_request(request), product_name=product_name
92+
)
93+
94+
data = ProductUIGet(product_name=product_name, ui=ui)
9095
return envelope_json_response(data)
9196

9297

services/web/server/src/simcore_service_webserver/products/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
get_product_name,
88
get_product_stripe_info,
99
get_product_template_path,
10+
get_product_ui,
1011
list_products,
1112
)
1213
from ._model import Product
@@ -17,6 +18,7 @@
1718
"get_product_name",
1819
"get_product_stripe_info",
1920
"get_product_template_path",
21+
"get_product_ui",
2022
"get_product",
2123
"list_products",
2224
"Product",

services/web/server/src/simcore_service_webserver/products/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ class ProductError(WebServerBaseError, ValueError):
1010
...
1111

1212

13+
class ProductNotFoundError(ProductError):
14+
msg_template = "Undefined product '{product_name}'"
15+
16+
1317
class ProductPriceNotDefinedError(ProductError):
1418
msg_template = "Product price not defined. {reason}"
1519

0 commit comments

Comments
 (0)