-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodel.py
64 lines (48 loc) · 1.84 KB
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from pydantic import AfterValidator, BaseModel
from sqlmodel import Field, SQLModel
import uuid
from custom_validation import ValidateListToStr
from typing import TypeVar, Annotated
from enum import Enum
import datetime
import pytz
# Set Local Time Zone
local_timezone = pytz.timezone('America/Argentina/Buenos_Aires')
SCRIPT_PATH = "./order_service.py"
# Annotated para usar en ValidateListToStr
T = TypeVar('T')
ValidList = Annotated[list[T], AfterValidator(ValidateListToStr.convert_list_to_str)]
class Estado(Enum):
Confirmado = "CNF"
Pendiente = "PND"
Cancelado = "CAN"
class Producto(BaseModel):
producto: str = Field(default=uuid.uuid4())
cantidad: float = Field(..., gt=0)
class ProductoBase(BaseModel):
producto: ValidList[Producto]
estado: Estado | None = "CNF"
total: float | None = None
class PedidoBase(SQLModel):
producto: str
estado: Estado | None = "CNF"
total: float | None = None
class Pedido(PedidoBase, table=True):
id: str = Field(default_factory=lambda: str(uuid.uuid4()), primary_key=True)
userid: str = Field(default_factory=lambda: str(uuid.uuid4()))
costo: float = Field(default=12.6)
creacion: datetime.datetime = Field(default_factory=lambda: datetime.datetime.now(local_timezone))
class PedidoPrecioResponse(BaseModel):
pedidoId: str = Field(default=str(uuid.uuid4()))
userId: str = Field(default=str(uuid.uuid4()))
producto: list[Producto]
creacion: datetime.datetime = Field(default=lambda: datetime.datetime.now(local_timezone))
total: float
costo: float
class PedidoResponse(BaseModel):
pedidoId: str = Field(default=str(uuid.uuid4()))
userId: str = Field(default=str(uuid.uuid4()))
producto: list[Producto]
estado: Estado
creacion: datetime.datetime = Field(default=lambda: datetime.datetime.now(local_timezone))
total: float