File tree Expand file tree Collapse file tree 5 files changed +38
-4
lines changed
services/web/server/src/simcore_service_webserver/products Expand file tree Collapse file tree 5 files changed +38
-4
lines changed Original file line number Diff line number Diff line change 11from decimal import Decimal
2+ from itertools import product
23from pathlib import Path
3- from typing import cast
4+ from typing import Any , cast
45
56import aiofiles
67from aiohttp import web
1213from ._db import ProductRepository
1314from ._events import APP_PRODUCTS_TEMPLATES_DIR_KEY
1415from ._model import Product
15- from .errors import BelowMinimumPaymentError , ProductPriceNotDefinedError
16+ from .errors import (
17+ BelowMinimumPaymentError ,
18+ ProductNotFoundError ,
19+ ProductPriceNotDefinedError ,
20+ )
1621
1722
1823def 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+
5974async def get_credit_amount (
6075 app : web .Application ,
6176 * ,
Original file line number Diff line number Diff line change 11import logging
22from decimal import Decimal
3- from typing import AsyncIterator , NamedTuple
3+ from typing import Any , AsyncIterator , NamedTuple
44
55import sqlalchemy as sa
66from 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
Original file line number Diff line number Diff line change 1313from pydantic import Field
1414from servicelib .aiohttp .requests_validation import parse_request_path_parameters_as
1515from servicelib .request_keys import RQT_USERID_KEY
16+ from simcore_service_webserver .products ._db import ProductRepository
1617
1718from .._constants import RQ_PRODUCT_KEY
1819from .._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
Original file line number Diff line number Diff line change 77 get_product_name ,
88 get_product_stripe_info ,
99 get_product_template_path ,
10+ get_product_ui ,
1011 list_products ,
1112)
1213from ._model import Product
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" ,
Original file line number Diff line number Diff 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+
1317class ProductPriceNotDefinedError (ProductError ):
1418 msg_template = "Product price not defined. {reason}"
1519
You can’t perform that action at this time.
0 commit comments