refactor: enforce strict architecture rules and add Pydantic response models
- 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>
This commit is contained in:
@@ -21,7 +21,11 @@ from models.schema.admin import (
|
||||
PlatformAlertCreate,
|
||||
PlatformAlertListResponse,
|
||||
PlatformAlertResolve,
|
||||
PlatformAlertResponse,
|
||||
)
|
||||
from models.schema.notification import (
|
||||
AlertStatisticsResponse,
|
||||
MessageResponse,
|
||||
UnreadCountResponse,
|
||||
)
|
||||
|
||||
router = APIRouter(prefix="/notifications")
|
||||
@@ -49,17 +53,17 @@ def get_notifications(
|
||||
)
|
||||
|
||||
|
||||
@router.get("/unread-count")
|
||||
@router.get("/unread-count", response_model=UnreadCountResponse)
|
||||
def get_unread_count(
|
||||
db: Session = Depends(get_db),
|
||||
current_admin: User = Depends(get_current_admin_api),
|
||||
):
|
||||
"""Get count of unread notifications."""
|
||||
# TODO: Implement
|
||||
return {"unread_count": 0}
|
||||
return UnreadCountResponse(unread_count=0)
|
||||
|
||||
|
||||
@router.put("/{notification_id}/read")
|
||||
@router.put("/{notification_id}/read", response_model=MessageResponse)
|
||||
def mark_as_read(
|
||||
notification_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
@@ -67,17 +71,17 @@ def mark_as_read(
|
||||
):
|
||||
"""Mark notification as read."""
|
||||
# TODO: Implement
|
||||
return {"message": "Notification marked as read"}
|
||||
return MessageResponse(message="Notification marked as read")
|
||||
|
||||
|
||||
@router.put("/mark-all-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),
|
||||
):
|
||||
"""Mark all notifications as read."""
|
||||
# TODO: Implement
|
||||
return {"message": "All notifications marked as read"}
|
||||
return MessageResponse(message="All notifications marked as read")
|
||||
|
||||
|
||||
# ============================================================================
|
||||
@@ -101,19 +105,19 @@ def get_platform_alerts(
|
||||
)
|
||||
|
||||
|
||||
@router.post("/alerts", response_model=PlatformAlertResponse)
|
||||
@router.post("/alerts", response_model=MessageResponse)
|
||||
def create_platform_alert(
|
||||
alert_data: PlatformAlertCreate,
|
||||
db: Session = Depends(get_db),
|
||||
current_admin: User = Depends(get_current_admin_api),
|
||||
):
|
||||
"""Create new platform alert (manual)."""
|
||||
# TODO: Implement
|
||||
# TODO: Implement - return PlatformAlertResponse when service is ready
|
||||
logger.info(f"Admin {current_admin.username} created alert: {alert_data.title}")
|
||||
return {}
|
||||
return MessageResponse(message="Platform alert creation coming soon")
|
||||
|
||||
|
||||
@router.put("/alerts/{alert_id}/resolve")
|
||||
@router.put("/alerts/{alert_id}/resolve", response_model=MessageResponse)
|
||||
def resolve_platform_alert(
|
||||
alert_id: int,
|
||||
resolve_data: PlatformAlertResolve,
|
||||
@@ -123,19 +127,19 @@ def resolve_platform_alert(
|
||||
"""Resolve platform alert."""
|
||||
# TODO: Implement
|
||||
logger.info(f"Admin {current_admin.username} resolved alert {alert_id}")
|
||||
return {"message": "Alert resolved successfully"}
|
||||
return MessageResponse(message="Alert resolved successfully")
|
||||
|
||||
|
||||
@router.get("/alerts/stats")
|
||||
@router.get("/alerts/stats", response_model=AlertStatisticsResponse)
|
||||
def get_alert_statistics(
|
||||
db: Session = Depends(get_db),
|
||||
current_admin: User = Depends(get_current_admin_api),
|
||||
):
|
||||
"""Get alert statistics for dashboard."""
|
||||
# TODO: Implement
|
||||
return {
|
||||
"total_alerts": 0,
|
||||
"active_alerts": 0,
|
||||
"critical_alerts": 0,
|
||||
"resolved_today": 0,
|
||||
}
|
||||
return AlertStatisticsResponse(
|
||||
total_alerts=0,
|
||||
active_alerts=0,
|
||||
critical_alerts=0,
|
||||
resolved_today=0,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user