feat: define Pydantic schemas for data validation and API serialization
Browse files- backend/app/schemas/schemas.py +111 -1
backend/app/schemas/schemas.py
CHANGED
|
@@ -1 +1,111 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import uuid
|
| 2 |
+
import datetime
|
| 3 |
+
from typing import Optional, List
|
| 4 |
+
from pydantic import BaseModel, Field, ConfigDict
|
| 5 |
+
|
| 6 |
+
# AUTHENTICATION & USER SCHEMAS
|
| 7 |
+
class GoogleAuthRequest(BaseModel):
|
| 8 |
+
token_id: str= Field(description= "Google OAuth ID Token received on the frontend")
|
| 9 |
+
|
| 10 |
+
class Token(BaseModel):
|
| 11 |
+
access_token: str
|
| 12 |
+
token_type: str= "bearer"
|
| 13 |
+
|
| 14 |
+
class TokenPayload(BaseModel):
|
| 15 |
+
sub: Optional[str]= None
|
| 16 |
+
|
| 17 |
+
class UserBase(BaseModel):
|
| 18 |
+
email: str
|
| 19 |
+
full_name: Optional[str]= None
|
| 20 |
+
picture_url: Optional[str]= None
|
| 21 |
+
|
| 22 |
+
class UserResponse(UserBase):
|
| 23 |
+
id: uuid.UUID
|
| 24 |
+
google_id: str
|
| 25 |
+
credits: int
|
| 26 |
+
last_credit_refresh: datetime.datetime
|
| 27 |
+
created_at: datetime.datetime
|
| 28 |
+
|
| 29 |
+
model_config= ConfigDict(from_attributes= True)
|
| 30 |
+
|
| 31 |
+
# WATCHLIST SCHEMAS
|
| 32 |
+
class WatchlistBase(BaseModel):
|
| 33 |
+
ticker: str= Field(..., description= "Stock symbol, e.g., AAPL or TCS.NS")
|
| 34 |
+
|
| 35 |
+
class WatchlistCreate(WatchlistBase):
|
| 36 |
+
pass
|
| 37 |
+
|
| 38 |
+
class WatchlistResponse(WatchlistBase):
|
| 39 |
+
id: uuid.UUID
|
| 40 |
+
user_id: uuid.UUID
|
| 41 |
+
created_at: datetime.datetime
|
| 42 |
+
|
| 43 |
+
model_config= ConfigDict(from_attributes= True)
|
| 44 |
+
|
| 45 |
+
# ALERT SCHEMAS
|
| 46 |
+
class AlertBase(BaseModel):
|
| 47 |
+
ticker: str= Field(..., description= "Stock symbol to monitor")
|
| 48 |
+
target_price: float= Field(..., gt=0, description= "Price target that triggers the alert")
|
| 49 |
+
condition: str= Field(..., description= "Trigger condition: 'above' or 'below'")
|
| 50 |
+
|
| 51 |
+
class AlertCreate(AlertBase):
|
| 52 |
+
pass
|
| 53 |
+
|
| 54 |
+
class AlertUpdate(BaseModel):
|
| 55 |
+
target_price: Optional[float]= Field(None, gt=0)
|
| 56 |
+
condition: Optional[str]= None
|
| 57 |
+
is_active: Optional[bool]= None
|
| 58 |
+
|
| 59 |
+
class AlertResponse(AlertBase):
|
| 60 |
+
id: uuid.UUID
|
| 61 |
+
user_id: uuid.UUID
|
| 62 |
+
is_active: bool
|
| 63 |
+
created_at: datetime.datetime
|
| 64 |
+
|
| 65 |
+
model_config= ConfigDict(from_attributes= True)
|
| 66 |
+
|
| 67 |
+
# STOCK HISTORY SCHEMAS
|
| 68 |
+
class StockHistoryBase(BaseModel):
|
| 69 |
+
ticker: str
|
| 70 |
+
timestamp: datetime.datetime
|
| 71 |
+
open: float
|
| 72 |
+
high: float
|
| 73 |
+
low: float
|
| 74 |
+
close: float
|
| 75 |
+
volume: int
|
| 76 |
+
|
| 77 |
+
class StockHistoryResponse(StockHistoryBase):
|
| 78 |
+
model_config= ConfigDict(from_attributes= True)
|
| 79 |
+
|
| 80 |
+
# AI INSIGHTS & CHAT SCHEMAS
|
| 81 |
+
class GeminiInsightResponse(BaseModel):
|
| 82 |
+
ticker: str
|
| 83 |
+
bullish_probability: int= Field(..., ge=0, le= 100)
|
| 84 |
+
reason: str
|
| 85 |
+
credits_remaining: int
|
| 86 |
+
|
| 87 |
+
# PAYMENT & RAZORPAY SCHEMAS
|
| 88 |
+
class PaymentOrderCreate(BaseModel):
|
| 89 |
+
amount: int= Field(..., gt=0, description= "Amount in Rupees, e.g., 100 or 200")
|
| 90 |
+
|
| 91 |
+
class PaymentOrderResponse(BaseModel):
|
| 92 |
+
order_id: str
|
| 93 |
+
amount: int
|
| 94 |
+
currency: str= "INR"
|
| 95 |
+
|
| 96 |
+
class PaymentCaptureRequest(BaseModel):
|
| 97 |
+
razorpay_order_id: str
|
| 98 |
+
razorpay_payment_id: str
|
| 99 |
+
razorpay_signature: str
|
| 100 |
+
|
| 101 |
+
class PaymentTransactionResponse(BaseModel):
|
| 102 |
+
id: uuid.UUID
|
| 103 |
+
user_id: uuid.UUID
|
| 104 |
+
razorpay_order_id: str
|
| 105 |
+
razorpay_payment_id: Optional[str]= None
|
| 106 |
+
amount: int
|
| 107 |
+
status: str
|
| 108 |
+
credits_credited: int
|
| 109 |
+
created_at: datetime.datetime
|
| 110 |
+
|
| 111 |
+
model_config= ConfigDict(from_attributes= True)
|