-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemas.py
More file actions
97 lines (68 loc) · 2.8 KB
/
schemas.py
File metadata and controls
97 lines (68 loc) · 2.8 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from decimal import Decimal
from datetime import datetime
from typing import List, Optional
from pydantic import BaseModel, Field, conint
class AddOrderItemRequest(BaseModel):
"""Тело запроса: добавление товара в заказ."""
nomenclature_id: int = Field(..., description="ID номенклатуры")
quantity: conint(gt=0) = Field(..., description="Количество")
model_config = {"json_schema_extra": {"example": {"nomenclature_id": 1, "quantity": 2}}}
class RemoveOrderItemRequest(BaseModel):
"""Тело запроса: удаление товара из заказа.
Можно удалить позицию полностью или уменьшить количество.
При удалении товар возвращается в остатки по номенклатуре.
"""
nomenclature_id: int = Field(..., description="ID номенклатуры в заказе")
quantity: Optional[conint(gt=0)] = Field(
None,
description=(
"Количество для удаления. "
"Если не указано или больше/равно текущему количеству в заказе, "
"позиция будет удалена полностью."
),
)
model_config = {
"json_schema_extra": {
"example": {
"nomenclature_id": 1,
"quantity": 1,
}
}
}
class OrderItemResponse(BaseModel):
"""Позиция заказа в ответе API."""
id: int
order_id: int
nomenclature_id: int
quantity: int
price: Decimal
model_config = {"from_attributes": True}
class OrderCreate(BaseModel):
"""Тело запроса: создание заказа."""
client_id: int = Field(..., description="ID клиента")
model_config = {
"json_schema_extra": {
"example": {
"client_id": 1,
}
}
}
class OrderResponse(BaseModel):
"""Информация о заказе."""
id: int
client_id: int
created_at: datetime
items: List[OrderItemResponse] = []
model_config = {"from_attributes": True}
class NomenclatureResponse(BaseModel):
"""Номенклатура в ответе API."""
id: int
name: str
quantity: int
price: Decimal
category_id: Optional[int] = None
model_config = {"from_attributes": True}
class ErrorResponse(BaseModel):
"""Единообразный формат ошибки."""
detail: str = Field(..., description="Описание ошибки")
code: Optional[str] = Field(None, description="Код ошибки")