fix(api): use proper Pydantic models in vendor themes/domains

vendor_themes.py:
- Return ThemePresetListResponse instead of raw dict (API-001 fix)
- Add ThemePresetResponse response_model to apply_theme_preset
- Add ThemeDeleteResponse response_model to delete endpoint

vendor_domain.py:
- Remove _get_vendor_by_id helper with direct DB query
- Use vendor_service.get_vendor_by_id() instead (API-002 fix)

models/schema/vendor_theme.py:
- Add ThemeDeleteResponse model for delete endpoint response

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-03 21:34:20 +01:00
parent 6d05b91e9f
commit 901471bb76
3 changed files with 21 additions and 34 deletions

View File

@@ -21,7 +21,9 @@ 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.vendor_theme import (
ThemeDeleteResponse,
ThemePresetListResponse,
ThemePresetResponse,
VendorThemeResponse,
VendorThemeUpdate,
)
@@ -51,7 +53,7 @@ async def get_theme_presets(current_admin: User = Depends(get_current_admin_api)
logger.info("Getting theme presets")
presets = vendor_theme_service.get_available_presets()
return {"presets": presets}
return ThemePresetListResponse(presets=presets)
# ============================================================================
@@ -134,7 +136,7 @@ async def update_vendor_theme(
# Service handles all validation and raises appropriate exceptions
# Global exception handler converts them to proper HTTP responses
theme = vendor_theme_service.update_theme(db, vendor_code, theme_data)
return theme.to_dict()
return VendorThemeResponse(**theme.to_dict())
# ============================================================================
@@ -142,7 +144,7 @@ async def update_vendor_theme(
# ============================================================================
@router.post("/{vendor_code}/preset/{preset_name}")
@router.post("/{vendor_code}/preset/{preset_name}", response_model=ThemePresetResponse)
async def apply_theme_preset(
vendor_code: str = Path(..., description="Vendor code"),
preset_name: str = Path(..., description="Preset name"),
@@ -184,10 +186,10 @@ async def apply_theme_preset(
# Global exception handler converts to HTTP 404
theme = vendor_theme_service.apply_theme_preset(db, vendor_code, preset_name)
return {
"message": f"Applied {preset_name} preset successfully",
"theme": theme.to_dict(),
}
return ThemePresetResponse(
message=f"Applied {preset_name} preset successfully",
theme=VendorThemeResponse(**theme.to_dict()),
)
# ============================================================================
@@ -195,7 +197,7 @@ async def apply_theme_preset(
# ============================================================================
@router.delete("/{vendor_code}")
@router.delete("/{vendor_code}", response_model=ThemeDeleteResponse)
async def delete_vendor_theme(
vendor_code: str = Path(..., description="Vendor code"),
db: Session = Depends(get_db),
@@ -224,4 +226,4 @@ async def delete_vendor_theme(
# Service handles deletion and raises exceptions if needed
# Global exception handler converts them to proper HTTP responses
result = vendor_theme_service.delete_theme(db, vendor_code)
return result
return ThemeDeleteResponse(message=result.get("message", "Theme deleted successfully"))