fixing DQ issues

This commit is contained in:
2025-09-19 16:54:13 +02:00
parent 0ce708cf09
commit f042616fdd
45 changed files with 3625 additions and 68 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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()

View File

@@ -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

View File

@@ -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()