From 823718fd2a7f2446b16980c0ea292356ce41d73d Mon Sep 17 00:00:00 2001 From: Cosmin Poieana Date: Sat, 23 Nov 2024 09:49:47 +0200 Subject: [PATCH] Minor refactors --- deep_ice/__init__.py | 2 +- deep_ice/api/routes/cart.py | 6 +++--- deep_ice/api/routes/payments.py | 5 ++--- deep_ice/core/config.py | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/deep_ice/__init__.py b/deep_ice/__init__.py index db57a49..973501c 100644 --- a/deep_ice/__init__.py +++ b/deep_ice/__init__.py @@ -26,7 +26,7 @@ async def lifespan(fast_app: FastAPI): class TaskQueue: functions = [payment_service.make_payment_task] redis_settings = redis_settings - max_tries = settings.TASK_MAX_RETRIES + max_tries = settings.TASK_MAX_TRIES retry_delay = settings.TASK_RETRY_DELAY diff --git a/deep_ice/api/routes/cart.py b/deep_ice/api/routes/cart.py index 9351b93..c88939c 100644 --- a/deep_ice/api/routes/cart.py +++ b/deep_ice/api/routes/cart.py @@ -43,13 +43,14 @@ async def get_cart_items(current_user: CurrentUserDep, cart_service: CartService return cart -@router.post("/items", response_model=RetrieveCartItem) +@router.post( + "/items", response_model=RetrieveCartItem, status_code=status.HTTP_201_CREATED +) async def add_item_to_cart( session: SessionDep, current_user: CurrentUserDep, cart_service: CartServiceDep, item: Annotated[CreateCartItem, Body()], - response: Response, ): cart = await cart_service.ensure_cart(cast(int, current_user.id)) cart_item = CartItem(cart_id=cart.id, **item.model_dump()) @@ -65,7 +66,6 @@ async def add_item_to_cart( else: cart_item.icecream = icecream - response.status_code = status.HTTP_201_CREATED return cart_item diff --git a/deep_ice/api/routes/payments.py b/deep_ice/api/routes/payments.py index 45f9a9a..8dcb346 100644 --- a/deep_ice/api/routes/payments.py +++ b/deep_ice/api/routes/payments.py @@ -6,9 +6,8 @@ from sqlalchemy.exc import SQLAlchemyError from deep_ice.core import logger -from deep_ice.core.dependencies import CurrentUserDep, SessionDep +from deep_ice.core.dependencies import CartServiceDep, CurrentUserDep, SessionDep from deep_ice.models import PaymentMethod, PaymentStatus, RetrievePayment -from deep_ice.services.cart import CartService from deep_ice.services.order import OrderService from deep_ice.services.payment import PaymentError, PaymentService, payment_stub from deep_ice.services.stats import stats_service @@ -20,13 +19,13 @@ async def make_payment( session: SessionDep, current_user: CurrentUserDep, + cart_service: CartServiceDep, method: Annotated[PaymentMethod, Body(embed=True)], request: Request, response: Response, ): # FIXME(cmin764): Check if we need an async Lock primitive here in order to allow # only one user to submit an order at a time. (based on available stock check) - cart_service = CartService(session) cart = await cart_service.get_cart(cast(int, current_user.id)) if not cart or not cart.items: raise HTTPException( diff --git a/deep_ice/core/config.py b/deep_ice/core/config.py index fd72c26..8524844 100644 --- a/deep_ice/core/config.py +++ b/deep_ice/core/config.py @@ -31,7 +31,7 @@ class Settings(BaseSettings): REDIS_HOST: str = "localhost" - TASK_MAX_RETRIES: int = 3 + TASK_MAX_TRIES: int = 3 TASK_RETRY_DELAY: int = 1 # seconds between retries TASK_BACKOFF_FACTOR: int = 5 # seconds to wait based on the job try counter