load project
This commit is contained in:
14
backend/app/models/__init__.py
Normal file
14
backend/app/models/__init__.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from app.models.document import FilledDocument
|
||||
from app.models.template import DocumentTemplate, TemplateVariable
|
||||
from app.models.user import User, UserRole
|
||||
from app.models.verification_token import TokenType, VerificationToken
|
||||
|
||||
__all__ = [
|
||||
"User",
|
||||
"UserRole",
|
||||
"DocumentTemplate",
|
||||
"TemplateVariable",
|
||||
"FilledDocument",
|
||||
"VerificationToken",
|
||||
"TokenType",
|
||||
]
|
||||
23
backend/app/models/document.py
Normal file
23
backend/app/models/document.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, ForeignKey, String, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class FilledDocument(Base):
|
||||
__tablename__ = "filled_documents"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
||||
template_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("document_templates.id", ondelete="CASCADE")
|
||||
)
|
||||
owner_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"))
|
||||
name: Mapped[str] = mapped_column(String(255))
|
||||
field_data: Mapped[str] = mapped_column(Text)
|
||||
rendered_docx_path: Mapped[str | None] = mapped_column(String(512), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
|
||||
template = relationship("DocumentTemplate", back_populates="documents")
|
||||
owner = relationship("User", back_populates="documents")
|
||||
54
backend/app/models/template.py
Normal file
54
backend/app/models/template.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, ForeignKey, Integer, String, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class DocumentTemplate(Base):
|
||||
__tablename__ = "document_templates"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
||||
name: Mapped[str] = mapped_column(String(255))
|
||||
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
original_filename: Mapped[str] = mapped_column(String(255))
|
||||
file_path: Mapped[str] = mapped_column(String(512))
|
||||
owner_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"))
|
||||
is_public: Mapped[bool] = mapped_column(default=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime, default=datetime.utcnow, onupdate=datetime.utcnow
|
||||
)
|
||||
|
||||
owner = relationship("User", back_populates="templates")
|
||||
variables = relationship(
|
||||
"TemplateVariable",
|
||||
back_populates="template",
|
||||
cascade="all, delete-orphan",
|
||||
order_by="TemplateVariable.order",
|
||||
)
|
||||
documents = relationship(
|
||||
"FilledDocument",
|
||||
back_populates="template",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
|
||||
|
||||
class TemplateVariable(Base):
|
||||
__tablename__ = "template_variables"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
||||
template_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("document_templates.id", ondelete="CASCADE")
|
||||
)
|
||||
name: Mapped[str] = mapped_column(String(255))
|
||||
label: Mapped[str] = mapped_column(String(255))
|
||||
field_type: Mapped[str] = mapped_column(String(50))
|
||||
default_value: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
is_required: Mapped[bool] = mapped_column(default=True)
|
||||
order: Mapped[int] = mapped_column(Integer, default=0)
|
||||
parent_variable: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
style_params: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
|
||||
template = relationship("DocumentTemplate", back_populates="variables")
|
||||
40
backend/app/models/user.py
Normal file
40
backend/app/models/user.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import enum
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, Enum, ForeignKey, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class UserRole(str, enum.Enum):
|
||||
user = "user"
|
||||
admin = "admin"
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
||||
email: Mapped[str] = mapped_column(String(255), unique=True, index=True)
|
||||
username: Mapped[str] = mapped_column(String(100), unique=True, index=True)
|
||||
hashed_password: Mapped[str] = mapped_column(String(255))
|
||||
role: Mapped[UserRole] = mapped_column(Enum(UserRole), default=UserRole.user)
|
||||
is_active: Mapped[bool] = mapped_column(default=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
|
||||
templates = relationship(
|
||||
"DocumentTemplate",
|
||||
back_populates="owner",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
documents = relationship(
|
||||
"FilledDocument",
|
||||
back_populates="owner",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
verification_tokens = relationship(
|
||||
"VerificationToken",
|
||||
back_populates="user",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
25
backend/app/models/verification_token.py
Normal file
25
backend/app/models/verification_token.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import enum
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, Enum, ForeignKey, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class TokenType(str, enum.Enum):
|
||||
activation = "activation"
|
||||
password_reset = "password_reset"
|
||||
|
||||
|
||||
class VerificationToken(Base):
|
||||
__tablename__ = "verification_tokens"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"))
|
||||
code: Mapped[str] = mapped_column(String(10), index=True)
|
||||
token_type: Mapped[TokenType] = mapped_column(Enum(TokenType))
|
||||
expires_at: Mapped[datetime] = mapped_column(DateTime)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
|
||||
user = relationship("User", back_populates="verification_tokens")
|
||||
Reference in New Issue
Block a user