fixing DQ issues

This commit is contained in:
2025-09-14 15:47:38 +02:00
parent 3eb18ef91e
commit 0ce708cf09
27 changed files with 430 additions and 214 deletions

View File

@@ -1,3 +1,12 @@
# app/services/product_service.py
"""Summary description ....
This module provides classes and functions for:
- ....
- ....
- ....
"""
import logging
from datetime import datetime
from typing import Generator, List, Optional
@@ -15,11 +24,12 @@ logger = logging.getLogger(__name__)
class ProductService:
def __init__(self):
"""Class constructor."""
self.gtin_processor = GTINProcessor()
self.price_processor = PriceProcessor()
def create_product(self, db: Session, product_data: ProductCreate) -> Product:
"""Create a new product with validation"""
"""Create a new product with validation."""
try:
# Process and validate GTIN if provided
if product_data.gtin:
@@ -59,7 +69,7 @@ class ProductService:
raise
def get_product_by_id(self, db: Session, product_id: str) -> Optional[Product]:
"""Get a product by its ID"""
"""Get a product by its ID."""
return db.query(Product).filter(Product.product_id == product_id).first()
def get_products_with_filters(
@@ -74,7 +84,7 @@ class ProductService:
shop_name: Optional[str] = None,
search: Optional[str] = None,
) -> tuple[List[Product], int]:
"""Get products with filtering and pagination"""
"""Get products with filtering and pagination."""
query = db.query(Product)
# Apply filters
@@ -106,7 +116,7 @@ class ProductService:
def update_product(
self, db: Session, product_id: str, product_update: ProductUpdate
) -> Product:
"""Update product with validation"""
"""Update product with validation."""
product = db.query(Product).filter(Product.product_id == product_id).first()
if not product:
raise ValueError("Product not found")
@@ -141,7 +151,7 @@ class ProductService:
return product
def delete_product(self, db: Session, product_id: str) -> bool:
"""Delete product and associated stock"""
"""Delete product and associated stock."""
product = db.query(Product).filter(Product.product_id == product_id).first()
if not product:
raise ValueError("Product not found")
@@ -157,7 +167,7 @@ class ProductService:
return True
def get_stock_info(self, db: Session, gtin: str) -> Optional[StockSummaryResponse]:
"""Get stock information for a product by GTIN"""
"""Get stock information for a product by GTIN."""
stock_entries = db.query(Stock).filter(Stock.gtin == gtin).all()
if not stock_entries:
return None
@@ -178,7 +188,7 @@ class ProductService:
marketplace: Optional[str] = None,
shop_name: Optional[str] = None,
) -> Generator[str, None, None]:
"""Generate CSV export with streaming for memory efficiency"""
"""Generate CSV export with streaming for memory efficiency."""
# CSV header
yield (
"product_id,title,description,link,image_link,availability,price,currency,brand,"
@@ -214,7 +224,7 @@ class ProductService:
offset += batch_size
def product_exists(self, db: Session, product_id: str) -> bool:
"""Check if product exists by ID"""
"""Check if product exists by ID."""
return (
db.query(Product).filter(Product.product_id == product_id).first()
is not None