fixing DQ issues
This commit is contained in:
@@ -16,11 +16,8 @@ from sqlalchemy.orm import Session
|
||||
from app.api.deps import get_current_admin_user
|
||||
from app.core.database import get_db
|
||||
from app.services.admin_service import admin_service
|
||||
from models.api_models import (
|
||||
MarketplaceImportJobResponse,
|
||||
ShopListResponse,
|
||||
UserResponse,
|
||||
)
|
||||
from models.api_models import (MarketplaceImportJobResponse, ShopListResponse,
|
||||
UserResponse)
|
||||
from models.database_models import User
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -15,7 +15,8 @@ from sqlalchemy.orm import Session
|
||||
from app.api.deps import get_current_user
|
||||
from app.core.database import get_db
|
||||
from app.services.auth_service import auth_service
|
||||
from models.api_models import LoginResponse, UserLogin, UserRegister, UserResponse
|
||||
from models.api_models import (LoginResponse, UserLogin, UserRegister,
|
||||
UserResponse)
|
||||
from models.database_models import User
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -18,7 +18,8 @@ from app.core.database import get_db
|
||||
from app.services.marketplace_service import marketplace_service
|
||||
from app.tasks.background_tasks import process_marketplace_import
|
||||
from middleware.decorators import rate_limit
|
||||
from models.api_models import MarketplaceImportJobResponse, MarketplaceImportRequest
|
||||
from models.api_models import (MarketplaceImportJobResponse,
|
||||
MarketplaceImportRequest)
|
||||
from models.database_models import User
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -17,13 +17,9 @@ from sqlalchemy.orm import Session
|
||||
from app.api.deps import get_current_user
|
||||
from app.core.database import get_db
|
||||
from app.services.product_service import product_service
|
||||
from models.api_models import (
|
||||
ProductCreate,
|
||||
ProductDetailResponse,
|
||||
ProductListResponse,
|
||||
ProductResponse,
|
||||
ProductUpdate,
|
||||
)
|
||||
from models.api_models import (ProductCreate, ProductDetailResponse,
|
||||
ProductListResponse, ProductResponse,
|
||||
ProductUpdate)
|
||||
from models.database_models import User
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -15,14 +15,8 @@ from sqlalchemy.orm import Session
|
||||
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 models.api_models import (
|
||||
ShopCreate,
|
||||
ShopListResponse,
|
||||
ShopProductCreate,
|
||||
ShopProductResponse,
|
||||
ShopResponse,
|
||||
)
|
||||
from models.api_models import (ShopCreate, ShopListResponse, ShopProductCreate,
|
||||
ShopProductResponse, ShopResponse)
|
||||
from models.database_models import User
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -16,10 +16,7 @@ from sqlalchemy.orm import Session
|
||||
from app.api.deps import get_current_user
|
||||
from app.core.database import get_db
|
||||
from app.services.stats_service import stats_service
|
||||
from models.api_models import (
|
||||
MarketplaceStatsResponse,
|
||||
StatsResponse,
|
||||
)
|
||||
from models.api_models import MarketplaceStatsResponse, StatsResponse
|
||||
from models.database_models import User
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -16,13 +16,8 @@ from sqlalchemy.orm import Session
|
||||
from app.api.deps import get_current_user
|
||||
from app.core.database import get_db
|
||||
from app.services.stock_service import stock_service
|
||||
from models.api_models import (
|
||||
StockAdd,
|
||||
StockCreate,
|
||||
StockResponse,
|
||||
StockSummaryResponse,
|
||||
StockUpdate,
|
||||
)
|
||||
from models.api_models import (StockAdd, StockCreate, StockResponse,
|
||||
StockSummaryResponse, StockUpdate)
|
||||
from models.database_models import User
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -29,7 +29,7 @@ class AuthService:
|
||||
|
||||
def register_user(self, db: Session, user_data: UserRegister) -> User:
|
||||
"""
|
||||
Register a new user
|
||||
Register a new user.
|
||||
|
||||
Args:
|
||||
db: Database session
|
||||
|
||||
@@ -22,12 +22,14 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MarketplaceService:
|
||||
"""Service class for Marketplace operations following the application's service pattern."""
|
||||
|
||||
def __init__(self):
|
||||
"""Class constructor."""
|
||||
pass
|
||||
|
||||
def validate_shop_access(self, db: Session, shop_code: str, user: User) -> Shop:
|
||||
"""Validate that the shop exists and user has access to it"""
|
||||
"""Validate that the shop exists and user has access to it."""
|
||||
# Explicit type hint to help type checker shop: Optional[Shop]
|
||||
# Use case-insensitive query to handle both uppercase and lowercase codes
|
||||
shop: Optional[Shop] = (
|
||||
@@ -67,7 +69,8 @@ class MarketplaceService:
|
||||
db.refresh(import_job)
|
||||
|
||||
logger.info(
|
||||
f"Created marketplace import job {import_job.id}: {request.marketplace} -> {shop.shop_name} (shop_code: {shop.shop_code}) by user {user.username}"
|
||||
f"Created marketplace import job {import_job.id}: "
|
||||
f"{request.marketplace} -> {shop.shop_name} (shop_code: {shop.shop_code}) by user {user.username}"
|
||||
)
|
||||
|
||||
return import_job
|
||||
|
||||
@@ -23,6 +23,8 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ProductService:
|
||||
"""Service class for Product operations following the application's service pattern."""
|
||||
|
||||
def __init__(self):
|
||||
"""Class constructor."""
|
||||
self.gtin_processor = GTINProcessor()
|
||||
|
||||
@@ -8,7 +8,6 @@ This module provides classes and functions for:
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from fastapi import HTTPException
|
||||
@@ -28,7 +27,7 @@ class ShopService:
|
||||
self, db: Session, shop_data: ShopCreate, current_user: User
|
||||
) -> Shop:
|
||||
"""
|
||||
Create a new shop
|
||||
Create a new shop.
|
||||
|
||||
Args:
|
||||
db: Database session
|
||||
@@ -256,19 +255,19 @@ class ShopService:
|
||||
return shop_products, total
|
||||
|
||||
def get_shop_by_id(self, db: Session, shop_id: int) -> Optional[Shop]:
|
||||
"""Get shop by ID"""
|
||||
"""Get shop by ID."""
|
||||
return db.query(Shop).filter(Shop.id == shop_id).first()
|
||||
|
||||
def shop_code_exists(self, db: Session, shop_code: str) -> bool:
|
||||
"""Check if shop code already exists"""
|
||||
"""Check if shop code already exists."""
|
||||
return db.query(Shop).filter(Shop.shop_code == shop_code).first() is not None
|
||||
|
||||
def get_product_by_id(self, db: Session, product_id: str) -> Optional[Product]:
|
||||
"""Get product by product_id"""
|
||||
"""Get product by product_id."""
|
||||
return db.query(Product).filter(Product.product_id == product_id).first()
|
||||
|
||||
def product_in_shop(self, db: Session, shop_id: int, product_id: int) -> bool:
|
||||
"""Check if product is already in shop"""
|
||||
"""Check if product is already in shop."""
|
||||
return (
|
||||
db.query(ShopProduct)
|
||||
.filter(
|
||||
@@ -279,11 +278,11 @@ class ShopService:
|
||||
)
|
||||
|
||||
def is_shop_owner(self, shop: Shop, user: User) -> bool:
|
||||
"""Check if user is shop owner"""
|
||||
"""Check if user is shop owner."""
|
||||
return shop.owner_id == user.id
|
||||
|
||||
def can_view_shop(self, shop: Shop, user: User) -> bool:
|
||||
"""Check if user can view shop"""
|
||||
"""Check if user can view shop."""
|
||||
if user.role == "admin" or self.is_shop_owner(shop, user):
|
||||
return True
|
||||
return shop.is_active and shop.is_verified
|
||||
|
||||
@@ -23,6 +23,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
class StockService:
|
||||
"""Service class for stock operations following the application's service pattern."""
|
||||
|
||||
def __init__(self):
|
||||
"""Class constructor."""
|
||||
self.gtin_processor = GTINProcessor()
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
# app/tasks/background_tasks.py
|
||||
"""Summary description ....
|
||||
|
||||
This module provides classes and functions for:
|
||||
- ....
|
||||
- ....
|
||||
- ....
|
||||
"""
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
@@ -12,7 +20,7 @@ logger = logging.getLogger(__name__)
|
||||
async def process_marketplace_import(
|
||||
job_id: int, url: str, marketplace: str, shop_name: str, batch_size: int = 1000
|
||||
):
|
||||
"""Background task to process marketplace CSV import"""
|
||||
"""Background task to process marketplace CSV import."""
|
||||
db = SessionLocal()
|
||||
csv_processor = CSVProcessor()
|
||||
job = None # Initialize job variable
|
||||
|
||||
Reference in New Issue
Block a user