55 lines
1.1 KiB
Python
55 lines
1.1 KiB
Python
import uuid
|
|
from datetime import datetime
|
|
from typing import Literal, Optional
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
UserRole = Literal["PM", "CRA", "PV", "IMP", "ADMIN"]
|
|
|
|
|
|
class UserBase(BaseModel):
|
|
username: str = Field(min_length=1)
|
|
role: UserRole
|
|
is_active: bool = True
|
|
|
|
|
|
class UserCreate(BaseModel):
|
|
username: str = Field(min_length=1)
|
|
password: str = Field(min_length=1)
|
|
role: UserRole
|
|
|
|
|
|
class UserRead(BaseModel):
|
|
id: uuid.UUID
|
|
username: str
|
|
role: UserRole
|
|
is_active: bool
|
|
created_at: datetime
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class UserUpdate(BaseModel):
|
|
role: Optional[UserRole] = None
|
|
is_active: Optional[bool] = None
|
|
password: Optional[str] = Field(default=None, min_length=1)
|
|
|
|
|
|
class UserInDB(UserBase):
|
|
id: uuid.UUID
|
|
hashed_password: str
|
|
created_at: datetime
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class Token(BaseModel):
|
|
access_token: str
|
|
token_type: str = "bearer"
|
|
|
|
|
|
class TokenPayload(BaseModel):
|
|
sub: uuid.UUID
|
|
role: str
|
|
exp: Optional[int] = None
|