Skip to content

Commit 590f1e7

Browse files
committed
get default product name
1 parent 7cbc88c commit 590f1e7

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from simcore_postgres_database.models.products import products
1111
from simcore_postgres_database.utils_products import (
1212
execute_get_or_create_product_group,
13+
get_default_product_name,
1314
)
1415
from simcore_postgres_database.utils_products_prices import (
1516
ProductPriceInfo,
@@ -54,7 +55,7 @@
5455
]
5556

5657

57-
async def get_product_payment_fields(
58+
async def _get_product_payment_fields(
5859
conn: AsyncConnection, product_name: ProductName
5960
) -> PaymentFieldsTuple:
6061
price_info = await get_product_latest_price_info_or_none(
@@ -98,7 +99,7 @@ async def list_products(
9899
async for row in rows:
99100
name = row.name
100101

101-
payments = await get_product_payment_fields(conn, product_name=name)
102+
payments = await _get_product_payment_fields(conn, product_name=name)
102103

103104
app_products.append(
104105
Product(
@@ -130,9 +131,10 @@ async def get_product(
130131
async with pass_or_acquire_connection(self.engine, connection) as conn:
131132

132133
result = await conn.execute(query)
133-
row = result.one_or_none()
134-
if row:
135-
payments = await get_product_payment_fields(conn, product_name=row.name)
134+
if row := result.one_or_none():
135+
payments = await _get_product_payment_fields(
136+
conn, product_name=row.name
137+
)
136138
return Product(
137139
**row._asdict(),
138140
is_payment_enabled=payments.enabled,
@@ -143,7 +145,8 @@ async def get_product(
143145
async def get_default_product_name(
144146
self, connection: AsyncConnection | None = None
145147
) -> ProductName:
146-
raise NotImplementedError
148+
async with pass_or_acquire_connection(self.engine, connection) as conn:
149+
return await get_default_product_name(conn)
147150

148151
async def get_product_latest_price_info_or_none(
149152
self, product_name: str, connection: AsyncConnection | None = None

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ async def load_products(app: web.Application) -> list[Product]:
3030

3131

3232
async def get_default_product_name(app: web.Application) -> ProductName:
33-
raise NotImplementedError
33+
repo = ProductRepository.create_from_app(app)
34+
return await repo.get_default_product_name()
3435

3536

3637
def get_product(app: web.Application, product_name: ProductName) -> Product:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from ..constants import APP_PRODUCTS_KEY
1010
from . import _service
11-
from .models import Product
11+
from ._models import Product
1212

1313
_logger = logging.getLogger(__name__)
1414

0 commit comments

Comments
 (0)