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>
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
# app/api/v1/vendor/profile.py
|
|
"""
|
|
Vendor profile management endpoints.
|
|
|
|
Vendor Context: Uses token_vendor_id from JWT token (authenticated vendor API pattern).
|
|
The get_current_vendor_api dependency guarantees token_vendor_id is present.
|
|
"""
|
|
|
|
import logging
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.api.deps import get_current_vendor_api
|
|
from app.core.database import get_db
|
|
from app.services.vendor_service import vendor_service
|
|
from models.schema.auth import UserContext
|
|
from models.schema.vendor import VendorResponse, VendorUpdate
|
|
|
|
router = APIRouter(prefix="/profile")
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@router.get("", response_model=VendorResponse)
|
|
def get_vendor_profile(
|
|
current_user: UserContext = Depends(get_current_vendor_api),
|
|
db: Session = Depends(get_db),
|
|
):
|
|
"""Get current vendor profile information."""
|
|
vendor = vendor_service.get_vendor_by_id(db, current_user.token_vendor_id)
|
|
return vendor
|
|
|
|
|
|
@router.put("", response_model=VendorResponse)
|
|
def update_vendor_profile(
|
|
vendor_update: VendorUpdate,
|
|
current_user: UserContext = Depends(get_current_vendor_api),
|
|
db: Session = Depends(get_db),
|
|
):
|
|
"""Update vendor profile information."""
|
|
# Service handles permission checking and raises InsufficientPermissionsException if needed
|
|
return vendor_service.update_vendor(
|
|
db, current_user.token_vendor_id, vendor_update, current_user
|
|
)
|