-
Notifications
You must be signed in to change notification settings - Fork 0
/
schemas.py
56 lines (37 loc) · 1.78 KB
/
schemas.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
from datetime import datetime
from itertools import count
from typing import Literal, Optional
from pydantic import BaseModel, Field
class DepositRequest(BaseModel):
account: str = Field(..., json_schema_extra={"example": "DE000000000000000000000"})
amount: float = Field(..., json_schema_extra={"example": 50.0})
class DepositResponse(BaseModel):
account: str
new_balance: float
class WithdrawRequest(BaseModel):
account: str = Field(..., json_schema_extra={"example": "DE000000000000000000000"})
amount: float = Field(..., json_schema_extra={"example": 50.0})
class WithdrawResponse(BaseModel):
account: str
new_balance: float
class TransferRequest(BaseModel):
src_account: str = Field(..., json_schema_extra={"example": "DE000000000000000000000"})
dest_account: str = Field(..., json_schema_extra={"example": "DE000000000000000000001"})
amount: float = Field(..., json_schema_extra={"example": 50.0})
class TransferResponse(BaseModel):
src_account: str
dest_account: str
src_new_balance: float
dest_new_balance: float
class Transaction(BaseModel):
id: int = Field(default_factory=lambda: next(transaction_id_counter), example=1)
src_account: str = Field(..., example="A1")
type: Literal["deposit", "withdraw", "transfer"] = Field(..., example="deposit")
amount: float = Field(..., example=100.0)
dest_account: Optional[str] = Field(None, example="B1") # Nullable, relevant only for transfers
timestamp: datetime = Field(default_factory=datetime.utcnow, example="2024-01-01T12:00:00Z")
balance: float = Field(..., example=500.0) # Add a balance field
class AccountCreateRequest(BaseModel):
account_number: str
# Initialize a global counter for auto-incrementing the ID
transaction_id_counter = count(1)