Init project structure

This commit is contained in:
k1nq
2025-11-22 13:56:45 +05:00
parent ad0025be28
commit 74330b292f
25 changed files with 1343 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
"""Model exports for Alembic discovery."""
from app.models.base import Base
from app.models.user import User
__all__ = ["Base", "User"]
+10
View File
@@ -0,0 +1,10 @@
"""Declarative base for SQLAlchemy models."""
from sqlalchemy.orm import DeclarativeBase, declared_attr
class Base(DeclarativeBase):
"""Base class that configures naming conventions."""
@declared_attr.directive
def __tablename__(cls) -> str: # type: ignore[misc]
return cls.__name__.lower()
+23
View File
@@ -0,0 +1,23 @@
"""Token-related Pydantic schemas."""
from __future__ import annotations
from datetime import datetime
from pydantic import BaseModel, EmailStr
class TokenPayload(BaseModel):
sub: str
exp: datetime
email: EmailStr | None = None
class TokenResponse(BaseModel):
access_token: str
token_type: str = "bearer"
expires_in: int
class LoginRequest(BaseModel):
email: EmailStr
password: str
+48
View File
@@ -0,0 +1,48 @@
"""User ORM model and Pydantic schemas."""
from __future__ import annotations
from datetime import datetime
from pydantic import BaseModel, ConfigDict, EmailStr
from sqlalchemy import Boolean, DateTime, Integer, String, func
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base
class User(Base):
"""SQLAlchemy model for application users."""
__tablename__ = "users"
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
email: Mapped[str] = mapped_column(String(320), unique=True, index=True, nullable=False)
hashed_password: Mapped[str] = mapped_column(String(255), nullable=False)
full_name: Mapped[str | None] = mapped_column(String(255), nullable=True)
is_active: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), nullable=False
)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False
)
class UserBase(BaseModel):
"""Shared user fields for Pydantic schemas."""
email: EmailStr
full_name: str | None = None
is_active: bool = True
class UserCreate(UserBase):
password: str
class UserRead(UserBase):
id: int
created_at: datetime
updated_at: datetime
model_config = ConfigDict(from_attributes=True)