style: apply black and isort formatting across entire codebase
- Standardize quote style (single to double quotes) - Reorder and group imports alphabetically - Fix line breaks and indentation for consistency - Apply PEP 8 formatting standards Also updated Makefile to exclude both venv and .venv from code quality checks. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -8,18 +8,15 @@ No authentication required - uses session ID for cart tracking.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from fastapi import APIRouter, Depends, Path, Body, Request, HTTPException
|
||||
|
||||
from fastapi import APIRouter, Body, Depends, HTTPException, Path, Request
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.services.cart_service import cart_service
|
||||
from models.schema.cart import (
|
||||
AddToCartRequest,
|
||||
UpdateCartItemRequest,
|
||||
CartResponse,
|
||||
CartOperationResponse,
|
||||
ClearCartResponse,
|
||||
)
|
||||
from models.schema.cart import (AddToCartRequest, CartOperationResponse,
|
||||
CartResponse, ClearCartResponse,
|
||||
UpdateCartItemRequest)
|
||||
|
||||
router = APIRouter()
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -29,6 +26,7 @@ logger = logging.getLogger(__name__)
|
||||
# CART ENDPOINTS
|
||||
# ============================================================================
|
||||
|
||||
|
||||
@router.get("/cart/{session_id}", response_model=CartResponse)
|
||||
def get_cart(
|
||||
request: Request,
|
||||
@@ -45,12 +43,12 @@ def get_cart(
|
||||
- session_id: Unique session identifier for the cart
|
||||
"""
|
||||
# Get vendor from middleware
|
||||
vendor = getattr(request.state, 'vendor', None)
|
||||
vendor = getattr(request.state, "vendor", None)
|
||||
|
||||
if not vendor:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Vendor not found. Please access via vendor domain/subdomain/path."
|
||||
detail="Vendor not found. Please access via vendor domain/subdomain/path.",
|
||||
)
|
||||
|
||||
logger.info(
|
||||
@@ -59,23 +57,19 @@ def get_cart(
|
||||
"vendor_id": vendor.id,
|
||||
"vendor_code": vendor.subdomain,
|
||||
"session_id": session_id,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
cart = cart_service.get_cart(
|
||||
db=db,
|
||||
vendor_id=vendor.id,
|
||||
session_id=session_id
|
||||
)
|
||||
cart = cart_service.get_cart(db=db, vendor_id=vendor.id, session_id=session_id)
|
||||
|
||||
logger.info(
|
||||
f"[SHOP_API] get_cart result: {len(cart.get('items', []))} items in cart",
|
||||
extra={
|
||||
"session_id": session_id,
|
||||
"vendor_id": vendor.id,
|
||||
"item_count": len(cart.get('items', [])),
|
||||
"total": cart.get('total', 0),
|
||||
}
|
||||
"item_count": len(cart.get("items", [])),
|
||||
"total": cart.get("total", 0),
|
||||
},
|
||||
)
|
||||
|
||||
return CartResponse.from_service_dict(cart)
|
||||
@@ -102,12 +96,12 @@ def add_to_cart(
|
||||
- quantity: Quantity to add (default: 1)
|
||||
"""
|
||||
# Get vendor from middleware
|
||||
vendor = getattr(request.state, 'vendor', None)
|
||||
vendor = getattr(request.state, "vendor", None)
|
||||
|
||||
if not vendor:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Vendor not found. Please access via vendor domain/subdomain/path."
|
||||
detail="Vendor not found. Please access via vendor domain/subdomain/path.",
|
||||
)
|
||||
|
||||
logger.info(
|
||||
@@ -118,7 +112,7 @@ def add_to_cart(
|
||||
"session_id": session_id,
|
||||
"product_id": cart_data.product_id,
|
||||
"quantity": cart_data.quantity,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
result = cart_service.add_to_cart(
|
||||
@@ -126,7 +120,7 @@ def add_to_cart(
|
||||
vendor_id=vendor.id,
|
||||
session_id=session_id,
|
||||
product_id=cart_data.product_id,
|
||||
quantity=cart_data.quantity
|
||||
quantity=cart_data.quantity,
|
||||
)
|
||||
|
||||
logger.info(
|
||||
@@ -134,13 +128,15 @@ def add_to_cart(
|
||||
extra={
|
||||
"session_id": session_id,
|
||||
"result": result,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
return CartOperationResponse(**result)
|
||||
|
||||
|
||||
@router.put("/cart/{session_id}/items/{product_id}", response_model=CartOperationResponse)
|
||||
@router.put(
|
||||
"/cart/{session_id}/items/{product_id}", response_model=CartOperationResponse
|
||||
)
|
||||
def update_cart_item(
|
||||
request: Request,
|
||||
session_id: str = Path(..., description="Shopping session ID"),
|
||||
@@ -162,12 +158,12 @@ def update_cart_item(
|
||||
- quantity: New quantity (must be >= 1)
|
||||
"""
|
||||
# Get vendor from middleware
|
||||
vendor = getattr(request.state, 'vendor', None)
|
||||
vendor = getattr(request.state, "vendor", None)
|
||||
|
||||
if not vendor:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Vendor not found. Please access via vendor domain/subdomain/path."
|
||||
detail="Vendor not found. Please access via vendor domain/subdomain/path.",
|
||||
)
|
||||
|
||||
logger.debug(
|
||||
@@ -178,7 +174,7 @@ def update_cart_item(
|
||||
"session_id": session_id,
|
||||
"product_id": product_id,
|
||||
"quantity": cart_data.quantity,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
result = cart_service.update_cart_item(
|
||||
@@ -186,13 +182,15 @@ def update_cart_item(
|
||||
vendor_id=vendor.id,
|
||||
session_id=session_id,
|
||||
product_id=product_id,
|
||||
quantity=cart_data.quantity
|
||||
quantity=cart_data.quantity,
|
||||
)
|
||||
|
||||
return CartOperationResponse(**result)
|
||||
|
||||
|
||||
@router.delete("/cart/{session_id}/items/{product_id}", response_model=CartOperationResponse)
|
||||
@router.delete(
|
||||
"/cart/{session_id}/items/{product_id}", response_model=CartOperationResponse
|
||||
)
|
||||
def remove_from_cart(
|
||||
request: Request,
|
||||
session_id: str = Path(..., description="Shopping session ID"),
|
||||
@@ -210,12 +208,12 @@ def remove_from_cart(
|
||||
- product_id: ID of product to remove
|
||||
"""
|
||||
# Get vendor from middleware
|
||||
vendor = getattr(request.state, 'vendor', None)
|
||||
vendor = getattr(request.state, "vendor", None)
|
||||
|
||||
if not vendor:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Vendor not found. Please access via vendor domain/subdomain/path."
|
||||
detail="Vendor not found. Please access via vendor domain/subdomain/path.",
|
||||
)
|
||||
|
||||
logger.debug(
|
||||
@@ -225,14 +223,11 @@ def remove_from_cart(
|
||||
"vendor_code": vendor.subdomain,
|
||||
"session_id": session_id,
|
||||
"product_id": product_id,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
result = cart_service.remove_from_cart(
|
||||
db=db,
|
||||
vendor_id=vendor.id,
|
||||
session_id=session_id,
|
||||
product_id=product_id
|
||||
db=db, vendor_id=vendor.id, session_id=session_id, product_id=product_id
|
||||
)
|
||||
|
||||
return CartOperationResponse(**result)
|
||||
@@ -254,12 +249,12 @@ def clear_cart(
|
||||
- session_id: Unique session identifier for the cart
|
||||
"""
|
||||
# Get vendor from middleware
|
||||
vendor = getattr(request.state, 'vendor', None)
|
||||
vendor = getattr(request.state, "vendor", None)
|
||||
|
||||
if not vendor:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Vendor not found. Please access via vendor domain/subdomain/path."
|
||||
detail="Vendor not found. Please access via vendor domain/subdomain/path.",
|
||||
)
|
||||
|
||||
logger.debug(
|
||||
@@ -268,13 +263,9 @@ def clear_cart(
|
||||
"vendor_id": vendor.id,
|
||||
"vendor_code": vendor.subdomain,
|
||||
"session_id": session_id,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
result = cart_service.clear_cart(
|
||||
db=db,
|
||||
vendor_id=vendor.id,
|
||||
session_id=session_id
|
||||
)
|
||||
result = cart_service.clear_cart(db=db, vendor_id=vendor.id, session_id=session_id)
|
||||
|
||||
return ClearCartResponse(**result)
|
||||
|
||||
Reference in New Issue
Block a user