
Features: - User authentication with JWT - Client management with CRUD operations - Invoice generation and management - SQLite database with Alembic migrations - Detailed project documentation
61 lines
1.4 KiB
Python
61 lines
1.4 KiB
Python
from typing import List, Optional
|
|
|
|
from pydantic import BaseModel, EmailStr, Field, validator
|
|
|
|
|
|
# Shared properties
|
|
class UserBase(BaseModel):
|
|
email: EmailStr
|
|
full_name: str
|
|
company_name: Optional[str] = None
|
|
address: Optional[str] = None
|
|
phone: Optional[str] = None
|
|
is_active: bool = True
|
|
|
|
|
|
# Properties to receive via API on creation
|
|
class UserCreate(UserBase):
|
|
password: str = Field(..., min_length=8)
|
|
|
|
@validator("password")
|
|
def password_validation(cls, v):
|
|
if len(v) < 8:
|
|
raise ValueError("Password must be at least 8 characters long")
|
|
return v
|
|
|
|
|
|
# Properties to receive via API on update
|
|
class UserUpdate(UserBase):
|
|
email: Optional[EmailStr] = None
|
|
full_name: Optional[str] = None
|
|
password: Optional[str] = None
|
|
|
|
@validator("password")
|
|
def password_validation(cls, v):
|
|
if v is not None and len(v) < 8:
|
|
raise ValueError("Password must be at least 8 characters long")
|
|
return v
|
|
|
|
|
|
# Properties shared by models stored in DB
|
|
class UserInDBBase(UserBase):
|
|
id: int
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
|
|
|
|
# Properties to return via API
|
|
class User(UserInDBBase):
|
|
pass
|
|
|
|
|
|
# Properties stored in DB
|
|
class UserInDB(UserInDBBase):
|
|
hashed_password: str
|
|
|
|
|
|
# User with clients
|
|
class UserWithClients(User):
|
|
from app.schemas.client import Client
|
|
clients: List[Client] = [] |