Spaces:
Runtime error
Runtime error
| from typing import Optional | |
| from pydantic import BaseModel, Field, EmailStr | |
| class StudentSchema(BaseModel): | |
| name: str = Field(..., example="John Doe", | |
| description="Name of the student") | |
| email: EmailStr = Field(..., example="johndoe@gmail.com", | |
| description="Email of the student") | |
| password: str = Field(..., example="JohnDoe123", | |
| description="Password of the student") | |
| year: int = Field(..., gt=0, lt=5, example=1, description="Year of study") | |
| branch: str = Field(..., min_length=3, | |
| example="CSE or Computer Science and Engineering", description="Branch of study") | |
| division: str = Field(..., min_length=1, max_length=1, | |
| example="A", description="Division of study") | |
| pin: str = Field(..., min_length=10, max_length=10, | |
| example="20KJ1A0501", description="PIN of the student") | |
| gpa: Optional[float] = Field( | |
| None, gt=0, lt=10, example=9.0, description="GPA of the student") | |
| phone: int = Field(..., gt=1000000000, lt=9999999999, | |
| example=1234567890, description="Phone number of the student") | |
| address: str = Field(..., min_length=3, max_length=100, | |
| example="123, 1st cross, 1st main, City, State, Country - 123456", description="Address of the student") | |
| class Config: | |
| schema_extra = { | |
| "Example": { | |
| "name": "John Doe", | |
| "email": "Johndoe@example.com", | |
| "password": "JohnDoe123", | |
| "year": 1, | |
| "branch": "CSE", | |
| "division": "A", | |
| "pin": "20KJ1A0501", | |
| "gpa": 9.0, | |
| "phone": 1234567890, | |
| "address": """ | |
| 123, 1st cross, 1st main, | |
| City, State, Country - 123456""", | |
| } | |
| } | |
| class StudentUpdateSchema(BaseModel): | |
| name: Optional[str] = Field( | |
| None, example="John Doe", description="Name of the student") | |
| email: Optional[EmailStr] = Field( | |
| None, example="johndoe@example.com", description="Email") | |
| password: Optional[str] = Field( | |
| None, example="JohnDoe123", description="Password") | |
| year: Optional[int] = Field( | |
| None, gt=0, lt=5, example=1, description="Year of study") | |
| branch: Optional[str] = Field( | |
| None, min_length=3, example="CSE or Computer Science and Engineering", description="Branch of study") | |
| division: Optional[str] = Field( | |
| None, min_length=1, max_length=1, example="A", description="Division of study") | |
| pin: Optional[str] = Field(None, min_length=10, max_length=10, | |
| example="20KJ1A0501", description="PIN of the student") | |
| gpa: Optional[float] = Field( | |
| None, gt=0, lt=10, example=9.0, description="GPA of the student") | |
| phone: Optional[int] = Field(None, gt=1000000000, lt=9999999999, | |
| example=1234567890, description="Phone number of the student") | |
| address: Optional[str] = Field(None, min_length=3, max_length=100, | |
| example="123, 1st cross, 1st main, City, State, Country - 123456", | |
| description="Address of the student") | |
| class Config: | |
| schema_extra = { | |
| "Example": { | |
| "name": "John Doe", | |
| "email": "Johndoe@example.com", | |
| "password": "JohnDoe123", | |
| "year": 1, | |
| "branch": "CSE", | |
| "division": "A", | |
| "pin": "20KJ1A0501", | |
| "gpa": 9.0, | |
| "phone": 1234567890, | |
| "address": """ | |
| 123, 1st cross, 1st main, | |
| City, State, Country - 123456""", | |
| } | |
| } | |
| def ResponseModel(data, message): | |
| return { | |
| "data": [data], | |
| "code": 200, | |
| "message": message, | |
| } | |
| def ErrorResponseModel(error, code, message): | |
| return {"error": error, "code": code, "message": message} | |