- Update architecture rules to be stricter (API-003 now blocks ALL exception raising in endpoints, not just HTTPException) - Update get_current_vendor_api dependency to guarantee token_vendor_id presence - Remove redundant _get_vendor_from_token helpers from all vendor API files - Move vendor access validation to service layer methods - Add Pydantic response models for media, notification, and payment endpoints - Add get_active_vendor_by_code service method for public vendor lookup - Add get_import_job_for_vendor service method with vendor validation - Update validation script to detect exception raising patterns in endpoints 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <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.database.user import User
|
|
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: User = 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: User = 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
|
|
)
|