From 51a4c36d7ce5d5cc5f774a02a5af3ba41dc725ee Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Thu, 4 Jun 2026 00:06:22 +0000 Subject: [PATCH] Upload app/schemas/deal.py --- app/schemas/deal.py | 73 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 app/schemas/deal.py diff --git a/app/schemas/deal.py b/app/schemas/deal.py new file mode 100644 index 0000000..2a2ff0c --- /dev/null +++ b/app/schemas/deal.py @@ -0,0 +1,73 @@ +"""Pydantic schemas for Deal endpoints.""" + +from __future__ import annotations + +from datetime import date, datetime +from decimal import Decimal +from typing import Optional + +from pydantic import BaseModel, ConfigDict, Field + +from app.models.deal import DealStage + + +class DealBase(BaseModel): + title: str = Field(..., min_length=1, max_length=255) + value: Decimal = Field(default=Decimal("0"), max_digits=12, decimal_places=2) + currency: str = Field(default="EUR", min_length=3, max_length=3) + stage: DealStage = DealStage.lead + close_date: Optional[date] = None + account_id: int + won_lost_reason: Optional[str] = Field(None, max_length=512) + + +class DealCreate(DealBase): + pass + + +class DealUpdate(BaseModel): + title: Optional[str] = Field(None, min_length=1, max_length=255) + value: Optional[Decimal] = Field(None, max_digits=12, decimal_places=2) + currency: Optional[str] = Field(None, min_length=3, max_length=3) + close_date: Optional[date] = None + won_lost_reason: Optional[str] = Field(None, max_length=512) + + +class DealOut(DealBase): + model_config = ConfigDict(from_attributes=True) + + id: int + org_id: int + owner_id: int + created_at: datetime + updated_at: datetime + deleted_at: Optional[datetime] = None + + +class DealListItem(DealOut): + pass + + +class DealStageUpdate(BaseModel): + """Body for PATCH /api/v1/deals/{id}/stage.""" + + stage: DealStage + reason: Optional[str] = Field(None, max_length=512) + + +class DealPipelineOut(BaseModel): + """A single stage's slice of the pipeline.""" + + stage: DealStage + count: int + total_value: float + + +__all__ = [ + "DealCreate", + "DealListItem", + "DealOut", + "DealPipelineOut", + "DealStageUpdate", + "DealUpdate", +]