- 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>
152 lines
4.2 KiB
Python
152 lines
4.2 KiB
Python
# models/schema/notification.py
|
|
"""
|
|
Notification Pydantic schemas for API validation and responses.
|
|
|
|
This module provides schemas for:
|
|
- Vendor notifications (list, read, delete)
|
|
- Notification settings management
|
|
- Notification email templates
|
|
- Unread counts and statistics
|
|
"""
|
|
|
|
from datetime import datetime
|
|
from typing import Any
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
# ============================================================================
|
|
# SHARED RESPONSE SCHEMAS
|
|
# ============================================================================
|
|
|
|
|
|
class MessageResponse(BaseModel):
|
|
"""Generic message response for simple operations."""
|
|
|
|
message: str
|
|
|
|
|
|
class UnreadCountResponse(BaseModel):
|
|
"""Response for unread notification count."""
|
|
|
|
unread_count: int
|
|
message: str | None = None
|
|
|
|
|
|
# ============================================================================
|
|
# NOTIFICATION SCHEMAS
|
|
# ============================================================================
|
|
|
|
|
|
class NotificationResponse(BaseModel):
|
|
"""Single notification response."""
|
|
|
|
id: int
|
|
type: str
|
|
title: str
|
|
message: str
|
|
is_read: bool
|
|
read_at: datetime | None = None
|
|
priority: str = "normal"
|
|
action_url: str | None = None
|
|
metadata: dict[str, Any] | None = None
|
|
created_at: datetime
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class NotificationListResponse(BaseModel):
|
|
"""Paginated list of notifications."""
|
|
|
|
notifications: list[NotificationResponse] = []
|
|
total: int = 0
|
|
unread_count: int = 0
|
|
message: str | None = None
|
|
|
|
|
|
# ============================================================================
|
|
# NOTIFICATION SETTINGS SCHEMAS
|
|
# ============================================================================
|
|
|
|
|
|
class NotificationSettingsResponse(BaseModel):
|
|
"""Notification preferences response."""
|
|
|
|
email_notifications: bool = True
|
|
in_app_notifications: bool = True
|
|
notification_types: dict[str, bool] = Field(default_factory=dict)
|
|
message: str | None = None
|
|
|
|
|
|
class NotificationSettingsUpdate(BaseModel):
|
|
"""Request model for updating notification settings."""
|
|
|
|
email_notifications: bool | None = None
|
|
in_app_notifications: bool | None = None
|
|
notification_types: dict[str, bool] | None = None
|
|
|
|
|
|
# ============================================================================
|
|
# NOTIFICATION TEMPLATE SCHEMAS
|
|
# ============================================================================
|
|
|
|
|
|
class NotificationTemplateResponse(BaseModel):
|
|
"""Single notification template response."""
|
|
|
|
id: int
|
|
name: str
|
|
type: str
|
|
subject: str
|
|
body_html: str | None = None
|
|
body_text: str | None = None
|
|
variables: list[str] = Field(default_factory=list)
|
|
is_active: bool = True
|
|
created_at: datetime
|
|
updated_at: datetime | None = None
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class NotificationTemplateListResponse(BaseModel):
|
|
"""List of notification templates."""
|
|
|
|
templates: list[NotificationTemplateResponse] = []
|
|
message: str | None = None
|
|
|
|
|
|
class NotificationTemplateUpdate(BaseModel):
|
|
"""Request model for updating notification template."""
|
|
|
|
subject: str | None = Field(None, max_length=200)
|
|
body_html: str | None = None
|
|
body_text: str | None = None
|
|
is_active: bool | None = None
|
|
|
|
|
|
# ============================================================================
|
|
# TEST NOTIFICATION SCHEMA
|
|
# ============================================================================
|
|
|
|
|
|
class TestNotificationRequest(BaseModel):
|
|
"""Request model for sending test notification."""
|
|
|
|
template_id: int | None = Field(None, description="Template to use")
|
|
email: str | None = Field(None, description="Override recipient email")
|
|
notification_type: str = Field(default="test", description="Type of notification to send")
|
|
|
|
|
|
# ============================================================================
|
|
# ADMIN ALERT STATISTICS SCHEMA
|
|
# ============================================================================
|
|
|
|
|
|
class AlertStatisticsResponse(BaseModel):
|
|
"""Response for alert statistics."""
|
|
|
|
total_alerts: int = 0
|
|
active_alerts: int = 0
|
|
critical_alerts: int = 0
|
|
resolved_today: int = 0
|