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

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