Spaces:
Runtime error
Runtime error
File size: 4,108 Bytes
cb7f5fc |
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 |
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}
|