
- Setup project structure with FastAPI - Create user models with SQLAlchemy - Implement JWT authentication - Create auth endpoints (register, login, me) - Add health endpoint - Generate Alembic migrations - Update documentation Generated with BackendIM... (backend.im)
46 lines
958 B
Python
46 lines
958 B
Python
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, EmailStr, Field
|
|
|
|
|
|
# Shared properties
|
|
class UserBase(BaseModel):
|
|
email: Optional[EmailStr] = None
|
|
username: Optional[str] = None
|
|
is_active: Optional[bool] = True
|
|
is_superuser: bool = False
|
|
first_name: Optional[str] = None
|
|
last_name: Optional[str] = None
|
|
|
|
|
|
# Properties to receive via API on creation
|
|
class UserCreate(UserBase):
|
|
email: EmailStr
|
|
username: str
|
|
password: str
|
|
|
|
|
|
# Properties to receive via API on update
|
|
class UserUpdate(UserBase):
|
|
password: Optional[str] = None
|
|
|
|
|
|
# Properties shared by models stored in DB
|
|
class UserInDBBase(UserBase):
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
|
|
|
|
# Additional properties to return via API
|
|
class User(UserInDBBase):
|
|
pass
|
|
|
|
|
|
# Additional properties stored in DB
|
|
class UserInDB(UserInDBBase):
|
|
hashed_password: str |