refactor(api): introduce UserContext schema for API dependency injection

Replace direct User database model imports in API endpoints with UserContext
schema, following the architecture principle that API routes should not import
database models directly.

Changes:
- Create UserContext schema in models/schema/auth.py with from_user() factory
- Update app/api/deps.py to return UserContext from all auth dependencies
- Add _get_user_model() helper for functions needing User model access
- Update 58 API endpoint files to use UserContext instead of User
- Add noqa comments for 4 legitimate edge cases (enums, internal helpers)

Architecture validation: 0 errors (down from 61), 11 warnings remain

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-30 20:47:33 +01:00
parent 1ad30bd77e
commit cad862f469
60 changed files with 755 additions and 589 deletions

View File

@@ -23,7 +23,8 @@ from app.api.deps import get_current_super_admin, get_current_super_admin_api
from app.core.database import get_db
from app.exceptions import ValidationException
from app.services.admin_platform_service import admin_platform_service
from models.database.user import User
from models.database.user import User # noqa: API-007 - Internal helper uses User model
from models.schema.auth import UserContext
router = APIRouter(prefix="/admin-users")
logger = logging.getLogger(__name__)
@@ -142,7 +143,7 @@ def list_admin_users(
limit: int = Query(100, ge=1, le=500),
include_super_admins: bool = Query(True),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_super_admin),
current_admin: UserContext = Depends(get_current_super_admin),
):
"""
List all admin users with their platform assignments.
@@ -165,7 +166,7 @@ def list_admin_users(
def create_admin_user(
request: CreateAdminUserRequest,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_super_admin_api),
current_admin: UserContext = Depends(get_current_super_admin_api),
):
"""
Create a new admin user (super admin or platform admin).
@@ -225,7 +226,7 @@ def create_admin_user(
def get_admin_user(
user_id: int = Path(...),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_super_admin),
current_admin: UserContext = Depends(get_current_super_admin),
):
"""
Get admin user details with platform assignments.
@@ -241,7 +242,7 @@ def assign_admin_to_platform(
user_id: int = Path(...),
platform_id: int = Path(...),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_super_admin_api),
current_admin: UserContext = Depends(get_current_super_admin_api),
):
"""
Assign an admin to a platform.
@@ -268,7 +269,7 @@ def remove_admin_from_platform(
user_id: int = Path(...),
platform_id: int = Path(...),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_super_admin_api),
current_admin: UserContext = Depends(get_current_super_admin_api),
):
"""
Remove an admin's access to a platform.
@@ -295,7 +296,7 @@ def toggle_super_admin_status(
user_id: int = Path(...),
request: ToggleSuperAdminRequest = Body(...),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_super_admin_api),
current_admin: UserContext = Depends(get_current_super_admin_api),
):
"""
Promote or demote an admin to/from super admin.
@@ -323,7 +324,7 @@ def toggle_super_admin_status(
def get_admin_platforms(
user_id: int = Path(...),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_super_admin),
current_admin: UserContext = Depends(get_current_super_admin),
):
"""
Get all platforms assigned to an admin.
@@ -349,7 +350,7 @@ def get_admin_platforms(
def toggle_admin_status(
user_id: int = Path(...),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_super_admin_api),
current_admin: UserContext = Depends(get_current_super_admin_api),
):
"""
Toggle admin user active status.
@@ -376,7 +377,7 @@ def toggle_admin_status(
def delete_admin_user(
user_id: int = Path(...),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_super_admin_api),
current_admin: UserContext = Depends(get_current_super_admin_api),
):
"""
Delete an admin user.

View File

@@ -17,7 +17,7 @@ from sqlalchemy.orm import Session
from app.api.deps import get_current_admin_api
from app.core.database import get_db
from app.services.admin_audit_service import admin_audit_service
from models.database.user import User
from models.schema.auth import UserContext
from models.schema.admin import (
AdminAuditLogFilters,
AdminAuditLogListResponse,
@@ -38,7 +38,7 @@ def get_audit_logs(
skip: int = Query(0, ge=0, description="Number of records to skip"),
limit: int = Query(100, ge=1, le=1000, description="Maximum records to return"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get filtered admin audit logs.
@@ -68,7 +68,7 @@ def get_audit_logs(
def get_recent_audit_logs(
limit: int = Query(20, ge=1, le=100),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get recent audit logs (last 20 by default)."""
filters = AdminAuditLogFilters(limit=limit)
@@ -79,7 +79,7 @@ def get_recent_audit_logs(
def get_my_actions(
limit: int = Query(50, ge=1, le=100),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get audit logs for current admin's actions."""
return admin_audit_service.get_recent_actions_by_admin(
@@ -93,7 +93,7 @@ def get_actions_by_target(
target_id: str,
limit: int = Query(50, ge=1, le=100),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get all actions performed on a specific target.

View File

@@ -21,8 +21,8 @@ from app.exceptions import InsufficientPermissionsException, InvalidCredentialsE
from app.services.admin_platform_service import admin_platform_service
from app.services.auth_service import auth_service
from middleware.auth import AuthManager
from models.database.platform import Platform
from models.database.user import User
from models.database.platform import Platform # noqa: API-007 - Admin needs to query platforms
from models.schema.auth import UserContext
from models.schema.auth import LoginResponse, LogoutResponse, UserLogin, UserResponse
router = APIRouter(prefix="/auth")
@@ -85,7 +85,7 @@ def admin_login(
@router.get("/me", response_model=UserResponse)
def get_current_admin(current_user: User = Depends(get_current_admin_api)):
def get_current_admin(current_user: UserContext = Depends(get_current_admin_api)):
"""
Get current authenticated admin user.
@@ -131,7 +131,7 @@ def admin_logout(response: Response):
@router.get("/accessible-platforms")
def get_accessible_platforms(
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_from_cookie_or_header),
current_user: UserContext = Depends(get_current_admin_from_cookie_or_header),
):
"""
Get list of platforms this admin can access.
@@ -165,7 +165,7 @@ def select_platform(
platform_id: int,
response: Response,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_from_cookie_or_header),
current_user: UserContext = Depends(get_current_admin_from_cookie_or_header),
):
"""
Select platform context for platform admin.

View File

@@ -13,7 +13,7 @@ from sqlalchemy.orm import Session
from app.api.deps import get_current_admin_api
from app.core.database import get_db
from app.services.background_tasks_service import background_tasks_service
from models.database.user import User
from models.schema.auth import UserContext
router = APIRouter()
@@ -156,7 +156,7 @@ async def list_background_tasks(
),
limit: int = Query(50, ge=1, le=200),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
List all background tasks across the system
@@ -198,7 +198,7 @@ async def list_background_tasks(
@router.get("/tasks/stats", response_model=BackgroundTasksStatsResponse)
async def get_background_tasks_stats(
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Get statistics for background tasks
@@ -236,7 +236,7 @@ async def get_background_tasks_stats(
@router.get("/tasks/running", response_model=list[BackgroundTaskResponse])
async def list_running_tasks(
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
List currently running background tasks

View File

@@ -20,7 +20,7 @@ from app.services.code_quality_service import (
)
from app.tasks.code_quality_tasks import execute_code_quality_scan
from app.modules.dev_tools.models import ArchitectureScan
from models.database.user import User
from models.schema.auth import UserContext
from app.modules.analytics.schemas import CodeQualityDashboardStatsResponse
router = APIRouter()
@@ -197,7 +197,7 @@ async def trigger_scan(
request: ScanRequest = None,
background_tasks: BackgroundTasks = None,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Trigger code quality scan(s) as background tasks.
@@ -255,7 +255,7 @@ async def trigger_scan(
async def get_scan_status(
scan_id: int,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Get status of a specific scan.
@@ -272,7 +272,7 @@ async def get_scan_status(
@router.get("/scans/running", response_model=list[ScanResponse])
async def get_running_scans(
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Get all currently running scans.
@@ -290,7 +290,7 @@ async def list_scans(
None, description="Filter by validator type"
),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Get scan history
@@ -326,7 +326,7 @@ async def list_violations(
page: int = Query(1, ge=1, description="Page number"),
page_size: int = Query(50, ge=1, le=200, description="Items per page"),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Get violations with filtering and pagination
@@ -384,7 +384,7 @@ async def list_violations(
async def get_violation(
violation_id: int,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Get single violation with details
@@ -450,7 +450,7 @@ async def assign_violation(
violation_id: int,
request: AssignViolationRequest,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Assign violation to a developer
@@ -483,7 +483,7 @@ async def resolve_violation(
violation_id: int,
request: ResolveViolationRequest,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Mark violation as resolved
@@ -515,7 +515,7 @@ async def ignore_violation(
violation_id: int,
request: IgnoreViolationRequest,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Mark violation as ignored (won't fix)
@@ -547,7 +547,7 @@ async def add_comment(
violation_id: int,
request: AddCommentRequest,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Add comment to violation
@@ -577,7 +577,7 @@ async def get_dashboard_stats(
None, description="Filter by validator type (returns combined stats if not specified)"
),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Get dashboard statistics
@@ -602,7 +602,7 @@ async def get_dashboard_stats(
@router.get("/validator-types")
async def get_validator_types(
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Get list of available validator types

View File

@@ -13,7 +13,7 @@ from app.api.deps import get_current_admin_api
from app.core.database import get_db
from app.exceptions import CompanyHasVendorsException, ConfirmationRequiredException
from app.services.company_service import company_service
from models.database.user import User
from models.schema.auth import UserContext
from models.schema.company import (
CompanyCreate,
CompanyCreateResponse,
@@ -33,7 +33,7 @@ logger = logging.getLogger(__name__)
def create_company_with_owner(
company_data: CompanyCreate,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Create a new company with owner user account (Admin only).
@@ -87,7 +87,7 @@ def get_all_companies(
is_active: bool | None = Query(None),
is_verified: bool | None = Query(None),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get all companies with filtering (Admin only)."""
companies, total = company_service.get_companies(
@@ -128,7 +128,7 @@ def get_all_companies(
def get_company_details(
company_id: int = Path(..., description="Company ID"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get detailed company information including vendor counts (Admin only).
@@ -179,7 +179,7 @@ def update_company(
company_id: int = Path(..., description="Company ID"),
company_update: CompanyUpdate = Body(...),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Update company information (Admin only).
@@ -218,7 +218,7 @@ def toggle_company_verification(
company_id: int = Path(..., description="Company ID"),
verification_data: dict = Body(..., example={"is_verified": True}),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Toggle company verification status (Admin only).
@@ -251,7 +251,7 @@ def toggle_company_status(
company_id: int = Path(..., description="Company ID"),
status_data: dict = Body(..., example={"is_active": True}),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Toggle company active status (Admin only).
@@ -287,7 +287,7 @@ def transfer_company_ownership(
company_id: int = Path(..., description="Company ID"),
transfer_data: CompanyTransferOwnership = Body(...),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Transfer company ownership to another user (Admin only).
@@ -333,7 +333,7 @@ def delete_company(
company_id: int = Path(..., description="Company ID"),
confirm: bool = Query(False, description="Must be true to confirm deletion"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Delete company and all associated vendors (Admin only).

View File

@@ -11,7 +11,7 @@ from sqlalchemy.orm import Session
from app.api.deps import get_current_admin_api
from app.core.database import get_db
from app.services.admin_customer_service import admin_customer_service
from models.database.user import User
from models.schema.auth import UserContext
from app.modules.customers.schemas import (
CustomerDetailResponse,
CustomerListResponse,
@@ -35,7 +35,7 @@ def list_customers(
skip: int = Query(0, ge=0),
limit: int = Query(20, ge=1, le=100),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> CustomerListResponse:
"""
Get paginated list of customers across all vendors.
@@ -68,7 +68,7 @@ def list_customers(
def get_customer_stats(
vendor_id: int | None = Query(None, description="Filter by vendor ID"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> CustomerStatisticsResponse:
"""Get customer statistics."""
stats = admin_customer_service.get_customer_stats(db=db, vendor_id=vendor_id)
@@ -84,7 +84,7 @@ def get_customer_stats(
def get_customer(
customer_id: int,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> CustomerDetailResponse:
"""Get customer details by ID."""
customer = admin_customer_service.get_customer(db=db, customer_id=customer_id)
@@ -100,7 +100,7 @@ def get_customer(
def toggle_customer_status(
customer_id: int,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> CustomerMessageResponse:
"""Toggle customer active status."""
result = admin_customer_service.toggle_customer_status(

View File

@@ -12,7 +12,7 @@ from app.api.deps import get_current_admin_api
from app.core.database import get_db
from app.services.admin_service import admin_service
from app.services.stats_service import stats_service
from models.database.user import User
from models.schema.auth import UserContext
from app.modules.analytics.schemas import (
AdminDashboardResponse,
ImportStatsResponse,
@@ -32,7 +32,7 @@ logger = logging.getLogger(__name__)
@router.get("", response_model=AdminDashboardResponse)
def get_admin_dashboard(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get admin dashboard with platform statistics (Admin only)."""
user_stats = stats_service.get_user_statistics(db)
@@ -62,7 +62,7 @@ def get_admin_dashboard(
@router.get("/stats", response_model=StatsResponse)
def get_comprehensive_stats(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get comprehensive platform statistics (Admin only)."""
stats_data = stats_service.get_comprehensive_stats(db=db)
@@ -81,7 +81,7 @@ def get_comprehensive_stats(
@router.get("/stats/marketplace", response_model=list[MarketplaceStatsResponse])
def get_marketplace_stats(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get statistics broken down by marketplace (Admin only)."""
marketplace_stats = stats_service.get_marketplace_breakdown_stats(db=db)
@@ -100,7 +100,7 @@ def get_marketplace_stats(
@router.get("/stats/platform", response_model=PlatformStatsResponse)
def get_platform_statistics(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get comprehensive platform statistics (Admin only)."""
user_stats = stats_service.get_user_statistics(db)

View File

@@ -22,7 +22,7 @@ from app.core.database import get_db
from app.exceptions.base import ResourceNotFoundException, ValidationException
from app.services.email_service import EmailService
from app.services.email_template_service import EmailTemplateService
from models.database.user import User
from models.schema.auth import UserContext
router = APIRouter(prefix="/email-templates")
logger = logging.getLogger(__name__)
@@ -92,7 +92,7 @@ class CategoriesResponse(BaseModel):
@router.get("", response_model=TemplateListResponse)
def list_templates(
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""
@@ -106,7 +106,7 @@ def list_templates(
@router.get("/categories", response_model=CategoriesResponse)
def get_categories(
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""Get list of email template categories."""
@@ -117,7 +117,7 @@ def get_categories(
@router.get("/{code}")
def get_template(
code: str,
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""
@@ -133,7 +133,7 @@ def get_template(
def get_template_language(
code: str,
language: str,
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""
@@ -164,7 +164,7 @@ def update_template(
code: str,
language: str,
template_data: TemplateUpdate,
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""
@@ -189,7 +189,7 @@ def update_template(
def preview_template(
code: str,
preview_data: PreviewRequest,
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""
@@ -212,7 +212,7 @@ def preview_template(
def send_test_email(
code: str,
test_data: TestEmailRequest,
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""
@@ -258,7 +258,7 @@ def get_template_logs(
code: str,
limit: int = 50,
offset: int = 0,
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""

View File

@@ -18,7 +18,7 @@ from sqlalchemy.orm import Session
from app.api.deps import get_current_admin_api
from app.core.database import get_db
from app.services.feature_service import feature_service
from models.database.user import User
from models.schema.auth import UserContext
router = APIRouter(prefix="/features")
logger = logging.getLogger(__name__)
@@ -145,7 +145,7 @@ def _feature_to_response(feature) -> FeatureResponse:
def list_features(
category: str | None = Query(None, description="Filter by category"),
active_only: bool = Query(False, description="Only active features"),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""List all features with their tier assignments."""
@@ -161,7 +161,7 @@ def list_features(
@router.get("/categories", response_model=CategoryListResponse)
def list_categories(
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""List all feature categories."""
@@ -171,7 +171,7 @@ def list_categories(
@router.get("/tiers", response_model=TierListWithFeaturesResponse)
def list_tiers_with_features(
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""List all tiers with their feature assignments."""
@@ -195,7 +195,7 @@ def list_tiers_with_features(
@router.get("/{feature_code}", response_model=FeatureResponse)
def get_feature(
feature_code: str,
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""
@@ -217,7 +217,7 @@ def get_feature(
def update_feature(
feature_code: str,
request: UpdateFeatureRequest,
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""
@@ -253,7 +253,7 @@ def update_feature(
def update_tier_features(
tier_code: str,
request: UpdateTierFeaturesRequest,
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""
@@ -282,7 +282,7 @@ def update_tier_features(
@router.get("/tiers/{tier_code}/features", response_model=TierFeatureDetailResponse)
def get_tier_features(
tier_code: str,
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""

View File

@@ -14,7 +14,7 @@ from fastapi import APIRouter, Depends, File, Form, UploadFile
from app.api.deps import get_current_admin_api
from app.services.image_service import image_service
from models.database.user import User
from models.schema.auth import UserContext
from models.schema.image import (
ImageDeleteResponse,
ImageStorageStats,
@@ -30,7 +30,7 @@ async def upload_image(
file: UploadFile = File(...),
vendor_id: int = Form(...),
product_id: int | None = Form(None),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Upload and process an image.
@@ -67,7 +67,7 @@ async def upload_image(
@router.delete("/{image_hash}", response_model=ImageDeleteResponse)
async def delete_image(
image_hash: str,
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Delete an image and all its variants.
@@ -88,7 +88,7 @@ async def delete_image(
@router.get("/stats", response_model=ImageStorageStats)
async def get_storage_stats(
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get image storage statistics.

View File

@@ -23,7 +23,7 @@ from app.core.database import get_db
from app.services.inventory_import_service import inventory_import_service
from app.services.inventory_service import inventory_service
from app.services.inventory_transaction_service import inventory_transaction_service
from models.database.user import User
from models.schema.auth import UserContext
from app.modules.inventory.schemas import (
AdminInventoryAdjust,
AdminInventoryCreate,
@@ -61,7 +61,7 @@ def get_all_inventory(
low_stock: int | None = Query(None, ge=0, description="Filter items below threshold"),
search: str | None = Query(None, description="Search by product title or SKU"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get inventory across all vendors with filtering.
@@ -82,7 +82,7 @@ def get_all_inventory(
@router.get("/stats", response_model=AdminInventoryStats)
def get_inventory_stats(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get platform-wide inventory statistics."""
return inventory_service.get_inventory_stats_admin(db)
@@ -94,7 +94,7 @@ def get_low_stock_items(
vendor_id: int | None = Query(None, description="Filter by vendor"),
limit: int = Query(50, ge=1, le=200),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get items with low stock levels."""
return inventory_service.get_low_stock_items_admin(
@@ -108,7 +108,7 @@ def get_low_stock_items(
@router.get("/vendors", response_model=AdminVendorsWithInventoryResponse)
def get_vendors_with_inventory(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get list of vendors that have inventory entries."""
return inventory_service.get_vendors_with_inventory_admin(db)
@@ -118,7 +118,7 @@ def get_vendors_with_inventory(
def get_inventory_locations(
vendor_id: int | None = Query(None, description="Filter by vendor"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get list of unique inventory locations."""
return inventory_service.get_inventory_locations_admin(db, vendor_id)
@@ -137,7 +137,7 @@ def get_vendor_inventory(
location: str | None = Query(None, description="Filter by location"),
low_stock: int | None = Query(None, ge=0, description="Filter items below threshold"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get inventory for a specific vendor."""
return inventory_service.get_vendor_inventory_admin(
@@ -154,7 +154,7 @@ def get_vendor_inventory(
def get_product_inventory(
product_id: int,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get inventory summary for a specific product across all locations."""
return inventory_service.get_product_inventory_admin(db, product_id)
@@ -169,7 +169,7 @@ def get_product_inventory(
def set_inventory(
inventory_data: AdminInventoryCreate,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Set exact inventory quantity for a product at a location.
@@ -205,7 +205,7 @@ def set_inventory(
def adjust_inventory(
adjustment: AdminInventoryAdjust,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Adjust inventory by adding or removing quantity.
@@ -245,7 +245,7 @@ def update_inventory(
inventory_id: int,
inventory_update: InventoryUpdate,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Update inventory entry fields."""
# Get inventory to find vendor_id
@@ -268,7 +268,7 @@ def update_inventory(
def delete_inventory(
inventory_id: int,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Delete inventory entry."""
# Get inventory to find vendor_id and log details
@@ -324,7 +324,7 @@ async def import_inventory(
warehouse: str = Form("strassen", description="Warehouse name"),
clear_existing: bool = Form(False, description="Clear existing inventory before import"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Import inventory from a TSV/CSV file.
@@ -398,7 +398,7 @@ def get_all_transactions(
transaction_type: str | None = Query(None, description="Filter by type"),
order_id: int | None = Query(None, description="Filter by order"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get inventory transaction history across all vendors.
@@ -426,7 +426,7 @@ def get_all_transactions(
@router.get("/transactions/stats", response_model=AdminTransactionStatsResponse)
def get_transaction_stats(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get transaction statistics for the platform."""
stats = inventory_transaction_service.get_transaction_stats_admin(db)

View File

@@ -32,7 +32,7 @@ from app.services.letzshop import (
VendorNotFoundError,
)
from app.tasks.letzshop_tasks import process_historical_import
from models.database.user import User
from models.schema.auth import UserContext
from app.modules.marketplace.schemas import (
FulfillmentOperationResponse,
LetzshopCachedVendorDetail,
@@ -96,7 +96,7 @@ def list_vendors_letzshop_status(
False, description="Only show vendors with Letzshop configured"
),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
List all vendors with their Letzshop integration status.
@@ -130,7 +130,7 @@ def list_vendors_letzshop_status(
def get_vendor_credentials(
vendor_id: int = Path(..., description="Vendor ID"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get Letzshop credentials for a vendor (API key is masked)."""
order_service = get_order_service(db)
@@ -173,7 +173,7 @@ def create_or_update_vendor_credentials(
vendor_id: int = Path(..., description="Vendor ID"),
credentials_data: LetzshopCredentialsCreate = ...,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Create or update Letzshop credentials for a vendor."""
order_service = get_order_service(db)
@@ -220,7 +220,7 @@ def update_vendor_credentials(
vendor_id: int = Path(..., description="Vendor ID"),
credentials_data: LetzshopCredentialsUpdate = ...,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Partially update Letzshop credentials for a vendor."""
order_service = get_order_service(db)
@@ -269,7 +269,7 @@ def update_vendor_credentials(
def delete_vendor_credentials(
vendor_id: int = Path(..., description="Vendor ID"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Delete Letzshop credentials for a vendor."""
order_service = get_order_service(db)
@@ -308,7 +308,7 @@ def delete_vendor_credentials(
def test_vendor_connection(
vendor_id: int = Path(..., description="Vendor ID"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Test the Letzshop connection for a vendor using stored credentials."""
order_service = get_order_service(db)
@@ -333,7 +333,7 @@ def test_vendor_connection(
def test_api_key(
test_request: LetzshopConnectionTestRequest,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Test a Letzshop API key without saving it."""
creds_service = get_credentials_service(db)
@@ -372,7 +372,7 @@ def list_all_letzshop_orders(
None, description="Search by order number, customer name, or email"
),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
List Letzshop orders across all vendors (or for a specific vendor).
@@ -462,7 +462,7 @@ def list_vendor_letzshop_orders(
None, description="Search by order number, customer name, or email"
),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""List Letzshop orders for a vendor."""
order_service = get_order_service(db)
@@ -543,7 +543,7 @@ def list_vendor_letzshop_orders(
def get_letzshop_order_detail(
order_id: int = Path(..., description="Letzshop order ID"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get detailed information for a single Letzshop order."""
order_service = get_order_service(db)
@@ -623,7 +623,7 @@ def trigger_vendor_sync(
vendor_id: int = Path(..., description="Vendor ID"),
sync_request: LetzshopSyncTriggerRequest = LetzshopSyncTriggerRequest(),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Trigger a sync operation for a vendor.
@@ -721,7 +721,7 @@ def list_all_letzshop_jobs(
skip: int = Query(0, ge=0),
limit: int = Query(20, ge=1, le=100),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get unified list of all Letzshop-related jobs across all vendors.
@@ -753,7 +753,7 @@ def list_vendor_letzshop_jobs(
skip: int = Query(0, ge=0),
limit: int = Query(20, ge=1, le=100),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get unified list of Letzshop-related jobs for a vendor.
@@ -794,7 +794,7 @@ def start_historical_import(
vendor_id: int = Path(..., description="Vendor ID"),
background_tasks: BackgroundTasks = None,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Start historical order import from Letzshop as a background job.
@@ -861,7 +861,7 @@ def get_historical_import_status(
vendor_id: int = Path(..., description="Vendor ID"),
job_id: int = Path(..., description="Import job ID"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get status of a historical import job.
@@ -884,7 +884,7 @@ def get_historical_import_status(
def get_import_summary(
vendor_id: int = Path(..., description="Vendor ID"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get summary statistics for imported Letzshop orders.
@@ -919,7 +919,7 @@ def confirm_order(
vendor_id: int = Path(..., description="Vendor ID"),
order_id: int = Path(..., description="Order ID"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Confirm all inventory units for a Letzshop order.
@@ -1004,7 +1004,7 @@ def reject_order(
vendor_id: int = Path(..., description="Vendor ID"),
order_id: int = Path(..., description="Order ID"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Decline all inventory units for a Letzshop order.
@@ -1079,7 +1079,7 @@ def confirm_single_item(
order_id: int = Path(..., description="Order ID"),
item_id: str = Path(..., description="External Item ID (Letzshop inventory unit ID)"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Confirm a single inventory unit in an order.
@@ -1144,7 +1144,7 @@ def decline_single_item(
order_id: int = Path(..., description="Order ID"),
item_id: str = Path(..., description="External Item ID (Letzshop inventory unit ID)"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Decline a single inventory unit in an order.
@@ -1199,7 +1199,7 @@ def decline_single_item(
def sync_tracking_for_vendor(
vendor_id: int = Path(..., description="Vendor ID"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Sync tracking information from Letzshop for confirmed orders.
@@ -1297,7 +1297,7 @@ def get_vendor_sync_service(db: Session) -> LetzshopVendorSyncService:
def trigger_vendor_directory_sync(
background_tasks: BackgroundTasks,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Trigger a sync of the Letzshop vendor directory.
@@ -1351,7 +1351,7 @@ def trigger_vendor_directory_sync(
)
def get_vendor_directory_stats(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> LetzshopVendorDirectoryStatsResponse:
"""
Get statistics about the Letzshop vendor directory cache.
@@ -1377,7 +1377,7 @@ def list_cached_vendors(
page: int = Query(1, ge=1),
limit: int = Query(20, ge=1, le=100),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> LetzshopCachedVendorListResponse:
"""
List cached Letzshop vendors with search and filtering.
@@ -1429,7 +1429,7 @@ def list_cached_vendors(
def get_cached_vendor_detail(
slug: str = Path(..., description="Letzshop vendor slug"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> LetzshopCachedVendorDetailResponse:
"""
Get detailed information about a cached Letzshop vendor.
@@ -1487,7 +1487,7 @@ def create_vendor_from_letzshop(
slug: str = Path(..., description="Letzshop vendor slug"),
company_id: int = Query(..., description="Company ID to create vendor under"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> LetzshopCreateVendorFromCacheResponse:
"""
Create a platform vendor from a cached Letzshop vendor.

View File

@@ -22,7 +22,7 @@ from app.exceptions import ConfirmationRequiredException, ResourceNotFoundExcept
from app.services.admin_audit_service import admin_audit_service
from app.services.admin_settings_service import admin_settings_service
from app.services.log_service import log_service
from models.database.user import User
from models.schema.auth import UserContext
from models.schema.admin import (
ApplicationLogFilters,
ApplicationLogListResponse,
@@ -56,7 +56,7 @@ def get_database_logs(
skip: int = Query(0, ge=0),
limit: int = Query(100, ge=1, le=1000),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get logs from database with filtering.
@@ -82,7 +82,7 @@ def get_database_logs(
def get_log_statistics(
days: int = Query(7, ge=1, le=90, description="Number of days to analyze"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get log statistics for the last N days.
@@ -97,7 +97,7 @@ def cleanup_old_logs(
retention_days: int = Query(30, ge=1, le=365),
confirm: bool = Query(False, description="Must be true to confirm cleanup"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Delete logs older than retention period.
@@ -129,7 +129,7 @@ def cleanup_old_logs(
def delete_log(
log_id: int,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Delete a specific log entry."""
message = log_service.delete_log(db, log_id)
@@ -154,7 +154,7 @@ def delete_log(
@router.get("/files", response_model=LogFileListResponse)
def list_log_files(
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
List all available log files.
@@ -168,7 +168,7 @@ def list_log_files(
def get_file_log(
filename: str,
lines: int = Query(500, ge=1, le=10000, description="Number of lines to read"),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Read log file content.
@@ -181,7 +181,7 @@ def get_file_log(
@router.get("/files/{filename}/download")
def download_log_file(
filename: str,
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Download log file.
@@ -237,7 +237,7 @@ def download_log_file(
@router.get("/settings", response_model=LogSettingsResponse)
def get_log_settings(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get current log configuration settings."""
log_level = admin_settings_service.get_setting_value(db, "log_level", "INFO")
@@ -271,7 +271,7 @@ def get_log_settings(
def update_log_settings(
settings_update: LogSettingsUpdate,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Update log configuration settings.

View File

@@ -14,7 +14,7 @@ from app.services.marketplace_import_job_service import marketplace_import_job_s
from app.services.stats_service import stats_service
from app.services.vendor_service import vendor_service
from app.tasks.background_tasks import process_marketplace_import
from models.database.user import User
from models.schema.auth import UserContext
from app.modules.marketplace.schemas import (
AdminMarketplaceImportJobListResponse,
AdminMarketplaceImportJobRequest,
@@ -37,7 +37,7 @@ def get_all_marketplace_import_jobs(
page: int = Query(1, ge=1),
limit: int = Query(100, ge=1, le=100),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get all marketplace import jobs with pagination (Admin only)."""
jobs, total = marketplace_import_job_service.get_all_import_jobs_paginated(
@@ -64,7 +64,7 @@ async def create_marketplace_import_job(
request: AdminMarketplaceImportJobRequest,
background_tasks: BackgroundTasks,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Create a new marketplace import job (Admin only).
@@ -122,7 +122,7 @@ async def create_marketplace_import_job(
@router.get("/stats", response_model=ImportStatsResponse)
def get_import_statistics(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get marketplace import statistics (Admin only)."""
stats = stats_service.get_import_statistics(db)
@@ -133,7 +133,7 @@ def get_import_statistics(
def get_marketplace_import_job(
job_id: int,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get a single marketplace import job by ID (Admin only)."""
job = marketplace_import_job_service.get_import_job_by_id_admin(db, job_id)
@@ -147,7 +147,7 @@ def get_import_job_errors(
limit: int = Query(50, ge=1, le=100),
error_type: str | None = Query(None, description="Filter by error type"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get import errors for a specific job (Admin only).

View File

@@ -13,7 +13,7 @@ from sqlalchemy.orm import Session
from app.api.deps import get_current_admin_api
from app.core.database import get_db
from app.services.media_service import media_service
from models.database.user import User
from models.schema.auth import UserContext
from models.schema.media import (
MediaDetailResponse,
MediaItemResponse,
@@ -33,7 +33,7 @@ def get_vendor_media_library(
media_type: str | None = Query(None, description="image, video, document"),
folder: str | None = Query(None, description="Filter by folder"),
search: str | None = Query(None),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""
@@ -64,7 +64,7 @@ async def upload_vendor_media(
vendor_id: int,
file: UploadFile = File(...),
folder: str | None = Query("products", description="products, general, etc."),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""
@@ -98,7 +98,7 @@ async def upload_vendor_media(
def get_vendor_media_detail(
vendor_id: int,
media_id: int,
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""
@@ -118,7 +118,7 @@ def get_vendor_media_detail(
def delete_vendor_media(
vendor_id: int,
media_id: int,
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""

View File

@@ -29,8 +29,8 @@ from app.api.deps import (
)
from app.services.menu_service import MenuItemConfig, menu_service
from app.services.platform_service import platform_service
from models.database.admin_menu_config import FrontendType
from models.database.user import User
from models.database.admin_menu_config import FrontendType # noqa: API-007 - Enum for type safety
from models.schema.auth import UserContext
logger = logging.getLogger(__name__)
router = APIRouter(prefix="/menu-config")
@@ -159,7 +159,7 @@ async def get_platform_menu_config(
FrontendType.ADMIN, description="Frontend type (admin or vendor)"
),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Get menu configuration for a platform.
@@ -188,7 +188,7 @@ async def update_platform_menu_visibility(
FrontendType.ADMIN, description="Frontend type (admin or vendor)"
),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Update visibility for a single menu item for a platform.
@@ -224,7 +224,7 @@ async def bulk_update_platform_menu_visibility(
FrontendType.ADMIN, description="Frontend type (admin or vendor)"
),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Update visibility for multiple menu items at once.
@@ -257,7 +257,7 @@ async def reset_platform_menu_config(
FrontendType.ADMIN, description="Frontend type (admin or vendor)"
),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Reset menu configuration for a platform to defaults.
@@ -287,7 +287,7 @@ async def reset_platform_menu_config(
@router.get("/user", response_model=MenuConfigResponse)
async def get_user_menu_config(
db: Session = Depends(get_db),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Get the current super admin's personal menu configuration.
@@ -309,7 +309,7 @@ async def get_user_menu_config(
async def update_user_menu_visibility(
update_data: MenuVisibilityUpdateRequest,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Update visibility for a single menu item for the current super admin.
@@ -336,7 +336,7 @@ async def update_user_menu_visibility(
@router.post("/user/reset", response_model=MenuActionResponse)
async def reset_user_menu_config(
db: Session = Depends(get_db),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Reset the current super admin's menu configuration (hide all except mandatory).
@@ -356,7 +356,7 @@ async def reset_user_menu_config(
@router.post("/user/show-all", response_model=MenuActionResponse)
async def show_all_user_menu_config(
db: Session = Depends(get_db),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Show all menu items for the current super admin.
@@ -380,7 +380,7 @@ async def show_all_platform_menu_config(
FrontendType.ADMIN, description="Frontend type (admin or vendor)"
),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Show all menu items for a platform.
@@ -409,7 +409,7 @@ async def show_all_platform_menu_config(
@router.get("/render/admin", response_model=RenderedMenuResponse)
async def get_rendered_admin_menu(
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_from_cookie_or_header),
current_user: UserContext = Depends(get_current_admin_from_cookie_or_header),
):
"""
Get the rendered admin menu for the current user.

View File

@@ -46,7 +46,7 @@ from app.modules.messaging.schemas import (
ReopenConversationResponse,
UnreadCountResponse,
)
from models.database.user import User
from models.schema.auth import UserContext
router = APIRouter(prefix="/messages")
logger = logging.getLogger(__name__)
@@ -184,7 +184,7 @@ def list_conversations(
skip: int = Query(0, ge=0),
limit: int = Query(20, ge=1, le=100),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> AdminConversationListResponse:
"""List conversations for admin (admin_vendor and admin_customer channels)."""
conversations, total, total_unread = messaging_service.list_conversations(
@@ -211,7 +211,7 @@ def list_conversations(
@router.get("/unread-count", response_model=UnreadCountResponse)
def get_unread_count(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> UnreadCountResponse:
"""Get total unread message count for header badge."""
count = messaging_service.get_unread_count(
@@ -235,7 +235,7 @@ def get_recipients(
skip: int = Query(0, ge=0),
limit: int = Query(50, ge=1, le=100),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> RecipientListResponse:
"""Get list of available recipients for compose modal."""
if recipient_type == ParticipantType.VENDOR:
@@ -291,7 +291,7 @@ def get_recipients(
def create_conversation(
data: ConversationCreate,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> ConversationDetailResponse:
"""Create a new conversation."""
# Validate conversation type for admin
@@ -428,7 +428,7 @@ def get_conversation(
conversation_id: int,
mark_read: bool = Query(True, description="Automatically mark as read"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> ConversationDetailResponse:
"""Get conversation detail with messages."""
conversation = messaging_service.get_conversation(
@@ -465,7 +465,7 @@ async def send_message(
content: str = Form(...),
files: list[UploadFile] = File(default=[]),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> MessageResponse:
"""Send a message in a conversation, optionally with attachments."""
# Verify access
@@ -522,7 +522,7 @@ async def send_message(
def close_conversation(
conversation_id: int,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> CloseConversationResponse:
"""Close a conversation."""
conversation = messaging_service.close_conversation(
@@ -551,7 +551,7 @@ def close_conversation(
def reopen_conversation(
conversation_id: int,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> ReopenConversationResponse:
"""Reopen a closed conversation."""
conversation = messaging_service.reopen_conversation(
@@ -580,7 +580,7 @@ def reopen_conversation(
def mark_read(
conversation_id: int,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> MarkReadResponse:
"""Mark conversation as read."""
success = messaging_service.mark_conversation_read(
@@ -608,7 +608,7 @@ def update_preferences(
conversation_id: int,
preferences: NotificationPreferencesUpdate,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> PreferencesUpdateResponse:
"""Update notification preferences for a conversation."""
success = messaging_service.update_notification_preferences(

View File

@@ -22,7 +22,7 @@ from app.exceptions import ValidationException
from app.modules.registry import MODULES
from app.modules.service import module_service
from app.services.platform_service import platform_service
from models.database.user import User
from models.schema.auth import UserContext
logger = logging.getLogger(__name__)
router = APIRouter(prefix="/module-config")
@@ -267,7 +267,7 @@ async def get_module_config(
platform_id: int = Path(..., description="Platform ID"),
module_code: str = Path(..., description="Module code"),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Get configuration for a specific module on a platform.
@@ -311,7 +311,7 @@ async def update_module_config(
platform_id: int = Path(..., description="Platform ID"),
module_code: str = Path(..., description="Module code"),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Update configuration for a specific module on a platform.
@@ -354,7 +354,7 @@ async def update_module_config(
@router.get("/defaults/{module_code}", response_model=ConfigDefaultsResponse)
async def get_config_defaults(
module_code: str = Path(..., description="Module code"),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Get default configuration for a module.
@@ -386,7 +386,7 @@ async def reset_module_config(
platform_id: int = Path(..., description="Platform ID"),
module_code: str = Path(..., description="Module code"),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Reset module configuration to defaults.

View File

@@ -22,7 +22,7 @@ from app.api.deps import get_current_super_admin, get_db
from app.modules.registry import MODULES, get_core_module_codes
from app.modules.service import module_service
from app.services.platform_service import platform_service
from models.database.user import User
from models.schema.auth import UserContext
logger = logging.getLogger(__name__)
router = APIRouter(prefix="/modules")
@@ -100,7 +100,7 @@ def _build_module_response(
is_enabled: bool,
) -> ModuleResponse:
"""Build ModuleResponse from module code."""
from models.database.admin_menu_config import FrontendType
from models.database.admin_menu_config import FrontendType # noqa: API-007 - Enum for type safety
module = MODULES.get(code)
if not module:
@@ -127,7 +127,7 @@ def _build_module_response(
@router.get("", response_model=ModuleListResponse)
async def list_all_modules(
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
List all available modules.
@@ -157,7 +157,7 @@ async def list_all_modules(
async def get_platform_modules(
platform_id: int = Path(..., description="Platform ID"),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Get module configuration for a platform.
@@ -202,7 +202,7 @@ async def update_platform_modules(
update_data: EnableModulesRequest,
platform_id: int = Path(..., description="Platform ID"),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Update enabled modules for a platform.
@@ -250,7 +250,7 @@ async def enable_module(
request: ToggleModuleRequest,
platform_id: int = Path(..., description="Platform ID"),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Enable a single module for a platform.
@@ -293,7 +293,7 @@ async def disable_module(
request: ToggleModuleRequest,
platform_id: int = Path(..., description="Platform ID"),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Disable a single module for a platform.
@@ -341,7 +341,7 @@ async def disable_module(
async def enable_all_modules(
platform_id: int = Path(..., description="Platform ID"),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Enable all modules for a platform.
@@ -372,7 +372,7 @@ async def enable_all_modules(
async def disable_optional_modules(
platform_id: int = Path(..., description="Platform ID"),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_super_admin),
current_user: UserContext = Depends(get_current_super_admin),
):
"""
Disable all optional modules for a platform, keeping only core modules.

View File

@@ -19,7 +19,7 @@ from app.services.admin_notification_service import (
admin_notification_service,
platform_alert_service,
)
from models.database.user import User
from models.schema.auth import UserContext
from models.schema.admin import (
AdminNotificationCreate,
AdminNotificationListResponse,
@@ -52,7 +52,7 @@ def get_notifications(
skip: int = Query(0, ge=0),
limit: int = Query(50, ge=1, le=100),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> AdminNotificationListResponse:
"""Get admin notifications with filtering."""
notifications, total, unread_count = admin_notification_service.get_notifications(
@@ -93,7 +93,7 @@ def get_notifications(
def create_notification(
notification_data: AdminNotificationCreate,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> AdminNotificationResponse:
"""Create a new admin notification (manual)."""
notification = admin_notification_service.create_from_schema(
@@ -123,7 +123,7 @@ def create_notification(
def get_recent_notifications(
limit: int = Query(5, ge=1, le=10),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> dict:
"""Get recent unread notifications for header dropdown."""
notifications = admin_notification_service.get_recent_notifications(
@@ -151,7 +151,7 @@ def get_recent_notifications(
@router.get("/unread-count", response_model=UnreadCountResponse)
def get_unread_count(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> UnreadCountResponse:
"""Get count of unread notifications."""
count = admin_notification_service.get_unread_count(db)
@@ -162,7 +162,7 @@ def get_unread_count(
def mark_as_read(
notification_id: int,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> MessageResponse:
"""Mark notification as read."""
notification = admin_notification_service.mark_as_read(
@@ -178,7 +178,7 @@ def mark_as_read(
@router.put("/mark-all-read", response_model=MessageResponse)
def mark_all_as_read(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> MessageResponse:
"""Mark all notifications as read."""
count = admin_notification_service.mark_all_as_read(
@@ -193,7 +193,7 @@ def mark_all_as_read(
def delete_notification(
notification_id: int,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> MessageResponse:
"""Delete a notification."""
deleted = admin_notification_service.delete_notification(
@@ -220,7 +220,7 @@ def get_platform_alerts(
skip: int = Query(0, ge=0),
limit: int = Query(50, ge=1, le=100),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> PlatformAlertListResponse:
"""Get platform alerts with filtering."""
alerts, total, active_count, critical_count = platform_alert_service.get_alerts(
@@ -266,7 +266,7 @@ def get_platform_alerts(
def create_platform_alert(
alert_data: PlatformAlertCreate,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> PlatformAlertResponse:
"""Create new platform alert (manual)."""
alert = platform_alert_service.create_from_schema(db=db, data=alert_data)
@@ -299,7 +299,7 @@ def resolve_platform_alert(
alert_id: int,
resolve_data: PlatformAlertResolve,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> MessageResponse:
"""Resolve platform alert."""
alert = platform_alert_service.resolve_alert(
@@ -320,7 +320,7 @@ def resolve_platform_alert(
@router.get("/alerts/stats", response_model=AlertStatisticsResponse)
def get_alert_statistics(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> AlertStatisticsResponse:
"""Get alert statistics for dashboard."""
stats = platform_alert_service.get_statistics(db)

View File

@@ -17,7 +17,7 @@ from sqlalchemy.orm import Session
from app.api.deps import get_current_admin_api
from app.core.database import get_db
from app.services.order_item_exception_service import order_item_exception_service
from models.database.user import User
from models.schema.auth import UserContext
from app.modules.orders.schemas import (
BulkResolveRequest,
BulkResolveResponse,
@@ -53,7 +53,7 @@ def list_exceptions(
skip: int = Query(0, ge=0),
limit: int = Query(50, ge=1, le=200),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
List order item exceptions with filtering and pagination.
@@ -96,7 +96,7 @@ def list_exceptions(
def get_exception_stats(
vendor_id: int | None = Query(None, description="Filter by vendor"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get exception statistics.
@@ -116,7 +116,7 @@ def get_exception_stats(
def get_exception(
exception_id: int = Path(..., description="Exception ID"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get details of a single exception.
@@ -144,7 +144,7 @@ def resolve_exception(
exception_id: int = Path(..., description="Exception ID"),
request: ResolveExceptionRequest = ...,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Resolve an exception by assigning a product.
@@ -181,7 +181,7 @@ def ignore_exception(
exception_id: int = Path(..., description="Exception ID"),
request: IgnoreExceptionRequest = ...,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Mark an exception as ignored.
@@ -222,7 +222,7 @@ def bulk_resolve_by_gtin(
request: BulkResolveRequest,
vendor_id: int = Query(..., description="Vendor ID"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Bulk resolve all pending exceptions for a GTIN.

View File

@@ -20,7 +20,7 @@ from sqlalchemy.orm import Session
from app.api.deps import get_current_admin_api
from app.core.database import get_db
from app.services.order_service import order_service
from models.database.user import User
from models.schema.auth import UserContext
from app.modules.orders.schemas import (
AdminOrderItem,
AdminOrderListResponse,
@@ -50,7 +50,7 @@ def get_all_orders(
channel: str | None = Query(None, description="Filter by channel"),
search: str | None = Query(None, description="Search by order number or customer"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get orders across all vendors with filtering.
@@ -78,7 +78,7 @@ def get_all_orders(
@router.get("/stats", response_model=AdminOrderStats)
def get_order_stats(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get platform-wide order statistics."""
return order_service.get_order_stats_admin(db)
@@ -87,7 +87,7 @@ def get_order_stats(
@router.get("/vendors", response_model=AdminVendorsWithOrdersResponse)
def get_vendors_with_orders(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get list of vendors that have orders."""
vendors = order_service.get_vendors_with_orders_admin(db)
@@ -103,7 +103,7 @@ def get_vendors_with_orders(
def get_order_detail(
order_id: int,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get order details including items and addresses."""
order = order_service.get_order_by_id_admin(db, order_id)
@@ -122,7 +122,7 @@ def update_order_status(
order_id: int,
status_update: AdminOrderStatusUpdate,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Update order status.
@@ -152,7 +152,7 @@ def mark_order_as_shipped(
order_id: int,
ship_request: MarkAsShippedRequest,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Mark an order as shipped with optional tracking information.
@@ -182,7 +182,7 @@ def mark_order_as_shipped(
def get_shipping_label_info(
order_id: int,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get shipping label information for an order.

View File

@@ -17,7 +17,7 @@ from sqlalchemy.orm import Session
from app.api.deps import get_current_admin_api
from app.core.database import get_db
from app.services.platform_health_service import platform_health_service
from models.database.user import User
from models.schema.auth import UserContext
router = APIRouter()
logger = logging.getLogger(__name__)
@@ -115,7 +115,7 @@ class CapacityMetricsResponse(BaseModel):
@router.get("/health", response_model=PlatformHealthResponse)
async def get_platform_health(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get comprehensive platform health status.
@@ -139,7 +139,7 @@ async def get_platform_health(
@router.get("/capacity", response_model=CapacityMetricsResponse)
async def get_capacity_metrics(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get capacity-focused metrics for planning."""
metrics = platform_health_service.get_capacity_metrics(db)
@@ -149,7 +149,7 @@ async def get_capacity_metrics(
@router.get("/subscription-capacity")
async def get_subscription_capacity(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get subscription-based capacity metrics.
@@ -163,7 +163,7 @@ async def get_subscription_capacity(
async def get_growth_trends(
days: int = 30,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get growth trends over the specified period.
@@ -178,7 +178,7 @@ async def get_growth_trends(
@router.get("/recommendations")
async def get_scaling_recommendations(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get scaling recommendations based on current capacity and growth.
@@ -193,7 +193,7 @@ async def get_scaling_recommendations(
@router.post("/snapshot")
async def capture_snapshot(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Manually capture a capacity snapshot.

View File

@@ -23,7 +23,7 @@ from sqlalchemy.orm import Session
from app.api.deps import get_current_admin_from_cookie_or_header, get_db
from app.services.platform_service import platform_service
from models.database.user import User
from models.schema.auth import UserContext
logger = logging.getLogger(__name__)
router = APIRouter(prefix="/platforms")
@@ -142,7 +142,7 @@ def _build_platform_response(db: Session, platform) -> PlatformResponse:
@router.get("", response_model=PlatformListResponse)
async def list_platforms(
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_from_cookie_or_header),
current_user: UserContext = Depends(get_current_admin_from_cookie_or_header),
include_inactive: bool = Query(False, description="Include inactive platforms"),
):
"""
@@ -163,7 +163,7 @@ async def list_platforms(
async def get_platform(
code: str = Path(..., description="Platform code (oms, loyalty, etc.)"),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_from_cookie_or_header),
current_user: UserContext = Depends(get_current_admin_from_cookie_or_header),
):
"""
Get platform details by code.
@@ -179,7 +179,7 @@ async def update_platform(
update_data: PlatformUpdateRequest,
code: str = Path(..., description="Platform code"),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_from_cookie_or_header),
current_user: UserContext = Depends(get_current_admin_from_cookie_or_header),
):
"""
Update platform settings.
@@ -201,7 +201,7 @@ async def update_platform(
async def get_platform_stats(
code: str = Path(..., description="Platform code"),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_from_cookie_or_header),
current_user: UserContext = Depends(get_current_admin_from_cookie_or_header),
):
"""
Get detailed statistics for a platform.

View File

@@ -19,7 +19,7 @@ from sqlalchemy.orm import Session
from app.api.deps import get_current_admin_api
from app.core.database import get_db
from app.services.marketplace_product_service import marketplace_product_service
from models.database.user import User
from models.schema.auth import UserContext
router = APIRouter(prefix="/products")
logger = logging.getLogger(__name__)
@@ -161,7 +161,7 @@ def get_products(
is_digital: bool | None = Query(None, description="Filter by digital products"),
language: str = Query("en", description="Language for title lookup"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get all marketplace products with search and filtering.
@@ -195,7 +195,7 @@ def get_product_stats(
marketplace: str | None = Query(None, description="Filter by marketplace"),
vendor_name: str | None = Query(None, description="Filter by vendor name"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get product statistics for admin dashboard."""
stats = marketplace_product_service.get_admin_product_stats(
@@ -207,7 +207,7 @@ def get_product_stats(
@router.get("/marketplaces", response_model=MarketplacesResponse)
def get_marketplaces(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get list of unique marketplaces in the product catalog."""
marketplaces = marketplace_product_service.get_marketplaces_list(db)
@@ -217,7 +217,7 @@ def get_marketplaces(
@router.get("/vendors", response_model=VendorsResponse)
def get_product_vendors(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get list of unique vendor names in the product catalog."""
vendors = marketplace_product_service.get_source_vendors_list(db)
@@ -228,7 +228,7 @@ def get_product_vendors(
def copy_products_to_vendor(
request: CopyToVendorRequest,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Copy marketplace products to a vendor's catalog.
@@ -253,7 +253,7 @@ def copy_products_to_vendor(
def get_product_detail(
product_id: int,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get detailed product information including all translations."""
product = marketplace_product_service.get_admin_product_detail(db, product_id)

View File

@@ -21,7 +21,7 @@ from app.core.database import get_db
from app.exceptions import ConfirmationRequiredException, ResourceNotFoundException
from app.services.admin_audit_service import admin_audit_service
from app.services.admin_settings_service import admin_settings_service
from models.database.user import User
from models.schema.auth import UserContext
from models.schema.admin import (
AdminSettingCreate,
AdminSettingDefaultResponse,
@@ -42,7 +42,7 @@ def get_all_settings(
category: str | None = Query(None, description="Filter by category"),
is_public: bool | None = Query(None, description="Filter by public flag"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get all platform settings.
@@ -60,7 +60,7 @@ def get_all_settings(
@router.get("/categories")
def get_setting_categories(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get list of all setting categories."""
# This could be enhanced to return counts per category
@@ -81,7 +81,7 @@ def get_setting(
key: str,
default: str | None = Query(None, description="Default value if setting not found"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> AdminSettingResponse | AdminSettingDefaultResponse:
"""Get specific setting by key.
@@ -103,7 +103,7 @@ def get_setting(
def create_setting(
setting_data: AdminSettingCreate,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Create new platform setting.
@@ -136,7 +136,7 @@ def update_setting(
key: str,
update_data: AdminSettingUpdate,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Update existing setting value."""
old_value = admin_settings_service.get_setting_value(db, key)
@@ -163,7 +163,7 @@ def update_setting(
def upsert_setting(
setting_data: AdminSettingCreate,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Create or update setting (upsert).
@@ -196,7 +196,7 @@ def upsert_setting(
@router.get("/display/rows-per-page", response_model=RowsPerPageResponse)
def get_rows_per_page(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> RowsPerPageResponse:
"""Get the platform-wide rows per page setting."""
value = admin_settings_service.get_setting_value(db, "rows_per_page", default="20")
@@ -207,7 +207,7 @@ def get_rows_per_page(
def set_rows_per_page(
rows: int = Query(..., ge=10, le=100, description="Rows per page (10-100)"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> RowsPerPageUpdateResponse:
"""
Set the platform-wide rows per page setting.
@@ -268,7 +268,7 @@ def delete_setting(
key: str,
confirm: bool = Query(False, description="Must be true to confirm deletion"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Delete platform setting.
@@ -473,7 +473,7 @@ class TestEmailResponse(BaseModel):
@router.get("/email/status", response_model=EmailStatusResponse)
def get_email_status(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> EmailStatusResponse:
"""
Get platform email configuration status.
@@ -519,7 +519,7 @@ def get_email_status(
def update_email_settings(
settings_update: EmailSettingsUpdate,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Update platform email settings.
@@ -607,7 +607,7 @@ def update_email_settings(
@router.delete("/email/settings")
def reset_email_settings(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Reset email settings to use .env values.
@@ -646,7 +646,7 @@ def reset_email_settings(
def send_test_email(
request: TestEmailRequest,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
) -> TestEmailResponse:
"""
Send a test email using the platform email configuration.

View File

@@ -18,7 +18,7 @@ from app.api.deps import get_current_admin_api
from app.core.database import get_db
from app.services.admin_subscription_service import admin_subscription_service
from app.services.subscription_service import subscription_service
from models.database.user import User
from models.schema.auth import UserContext
from app.modules.billing.schemas import (
BillingHistoryListResponse,
BillingHistoryWithVendor,
@@ -46,7 +46,7 @@ logger = logging.getLogger(__name__)
@router.get("/tiers", response_model=SubscriptionTierListResponse)
def list_subscription_tiers(
include_inactive: bool = Query(False, description="Include inactive tiers"),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""
@@ -65,7 +65,7 @@ def list_subscription_tiers(
@router.get("/tiers/{tier_code}", response_model=SubscriptionTierResponse)
def get_subscription_tier(
tier_code: str = Path(..., description="Tier code"),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""Get a specific subscription tier by code."""
@@ -76,7 +76,7 @@ def get_subscription_tier(
@router.post("/tiers", response_model=SubscriptionTierResponse, status_code=201)
def create_subscription_tier(
tier_data: SubscriptionTierCreate,
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""Create a new subscription tier."""
@@ -90,7 +90,7 @@ def create_subscription_tier(
def update_subscription_tier(
tier_data: SubscriptionTierUpdate,
tier_code: str = Path(..., description="Tier code"),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""Update a subscription tier."""
@@ -104,7 +104,7 @@ def update_subscription_tier(
@router.delete("/tiers/{tier_code}", status_code=204)
def delete_subscription_tier(
tier_code: str = Path(..., description="Tier code"),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""
@@ -128,7 +128,7 @@ def list_vendor_subscriptions(
status: str | None = Query(None, description="Filter by status"),
tier: str | None = Query(None, description="Filter by tier"),
search: str | None = Query(None, description="Search vendor name"),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""
@@ -165,7 +165,7 @@ def list_vendor_subscriptions(
@router.get("/stats", response_model=SubscriptionStatsResponse)
def get_subscription_stats(
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""Get subscription statistics for admin dashboard."""
@@ -184,7 +184,7 @@ def list_billing_history(
per_page: int = Query(20, ge=1, le=100),
vendor_id: int | None = Query(None, description="Filter by vendor"),
status: str | None = Query(None, description="Filter by status"),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""List billing history (invoices) across all vendors."""
@@ -234,7 +234,7 @@ def list_billing_history(
def create_vendor_subscription(
create_data: VendorSubscriptionCreate,
vendor_id: int = Path(..., description="Vendor ID"),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""
@@ -280,7 +280,7 @@ def create_vendor_subscription(
@router.get("/{vendor_id}", response_model=VendorSubscriptionWithVendor)
def get_vendor_subscription(
vendor_id: int = Path(..., description="Vendor ID"),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""Get subscription details for a specific vendor."""
@@ -302,7 +302,7 @@ def get_vendor_subscription(
def update_vendor_subscription(
update_data: VendorSubscriptionUpdate,
vendor_id: int = Path(..., description="Vendor ID"),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
"""

View File

@@ -11,7 +11,7 @@ from app.api.deps import get_current_admin_api
from app.core.database import get_db
from app.services.test_runner_service import test_runner_service
from app.tasks.test_runner_tasks import execute_test_run
from models.database.user import User
from models.schema.auth import UserContext
router = APIRouter()
@@ -108,7 +108,7 @@ async def run_tests(
background_tasks: BackgroundTasks,
request: RunTestsRequest | None = None,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Start a pytest run in the background
@@ -168,7 +168,7 @@ async def run_tests(
async def list_runs(
limit: int = Query(20, ge=1, le=100, description="Number of runs to return"),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Get test run history
@@ -205,7 +205,7 @@ async def list_runs(
async def get_run(
run_id: int,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Get a specific test run
@@ -245,7 +245,7 @@ async def get_run_results(
None, description="Filter by outcome (passed, failed, error, skipped)"
),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Get test results for a specific run
@@ -272,7 +272,7 @@ async def get_run_results(
async def get_run_failures(
run_id: int,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Get failed tests from a specific run
@@ -298,7 +298,7 @@ async def get_run_failures(
@router.get("/stats", response_model=TestDashboardStatsResponse)
async def get_dashboard_stats(
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Get dashboard statistics
@@ -317,7 +317,7 @@ async def get_dashboard_stats(
@router.post("/collect")
async def collect_tests(
db: Session = Depends(get_db),
current_user: User = Depends(get_current_admin_api),
current_user: UserContext = Depends(get_current_admin_api),
):
"""
Collect test information without running tests

View File

@@ -16,7 +16,7 @@ from app.api.deps import get_current_admin_api
from app.core.database import get_db
from app.services.admin_service import admin_service
from app.services.stats_service import stats_service
from models.database.user import User
from models.schema.auth import UserContext
from models.schema.auth import (
UserCreate,
UserDeleteResponse,
@@ -40,7 +40,7 @@ def get_all_users(
role: str = Query("", description="Filter by role"),
is_active: str = Query("", description="Filter by active status"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get paginated list of all users (Admin only)."""
# Convert string params to proper types
@@ -70,7 +70,7 @@ def get_all_users(
def create_user(
user_data: UserCreate = Body(...),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Create a new user (Admin only)."""
user = admin_service.create_user(
@@ -108,7 +108,7 @@ def create_user(
@router.get("/stats")
def get_user_statistics(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get user statistics for admin dashboard (Admin only)."""
return stats_service.get_user_statistics(db)
@@ -119,7 +119,7 @@ def search_users(
q: str = Query(..., min_length=2, description="Search query (username or email)"),
limit: int = Query(10, ge=1, le=50),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Search users by username or email (Admin only).
@@ -134,7 +134,7 @@ def search_users(
def get_user_details(
user_id: int = Path(..., description="User ID"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get detailed user information (Admin only)."""
user = admin_service.get_user_details(db=db, user_id=user_id)
@@ -164,7 +164,7 @@ def update_user(
user_id: int = Path(..., description="User ID"),
user_update: UserUpdate = Body(...),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Update user information (Admin only)."""
update_data = user_update.model_dump(exclude_unset=True)
@@ -206,7 +206,7 @@ def update_user(
def toggle_user_status(
user_id: int = Path(..., description="User ID"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Toggle user active status (Admin only)."""
user, message = admin_service.toggle_user_status(
@@ -223,7 +223,7 @@ def toggle_user_status(
def delete_user(
user_id: int = Path(..., description="User ID"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Delete a user (Admin only)."""
message = admin_service.delete_user(

View File

@@ -18,7 +18,7 @@ from app.api.deps import get_current_admin_api
from app.core.database import get_db
from app.services.vendor_domain_service import vendor_domain_service
from app.services.vendor_service import vendor_service
from models.database.user import User
from models.schema.auth import UserContext
from models.schema.vendor_domain import (
DomainDeletionResponse,
DomainVerificationInstructions,
@@ -38,7 +38,7 @@ def add_vendor_domain(
vendor_id: int = Path(..., description="Vendor ID", gt=0),
domain_data: VendorDomainCreate = Body(...),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Add a custom domain to vendor (Admin only).
@@ -90,7 +90,7 @@ def add_vendor_domain(
def list_vendor_domains(
vendor_id: int = Path(..., description="Vendor ID", gt=0),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
List all domains for a vendor (Admin only).
@@ -133,7 +133,7 @@ def list_vendor_domains(
def get_domain_details(
domain_id: int = Path(..., description="Domain ID", gt=0),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get detailed information about a specific domain (Admin only).
@@ -166,7 +166,7 @@ def update_vendor_domain(
domain_id: int = Path(..., description="Domain ID", gt=0),
domain_update: VendorDomainUpdate = Body(...),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Update domain settings (Admin only).
@@ -209,7 +209,7 @@ def update_vendor_domain(
def delete_vendor_domain(
domain_id: int = Path(..., description="Domain ID", gt=0),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Delete a custom domain (Admin only).
@@ -237,7 +237,7 @@ def delete_vendor_domain(
def verify_domain_ownership(
domain_id: int = Path(..., description="Domain ID", gt=0),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Verify domain ownership via DNS TXT record (Admin only).
@@ -279,7 +279,7 @@ def verify_domain_ownership(
def get_domain_verification_instructions(
domain_id: int = Path(..., description="Domain ID", gt=0),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get DNS verification instructions for domain (Admin only).

View File

@@ -21,7 +21,7 @@ from app.api.deps import get_current_admin_api
from app.core.database import get_db
from app.services.subscription_service import subscription_service
from app.services.vendor_product_service import vendor_product_service
from models.database.user import User
from models.schema.auth import UserContext
from app.modules.catalog.schemas import (
CatalogVendor,
CatalogVendorsResponse,
@@ -54,7 +54,7 @@ def get_vendor_products(
is_featured: bool | None = Query(None, description="Filter by featured status"),
language: str = Query("en", description="Language for title lookup"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get all products in vendor catalogs with filtering.
@@ -85,7 +85,7 @@ def get_vendor_products(
def get_vendor_product_stats(
vendor_id: int | None = Query(None, description="Filter stats by vendor ID"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get vendor product statistics for admin dashboard."""
stats = vendor_product_service.get_product_stats(db, vendor_id=vendor_id)
@@ -95,7 +95,7 @@ def get_vendor_product_stats(
@router.get("/vendors", response_model=CatalogVendorsResponse)
def get_catalog_vendors(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get list of vendors with products in their catalogs."""
vendors = vendor_product_service.get_catalog_vendors(db)
@@ -106,7 +106,7 @@ def get_catalog_vendors(
def get_vendor_product_detail(
product_id: int,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get detailed vendor product information including override info."""
product = vendor_product_service.get_product_detail(db, product_id)
@@ -117,7 +117,7 @@ def get_vendor_product_detail(
def create_vendor_product(
data: VendorProductCreate,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Create a new vendor product."""
# Check product limit before creating
@@ -135,7 +135,7 @@ def update_vendor_product(
product_id: int,
data: VendorProductUpdate,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Update a vendor product."""
# Only include fields that were explicitly set
@@ -151,7 +151,7 @@ def update_vendor_product(
def remove_vendor_product(
product_id: int,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Remove a product from vendor catalog."""
result = vendor_product_service.remove_product(db, product_id)

View File

@@ -19,7 +19,7 @@ from sqlalchemy.orm import Session
from app.api.deps import get_current_admin_api, get_db
from app.services.vendor_theme_service import vendor_theme_service
from models.database.user import User
from models.schema.auth import UserContext
from models.schema.vendor_theme import (
ThemeDeleteResponse,
ThemePresetListResponse,
@@ -38,7 +38,7 @@ logger = logging.getLogger(__name__)
@router.get("/presets", response_model=ThemePresetListResponse)
async def get_theme_presets(current_admin: User = Depends(get_current_admin_api)):
async def get_theme_presets(current_admin: UserContext = Depends(get_current_admin_api)):
"""
Get all available theme presets with preview information.
@@ -65,7 +65,7 @@ async def get_theme_presets(current_admin: User = Depends(get_current_admin_api)
async def get_vendor_theme(
vendor_code: str = Path(..., description="Vendor code"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get theme configuration for a vendor.
@@ -101,7 +101,7 @@ async def update_vendor_theme(
vendor_code: str = Path(..., description="Vendor code"),
theme_data: VendorThemeUpdate = None,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Update or create theme for a vendor.
@@ -150,7 +150,7 @@ async def apply_theme_preset(
vendor_code: str = Path(..., description="Vendor code"),
preset_name: str = Path(..., description="Preset name"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Apply a theme preset to a vendor.
@@ -203,7 +203,7 @@ async def apply_theme_preset(
async def delete_vendor_theme(
vendor_code: str = Path(..., description="Vendor code"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Delete custom theme for a vendor.

View File

@@ -19,7 +19,7 @@ from app.exceptions import ConfirmationRequiredException
from app.services.admin_service import admin_service
from app.services.stats_service import stats_service
from app.services.vendor_service import vendor_service
from models.database.user import User
from models.schema.auth import UserContext
from app.modules.analytics.schemas import VendorStatsResponse
from models.schema.vendor import (
LetzshopExportRequest,
@@ -39,7 +39,7 @@ logger = logging.getLogger(__name__)
def create_vendor(
vendor_data: VendorCreate,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Create a new vendor (storefront/brand) under an existing company (Admin only).
@@ -89,7 +89,7 @@ def get_all_vendors_admin(
is_active: bool | None = Query(None),
is_verified: bool | None = Query(None),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get all vendors with filtering (Admin only)."""
vendors, total = admin_service.get_all_vendors(
@@ -106,7 +106,7 @@ def get_all_vendors_admin(
@router.get("/stats", response_model=VendorStatsResponse)
def get_vendor_statistics_endpoint(
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get vendor statistics for admin dashboard (Admin only)."""
stats = stats_service.get_vendor_statistics(db)
@@ -164,7 +164,7 @@ def _build_vendor_detail_response(vendor) -> VendorDetailResponse:
def get_vendor_details(
vendor_identifier: str = Path(..., description="Vendor ID or vendor_code"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Get detailed vendor information including company and owner details (Admin only).
@@ -186,7 +186,7 @@ def update_vendor(
vendor_identifier: str = Path(..., description="Vendor ID or vendor_code"),
vendor_update: VendorUpdate = Body(...),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Update vendor information (Admin only).
@@ -222,7 +222,7 @@ def toggle_vendor_verification(
vendor_identifier: str = Path(..., description="Vendor ID or vendor_code"),
verification_data: dict = Body(..., example={"is_verified": True}),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Set vendor verification status (Admin only).
@@ -251,7 +251,7 @@ def toggle_vendor_status(
vendor_identifier: str = Path(..., description="Vendor ID or vendor_code"),
status_data: dict = Body(..., example={"is_active": True}),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Set vendor active status (Admin only).
@@ -280,7 +280,7 @@ def delete_vendor(
vendor_identifier: str = Path(..., description="Vendor ID or vendor_code"),
confirm: bool = Query(False, description="Must be true to confirm deletion"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Delete vendor and all associated data (Admin only).
@@ -325,7 +325,7 @@ def export_vendor_products_letzshop(
),
include_inactive: bool = Query(False, description="Include inactive products"),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Export vendor products in Letzshop CSV format (Admin only).
@@ -372,7 +372,7 @@ def export_vendor_products_letzshop_to_folder(
vendor_identifier: str = Path(..., description="Vendor ID or vendor_code"),
request: LetzshopExportRequest = None,
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_api),
current_admin: UserContext = Depends(get_current_admin_api),
):
"""
Export vendor products to Letzshop pickup folder (Admin only).