Add User schema
This commit is contained in:
parent
98c2126a2e
commit
b682cb0091
@ -1,38 +1,32 @@
|
|||||||
from pydantic import BaseModel, Field, EmailStr
|
from pydantic import BaseModel, Field
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
class UserBase(BaseModel):
|
class UserBase(BaseModel):
|
||||||
username: str = Field(..., min_length=3, max_length=50)
|
session_token: Optional[str] = Field(None, unique=True)
|
||||||
email: EmailStr = Field(...)
|
is_logged_in: bool = Field(default=False)
|
||||||
|
last_logout: Optional[datetime] = None
|
||||||
|
last_login: Optional[datetime] = None
|
||||||
|
|
||||||
class UserCreate(UserBase):
|
class UserCreate(UserBase):
|
||||||
password: str = Field(..., min_length=8, max_length=100)
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
schema_extra = {
|
schema_extra = {
|
||||||
"example": {
|
"example": {
|
||||||
"username": "johndoe",
|
"session_token": "abc123xyz789",
|
||||||
"email": "john@example.com",
|
"is_logged_in": False,
|
||||||
"password": "securepass123"
|
"last_logout": "2023-01-01T12:00:00",
|
||||||
|
"last_login": "2023-01-01T10:00:00"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserResponse(UserBase):
|
class User(UserBase):
|
||||||
is_active: bool = True
|
|
||||||
is_logged_in: bool = False
|
|
||||||
last_logout: Optional[datetime] = None
|
|
||||||
session_token: Optional[str] = None
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
schema_extra = {
|
schema_extra = {
|
||||||
"example": {
|
"example": {
|
||||||
"username": "johndoe",
|
"session_token": "abc123xyz789",
|
||||||
"email": "john@example.com",
|
"is_logged_in": True,
|
||||||
"is_active": True,
|
"last_logout": "2023-01-01T18:00:00",
|
||||||
"is_logged_in": False,
|
"last_login": "2023-01-01T09:00:00"
|
||||||
"last_logout": "2023-01-01T00:00:00",
|
|
||||||
"session_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user