feat: new stuff

This commit is contained in:
2024-11-05 04:40:42 +03:00
parent d497bb0465
commit eeac97861c
10 changed files with 138 additions and 78 deletions

View File

@@ -1,3 +1,4 @@
import logging
from typing import Union, List
from backend.session import session_factory
@@ -10,26 +11,25 @@ async def process_update(product_ids: list[int]):
updates = [StockUpdate(product_id=product_id) for product_id in product_ids]
updater = StocksUpdater(session)
await updater.update(updates)
return {'message': f'Stocks for products [{",".join(map(str, product_ids))}] successfully updated'}
logging.info(f'Products [{",".join(list(map(str, product_ids)))}] successfully updated')
async def update_marketplace(marketplace_id: int):
async with session_factory() as session:
updater = StocksUpdater(session)
await updater.full_update_marketplace(marketplace_id)
return {'message': f'Stocks for marketplace {marketplace_id} successfully updated'}
logging.info(f'Marketplace {marketplace_id} successfully updated')
async def update_marketplace_products(marketplace_id: int, product_ids: list[int]):
async with session_factory() as session:
updater = StocksUpdater(session)
await updater.update_marketplace_products(marketplace_id, product_ids)
return {
'message': f'Products [{",".join(list(map(str, product_ids)))}] successfully updated for marketplace {marketplace_id}'}
logging.info(f'Products [{",".join(map(str, product_ids))}] for marketplace {marketplace_id} successfully updated')
async def update_marketplaces(marketplace_ids: Union[List[int], None]):
async with session_factory() as session:
updater = StocksUpdater(session)
await updater.full_update_all_marketplaces(marketplace_ids)
return {'message': f'Stocks for marketplaces [{",".join(map(str, marketplace_ids))}] successfully updated'}
logging.info(f'Marketplaces {marketplace_ids} successfully updated')