-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemas.py
More file actions
230 lines (196 loc) · 5.28 KB
/
schemas.py
File metadata and controls
230 lines (196 loc) · 5.28 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
from pydantic import BaseModel, Field, EmailStr
from datetime import date, datetime
from enum import Enum
from typing import Optional
class MonthEnum(str, Enum):
january = "January"
february = "February"
march = "March"
april = "April"
may = "May"
june = "June"
july = "July"
august = "August"
september = "September"
october = "October"
november = "November"
december = "December"
class RegistrationStatusEnum(str, Enum):
pending = "pending"
verified = "verified"
rejected = "rejected"
class TokenStatusEnum(str, Enum):
pending = "pending"
verified = "verified"
rejected = "rejected"
class PayoutStatusEnum(str, Enum):
pending = "pending"
delivered = "delivered"
defaulted = "defaulted"
# This is the schema for creating a farmer
class FarmerCreate(BaseModel):
name: str
country: str
region: str
address: str # New field
farm_size_ha: Optional[float] = None
contact: Optional[str] = None
identity_document: Optional[str] = None # e.g. URL or filename
class FarmerOut(BaseModel):
farmer_id: int = Field(alias="id")
name: str
country: str
region: str
address: str # New field
farm_size_ha: Optional[float]
contact: Optional[str]
identity_document: str
registration_status: RegistrationStatusEnum
registered_at: datetime
model_config = {
"from_attributes": True,
"populate_by_name": True,
"ser_json_by_alias": True
}
class FarmerStatusUpdate(BaseModel):
farmer_id: int
new_status: RegistrationStatusEnum
# This is the schema for creating a crop
class CropCreate(BaseModel):
crop_name: str
variety: Optional[str] = None
planting_date: date
expected_harvest_month: MonthEnum
farmer_id: int
farm_location: Optional[str] = None
organic_certified: Optional[bool] = False
class CropOut(BaseModel):
crop_id: int = Field(alias="id")
crop_name: str
variety: Optional[str]
planting_date: date
expected_harvest_month: MonthEnum
farmer_id: int
farm_location: Optional[str]
organic_certified: bool
model_config = {
"from_attributes": True,
"populate_by_name": True,
"ser_json_by_alias": True
}
# This is the schema for creating a token
class TokenCreate(BaseModel):
crop_id: int
token_count: int
price_per_token: int
expected_yield_unit: str
expected_total_yield: int
expected_roi: float
funding_deadline: date
currency: str = "USDT"
token_status: TokenStatusEnum = TokenStatusEnum.pending
class TokenOut(BaseModel):
token_id: int = Field(alias="id")
crop_id: int
crop_name: str
crop_variety: str
country: str
region: str
organic_certified: bool
token_count: int
price_per_token: int
expected_yield_unit: str
expected_total_yield: int
expected_roi: float
tokens_sold: int
is_funded: bool
funding_deadline: date
currency: str
status: str
created_at: datetime
funding_percentage: Optional[float] = None
tokens_left: Optional[int] = None
token_status: TokenStatusEnum
planting_date: Optional[date] = None
expected_harvest_month: Optional[str] = None
model_config = {
"from_attributes": True,
"populate_by_name": True,
"ser_json_by_alias": True
}
# This is the schema for investment requests
class TokenInvestmentRequest(BaseModel):
token_id: int
investor_id: str
quantity: int
class InvestmentOut(BaseModel):
investment_id: int = Field(alias="id")
token_id: int
investor_id: str
quantity: int
invested_at: datetime
model_config = {
"from_attributes": True,
"populate_by_name": True,
"ser_json_by_alias": True
}
# This is the schema for creating a contract
class ContractCreate(BaseModel):
token_id: int
quantity: int
delivery_type: str # "money" or "product"
class ContractOut(BaseModel):
id: int
token_id: int
farmer_id: int
investor_id: int
quantity: int
price_per_token: int
total_value: int
delivery_type: str
expected_roi: float
expected_harvest_month: MonthEnum
payout_status: PayoutStatusEnum
created_at: datetime
crop_name: Optional[str] = None
crop_variety: Optional[str] = None
model_config = {
"from_attributes": True,
"populate_by_name": True,
"ser_json_by_alias": True
}
class FarmerRegisterRequest(BaseModel):
email: EmailStr
password: str
class FarmerLoginRequest(BaseModel):
email: EmailStr
password: str
class FarmerAuthOut(BaseModel):
id: int
email: EmailStr
model_config = {
"from_attributes": True
}
class AuthWithFarmer(BaseModel):
access_token: str
token_type: str = "bearer"
farmer: FarmerAuthOut
class InvestorRegisterRequest(BaseModel):
email: str
password: str
class InvestorLoginRequest(BaseModel):
email: str
password: str
class InvestorAccountOut(BaseModel):
investor_id: int = Field(alias="id")
email: str
created_at: datetime
model_config = {
"from_attributes": True,
"populate_by_name": True,
"ser_json_by_alias": True
}
class AuthWithInvestor(BaseModel):
access_token: str
token_type: str
investor: InvestorAccountOut