code quality run

This commit is contained in:
2025-09-13 21:58:54 +02:00
parent 0dfd885847
commit 3eb18ef91e
63 changed files with 1802 additions and 1289 deletions

View File

@@ -1,17 +1,21 @@
import logging
from datetime import datetime
from typing import List, Optional
from fastapi import APIRouter, Depends, HTTPException, Query, BackgroundTasks
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException, Query
from sqlalchemy.orm import Session
from app.core.database import get_db
from app.api.deps import get_current_user, get_user_shop
from app.core.database import get_db
from app.services.shop_service import shop_service
from app.tasks.background_tasks import process_marketplace_import
from middleware.decorators import rate_limit
from models.api_models import MarketplaceImportJobResponse, MarketplaceImportRequest, ShopResponse, ShopCreate, \
ShopListResponse, ShopProductResponse, ShopProductCreate
from models.database_models import User, MarketplaceImportJob, Shop, Product, ShopProduct
from datetime import datetime
import logging
from models.api_models import (MarketplaceImportJobResponse,
MarketplaceImportRequest, ShopCreate,
ShopListResponse, ShopProductCreate,
ShopProductResponse, ShopResponse)
from models.database_models import (MarketplaceImportJob, Product, Shop,
ShopProduct, User)
router = APIRouter()
logger = logging.getLogger(__name__)
@@ -20,13 +24,15 @@ logger = logging.getLogger(__name__)
# Shop Management Routes
@router.post("/shop", response_model=ShopResponse)
def create_shop(
shop_data: ShopCreate,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user)
shop_data: ShopCreate,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user),
):
"""Create a new shop (Protected)"""
try:
shop = shop_service.create_shop(db=db, shop_data=shop_data, current_user=current_user)
shop = shop_service.create_shop(
db=db, shop_data=shop_data, current_user=current_user
)
return ShopResponse.model_validate(shop)
except HTTPException:
raise
@@ -37,12 +43,12 @@ def create_shop(
@router.get("/shop", response_model=ShopListResponse)
def get_shops(
skip: int = Query(0, ge=0),
limit: int = Query(100, ge=1, le=1000),
active_only: bool = Query(True),
verified_only: bool = Query(False),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user)
skip: int = Query(0, ge=0),
limit: int = Query(100, ge=1, le=1000),
active_only: bool = Query(True),
verified_only: bool = Query(False),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user),
):
"""Get shops with filtering (Protected)"""
try:
@@ -52,15 +58,10 @@ def get_shops(
skip=skip,
limit=limit,
active_only=active_only,
verified_only=verified_only
verified_only=verified_only,
)
return ShopListResponse(
shops=shops,
total=total,
skip=skip,
limit=limit
)
return ShopListResponse(shops=shops, total=total, skip=skip, limit=limit)
except HTTPException:
raise
except Exception as e:
@@ -69,10 +70,16 @@ def get_shops(
@router.get("/shop/{shop_code}", response_model=ShopResponse)
def get_shop(shop_code: str, db: Session = Depends(get_db), current_user: User = Depends(get_current_user)):
def get_shop(
shop_code: str,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user),
):
"""Get shop details (Protected)"""
try:
shop = shop_service.get_shop_by_code(db=db, shop_code=shop_code, current_user=current_user)
shop = shop_service.get_shop_by_code(
db=db, shop_code=shop_code, current_user=current_user
)
return ShopResponse.model_validate(shop)
except HTTPException:
raise
@@ -84,10 +91,10 @@ def get_shop(shop_code: str, db: Session = Depends(get_db), current_user: User =
# Shop Product Management
@router.post("/shop/{shop_code}/products", response_model=ShopProductResponse)
def add_product_to_shop(
shop_code: str,
shop_product: ShopProductCreate,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user)
shop_code: str,
shop_product: ShopProductCreate,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user),
):
"""Add existing product to shop catalog with shop-specific settings (Protected)"""
try:
@@ -96,9 +103,7 @@ def add_product_to_shop(
# Add product to shop
new_shop_product = shop_service.add_product_to_shop(
db=db,
shop=shop,
shop_product=shop_product
db=db, shop=shop, shop_product=shop_product
)
# Return with product details
@@ -114,18 +119,20 @@ def add_product_to_shop(
@router.get("/shop/{shop_code}/products")
def get_shop_products(
shop_code: str,
skip: int = Query(0, ge=0),
limit: int = Query(100, ge=1, le=1000),
active_only: bool = Query(True),
featured_only: bool = Query(False),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user)
shop_code: str,
skip: int = Query(0, ge=0),
limit: int = Query(100, ge=1, le=1000),
active_only: bool = Query(True),
featured_only: bool = Query(False),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user),
):
"""Get products in shop catalog (Protected)"""
try:
# Get shop
shop = shop_service.get_shop_by_code(db=db, shop_code=shop_code, current_user=current_user)
shop = shop_service.get_shop_by_code(
db=db, shop_code=shop_code, current_user=current_user
)
# Get shop products
shop_products, total = shop_service.get_shop_products(
@@ -135,7 +142,7 @@ def get_shop_products(
skip=skip,
limit=limit,
active_only=active_only,
featured_only=featured_only
featured_only=featured_only,
)
# Format response
@@ -150,7 +157,7 @@ def get_shop_products(
"total": total,
"skip": skip,
"limit": limit,
"shop": ShopResponse.model_validate(shop)
"shop": ShopResponse.model_validate(shop),
}
except HTTPException:
raise