Загрузить файлы в «app»

This commit is contained in:
2026-07-02 17:07:47 +00:00
parent 77092e8517
commit d92bb8f006
2 changed files with 98 additions and 0 deletions

47
app/models.py Normal file
View File

@@ -0,0 +1,47 @@
from datetime import datetime
from sqlalchemy import Boolean, DateTime, Float, ForeignKey, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.database import Base
class User(Base):
__tablename__ = "users"
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
email: Mapped[str] = mapped_column(String(255), unique=True, index=True, nullable=False)
password_hash: Mapped[str] = mapped_column(String(255), nullable=False)
rating: Mapped[float] = mapped_column(Float, default=0.0)
points: Mapped[int] = mapped_column(Integer, default=0)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
sessions: Mapped[list["Session"]] = relationship(back_populates="user", cascade="all, delete-orphan")
external_data: Mapped[list["ExternalData"]] = relationship(
back_populates="user", cascade="all, delete-orphan"
)
class Session(Base):
__tablename__ = "sessions"
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False, index=True)
token: Mapped[str] = mapped_column(String(64), unique=True, index=True, nullable=False)
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
expires_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
user: Mapped["User"] = relationship(back_populates="sessions")
class ExternalData(Base):
__tablename__ = "external_data"
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False, index=True)
source: Mapped[str] = mapped_column(String(128), nullable=False)
payload: Mapped[str] = mapped_column(Text, nullable=False)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
user: Mapped["User"] = relationship(back_populates="external_data")

51
app/schemas.py Normal file
View File

@@ -0,0 +1,51 @@
from datetime import datetime
from pydantic import BaseModel, EmailStr, Field
class UserRegister(BaseModel):
email: EmailStr
password: str = Field(min_length=6, max_length=128)
class UserLogin(BaseModel):
email: EmailStr
password: str
class UserPublic(BaseModel):
id: int
email: str
rating: float
points: int
created_at: datetime
class Config:
from_attributes = True
class SessionPublic(BaseModel):
id: int
created_at: datetime
expires_at: datetime
is_active: bool
class Config:
from_attributes = True
class ExternalDataCreate(BaseModel):
source: str = Field(min_length=1, max_length=128)
payload: dict | str
points_delta: int = 0
rating_delta: float = 0.0
class ExternalDataPublic(BaseModel):
id: int
source: str
payload: str
created_at: datetime
class Config:
from_attributes = True