refactor: update schemas for company-vendor architecture
- Update VendorResponse to use company_id instead of owner fields - Add VendorDetailResponse with company info (name, email, phone, website) - Update VendorCreate to require company_id - Add owner_email, owner_username, vendors list to CompanyDetailResponse - Remove obsolete VendorTransferOwnership schemas 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,9 @@ Pydantic schemas for Company model.
|
||||
These schemas are used for API request/response validation and serialization.
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, EmailStr, Field, field_validator
|
||||
|
||||
|
||||
@@ -106,16 +109,24 @@ class CompanyResponse(BaseModel):
|
||||
|
||||
class CompanyDetailResponse(CompanyResponse):
|
||||
"""
|
||||
Detailed company response including vendor count.
|
||||
Detailed company response including vendor count and owner details.
|
||||
|
||||
Used for company detail pages and admin views.
|
||||
"""
|
||||
|
||||
# Owner details (from related User)
|
||||
owner_email: str | None = Field(None, description="Owner's email address")
|
||||
owner_username: str | None = Field(None, description="Owner's username")
|
||||
|
||||
# Vendor statistics
|
||||
vendor_count: int = Field(0, description="Number of vendors under this company")
|
||||
active_vendor_count: int = Field(
|
||||
0, description="Number of active vendors under this company"
|
||||
)
|
||||
|
||||
# Vendors list (optional, for detail view)
|
||||
vendors: list | None = Field(None, description="List of vendors under this company")
|
||||
|
||||
|
||||
class CompanyListResponse(BaseModel):
|
||||
"""Schema for paginated company list."""
|
||||
@@ -153,3 +164,53 @@ class CompanySummary(BaseModel):
|
||||
is_active: bool
|
||||
is_verified: bool
|
||||
vendor_count: int = 0
|
||||
|
||||
|
||||
class CompanyTransferOwnership(BaseModel):
|
||||
"""
|
||||
Schema for transferring company ownership to another user.
|
||||
|
||||
This is a critical operation that requires:
|
||||
- Confirmation flag
|
||||
- Reason for audit trail (optional)
|
||||
"""
|
||||
|
||||
new_owner_user_id: int = Field(
|
||||
..., description="ID of the user who will become the new owner", gt=0
|
||||
)
|
||||
|
||||
confirm_transfer: bool = Field(
|
||||
..., description="Must be true to confirm ownership transfer"
|
||||
)
|
||||
|
||||
transfer_reason: str | None = Field(
|
||||
None,
|
||||
max_length=500,
|
||||
description="Reason for ownership transfer (for audit logs)",
|
||||
)
|
||||
|
||||
@field_validator("confirm_transfer")
|
||||
@classmethod
|
||||
def validate_confirmation(cls, v):
|
||||
"""Ensure confirmation is explicitly true."""
|
||||
if not v:
|
||||
raise ValueError("Ownership transfer requires explicit confirmation")
|
||||
return v
|
||||
|
||||
|
||||
class CompanyTransferOwnershipResponse(BaseModel):
|
||||
"""Response after successful ownership transfer."""
|
||||
|
||||
message: str
|
||||
company_id: int
|
||||
company_name: str
|
||||
|
||||
old_owner: dict[str, Any] = Field(
|
||||
..., description="Information about the previous owner"
|
||||
)
|
||||
new_owner: dict[str, Any] = Field(
|
||||
..., description="Information about the new owner"
|
||||
)
|
||||
|
||||
transferred_at: datetime
|
||||
transfer_reason: str | None
|
||||
|
||||
Reference in New Issue
Block a user