feat: implement AI legal assistant system MVP
Core modules: - Laws: CRUD, search, AI-powered QA - Analysis: legal research and case management - Contracts: lifecycle management with templates - Signatures: electronic signature workflow Infrastructure: - FastAPI + SQLite + async SQLAlchemy - Docker deployment support - 54 unit tests passing Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
830b33c4b3
commit
656f596d7e
51 files changed
+3690
No files matched your search
@@ -0,0 +1 @@
|
||||
# Models package
|
||||
@@ -0,0 +1,96 @@
|
||||
"""Analysis model for legal research."""
|
||||
import enum
|
||||
from datetime import date, datetime
|
||||
from typing import Optional, List
|
||||
|
||||
from sqlalchemy import String, Text, Date, DateTime, Enum as SQLEnum, Integer, ForeignKey, JSON
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class AnalysisStatus(str, enum.Enum):
|
||||
"""Analysis status enumeration."""
|
||||
DRAFT = "draft"
|
||||
IN_PROGRESS = "in_progress"
|
||||
COMPLETED = "completed"
|
||||
|
||||
|
||||
class LegalAnalysis(Base):
|
||||
"""Legal analysis model."""
|
||||
|
||||
__tablename__ = "legal_analyses"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
user_id: Mapped[int] = mapped_column(Integer, ForeignKey("users.id"), index=True)
|
||||
title: Mapped[str] = mapped_column(String(200))
|
||||
case_description: Mapped[str] = mapped_column(Text)
|
||||
legal_basis: Mapped[Optional[dict]] = mapped_column(JSON, nullable=True)
|
||||
analysis_content: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
conclusion: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
status: Mapped[AnalysisStatus] = mapped_column(
|
||||
SQLEnum(AnalysisStatus),
|
||||
default=AnalysisStatus.DRAFT
|
||||
)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
user_id: int,
|
||||
title: str,
|
||||
case_description: str,
|
||||
legal_basis: Optional[dict] = None,
|
||||
analysis_content: Optional[str] = None,
|
||||
conclusion: Optional[str] = None,
|
||||
status: AnalysisStatus = AnalysisStatus.DRAFT,
|
||||
**kwargs
|
||||
):
|
||||
self.user_id = user_id
|
||||
self.title = title
|
||||
self.case_description = case_description
|
||||
self.legal_basis = legal_basis
|
||||
self.analysis_content = analysis_content
|
||||
self.conclusion = conclusion
|
||||
self.status = status
|
||||
self.created_at = datetime.utcnow()
|
||||
self.updated_at = datetime.utcnow()
|
||||
|
||||
|
||||
class Case(Base):
|
||||
"""Case model for case database."""
|
||||
|
||||
__tablename__ = "cases"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
title: Mapped[str] = mapped_column(String(200), index=True)
|
||||
case_number: Mapped[Optional[str]] = mapped_column(String(50), nullable=True)
|
||||
court: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
|
||||
case_type: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
|
||||
judgment_date: Mapped[Optional[date]] = mapped_column(Date, nullable=True)
|
||||
facts: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
judgment: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
reasoning: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
title: str,
|
||||
case_number: Optional[str] = None,
|
||||
court: Optional[str] = None,
|
||||
case_type: Optional[str] = None,
|
||||
judgment_date: Optional[date] = None,
|
||||
facts: Optional[str] = None,
|
||||
judgment: Optional[str] = None,
|
||||
reasoning: Optional[str] = None,
|
||||
**kwargs
|
||||
):
|
||||
self.title = title
|
||||
self.case_number = case_number
|
||||
self.court = court
|
||||
self.case_type = case_type
|
||||
self.judgment_date = judgment_date
|
||||
self.facts = facts
|
||||
self.judgment = judgment
|
||||
self.reasoning = reasoning
|
||||
self.created_at = datetime.utcnow()
|
||||
@@ -0,0 +1,60 @@
|
||||
"""Case review model."""
|
||||
import enum
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import String, Text, DateTime, Enum as SQLEnum, Integer, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class ReviewStatus(str, enum.Enum):
|
||||
"""Review status enumeration."""
|
||||
PENDING = "pending"
|
||||
APPROVED = "approved"
|
||||
REJECTED = "rejected"
|
||||
|
||||
|
||||
class ReviewType(str, enum.Enum):
|
||||
"""Review type enumeration."""
|
||||
INITIAL = "initial"
|
||||
SECONDARY = "secondary"
|
||||
FINAL = "final"
|
||||
|
||||
|
||||
class CaseReview(Base):
|
||||
"""Case review model."""
|
||||
|
||||
__tablename__ = "case_reviews"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
case_id: Mapped[int] = mapped_column(Integer, ForeignKey("cases.id"), index=True)
|
||||
reviewer_id: Mapped[int] = mapped_column(Integer, ForeignKey("users.id"), index=True)
|
||||
review_type: Mapped[ReviewType] = mapped_column(SQLEnum(ReviewType))
|
||||
opinion: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
score: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
|
||||
status: Mapped[ReviewStatus] = mapped_column(
|
||||
SQLEnum(ReviewStatus),
|
||||
default=ReviewStatus.PENDING
|
||||
)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||
reviewed_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
case_id: int,
|
||||
reviewer_id: int,
|
||||
review_type: ReviewType,
|
||||
opinion: Optional[str] = None,
|
||||
score: Optional[int] = None,
|
||||
status: ReviewStatus = ReviewStatus.PENDING,
|
||||
**kwargs
|
||||
):
|
||||
self.case_id = case_id
|
||||
self.reviewer_id = reviewer_id
|
||||
self.review_type = review_type
|
||||
self.opinion = opinion
|
||||
self.score = score
|
||||
self.status = status
|
||||
self.created_at = datetime.utcnow()
|
||||
@@ -0,0 +1,131 @@
|
||||
"""Contract model."""
|
||||
import enum
|
||||
from datetime import date, datetime
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import String, Text, Date, DateTime, Enum as SQLEnum, Integer, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class ContractStatus(str, enum.Enum):
|
||||
"""Contract status enumeration."""
|
||||
DRAFT = "draft"
|
||||
PENDING_APPROVAL = "pending_approval"
|
||||
APPROVED = "approved"
|
||||
PENDING_SIGNATURE = "pending_signature"
|
||||
SIGNED = "signed"
|
||||
ARCHIVED = "archived"
|
||||
REJECTED = "rejected"
|
||||
|
||||
|
||||
class Contract(Base):
|
||||
"""Contract model."""
|
||||
|
||||
__tablename__ = "contracts"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
template_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("contract_templates.id"), nullable=True)
|
||||
title: Mapped[str] = mapped_column(String(200), index=True)
|
||||
contract_number: Mapped[Optional[str]] = mapped_column(String(50), nullable=True)
|
||||
party_a: Mapped[str] = mapped_column(String(100))
|
||||
party_b: Mapped[str] = mapped_column(String(100))
|
||||
content: Mapped[str] = mapped_column(Text)
|
||||
status: Mapped[ContractStatus] = mapped_column(
|
||||
SQLEnum(ContractStatus),
|
||||
default=ContractStatus.DRAFT
|
||||
)
|
||||
effective_date: Mapped[Optional[date]] = mapped_column(Date, nullable=True)
|
||||
expiry_date: Mapped[Optional[date]] = mapped_column(Date, nullable=True)
|
||||
file_path: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
|
||||
created_by: Mapped[int] = mapped_column(Integer, ForeignKey("users.id"))
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
title: str,
|
||||
party_a: str,
|
||||
party_b: str,
|
||||
content: str,
|
||||
created_by: int,
|
||||
template_id: Optional[int] = None,
|
||||
contract_number: Optional[str] = None,
|
||||
status: ContractStatus = ContractStatus.DRAFT,
|
||||
effective_date: Optional[date] = None,
|
||||
expiry_date: Optional[date] = None,
|
||||
file_path: Optional[str] = None,
|
||||
**kwargs
|
||||
):
|
||||
self.title = title
|
||||
self.party_a = party_a
|
||||
self.party_b = party_b
|
||||
self.content = content
|
||||
self.created_by = created_by
|
||||
self.template_id = template_id
|
||||
self.contract_number = contract_number
|
||||
self.status = status
|
||||
self.effective_date = effective_date
|
||||
self.expiry_date = expiry_date
|
||||
self.file_path = file_path
|
||||
self.created_at = datetime.utcnow()
|
||||
self.updated_at = datetime.utcnow()
|
||||
|
||||
|
||||
class ContractTemplate(Base):
|
||||
"""Contract template model."""
|
||||
|
||||
__tablename__ = "contract_templates"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
name: Mapped[str] = mapped_column(String(100))
|
||||
contract_type: Mapped[Optional[str]] = mapped_column(String(50), nullable=True)
|
||||
content: Mapped[str] = mapped_column(Text)
|
||||
variables: Mapped[Optional[dict]] = mapped_column(String, nullable=True) # JSON string
|
||||
created_by: Mapped[int] = mapped_column(Integer, ForeignKey("users.id"))
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
content: str,
|
||||
created_by: int,
|
||||
contract_type: Optional[str] = None,
|
||||
variables: Optional[dict] = None,
|
||||
**kwargs
|
||||
):
|
||||
self.name = name
|
||||
self.content = content
|
||||
self.created_by = created_by
|
||||
self.contract_type = contract_type
|
||||
self.variables = variables
|
||||
self.created_at = datetime.utcnow()
|
||||
|
||||
|
||||
class ContractApproval(Base):
|
||||
"""Contract approval model."""
|
||||
|
||||
__tablename__ = "contract_approvals"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
contract_id: Mapped[int] = mapped_column(Integer, ForeignKey("contracts.id"), index=True)
|
||||
approver_id: Mapped[int] = mapped_column(Integer, ForeignKey("users.id"), index=True)
|
||||
status: Mapped[ContractStatus] = mapped_column(SQLEnum(ContractStatus))
|
||||
comment: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||
approved_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
contract_id: int,
|
||||
approver_id: int,
|
||||
status: ContractStatus,
|
||||
comment: Optional[str] = None,
|
||||
**kwargs
|
||||
):
|
||||
self.contract_id = contract_id
|
||||
self.approver_id = approver_id
|
||||
self.status = status
|
||||
self.comment = comment
|
||||
self.created_at = datetime.utcnow()
|
||||
@@ -0,0 +1,106 @@
|
||||
"""Law model for legal regulations."""
|
||||
import enum
|
||||
from datetime import date, datetime
|
||||
from typing import Optional, List
|
||||
|
||||
from sqlalchemy import String, Text, Date, DateTime, Enum as SQLEnum, Integer, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class LawType(str, enum.Enum):
|
||||
"""Law type enumeration."""
|
||||
LAW = "law" # 法律
|
||||
REGULATION = "regulation" # 法规
|
||||
RULE = "rule" # 规章
|
||||
JUDICIAL_INTERPRETATION = "judicial_interpretation" # 司法解释
|
||||
|
||||
|
||||
class LawStatus(str, enum.Enum):
|
||||
"""Law status enumeration."""
|
||||
EFFECTIVE = "effective" # 有效
|
||||
REVOKED = "revoked" # 废止
|
||||
AMENDED = "amended" # 修订
|
||||
|
||||
|
||||
class Law(Base):
|
||||
"""Law model for legal regulations."""
|
||||
|
||||
__tablename__ = "laws"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
title: Mapped[str] = mapped_column(String(200), index=True)
|
||||
law_type: Mapped[LawType] = mapped_column(SQLEnum(LawType), nullable=False)
|
||||
promulgation_date: Mapped[date] = mapped_column(Date, nullable=False)
|
||||
effective_date: Mapped[date] = mapped_column(Date, nullable=False)
|
||||
status: Mapped[LawStatus] = mapped_column(
|
||||
SQLEnum(LawStatus),
|
||||
nullable=False
|
||||
)
|
||||
issuing_authority: Mapped[str] = mapped_column(String(100))
|
||||
content: Mapped[str] = mapped_column(Text)
|
||||
document_number: Mapped[Optional[str]] = mapped_column(String(50), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||
|
||||
# Relationships
|
||||
articles: Mapped[List["LawArticle"]] = relationship(
|
||||
back_populates="law", cascade="all, delete-orphan"
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
title: str,
|
||||
law_type: LawType,
|
||||
promulgation_date: date,
|
||||
effective_date: date,
|
||||
issuing_authority: str,
|
||||
content: str,
|
||||
status: LawStatus = LawStatus.EFFECTIVE,
|
||||
document_number: Optional[str] = None,
|
||||
**kwargs
|
||||
):
|
||||
self.title = title
|
||||
self.law_type = law_type
|
||||
self.promulgation_date = promulgation_date
|
||||
self.effective_date = effective_date
|
||||
self.status = status
|
||||
self.issuing_authority = issuing_authority
|
||||
self.content = content
|
||||
self.document_number = document_number
|
||||
self.created_at = datetime.utcnow()
|
||||
self.updated_at = datetime.utcnow()
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Law(id={self.id}, title={self.title})>"
|
||||
|
||||
|
||||
class LawArticle(Base):
|
||||
"""Law article model for individual articles."""
|
||||
|
||||
__tablename__ = "law_articles"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
law_id: Mapped[int] = mapped_column(Integer, ForeignKey("laws.id"), index=True)
|
||||
article_number: Mapped[str] = mapped_column(String(20))
|
||||
content: Mapped[str] = mapped_column(Text)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||
|
||||
# Relationships
|
||||
law: Mapped["Law"] = relationship(back_populates="articles")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
law_id: int,
|
||||
article_number: str,
|
||||
content: str,
|
||||
**kwargs
|
||||
):
|
||||
self.law_id = law_id
|
||||
self.article_number = article_number
|
||||
self.content = content
|
||||
self.created_at = datetime.utcnow()
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<LawArticle(id={self.id}, article_number={self.article_number})>"
|
||||
@@ -0,0 +1,119 @@
|
||||
"""Signature model for electronic signatures."""
|
||||
import enum
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import String, Text, DateTime, Enum as SQLEnum, Integer, ForeignKey, JSON
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class SignatureStatus(str, enum.Enum):
|
||||
"""Signature status enumeration."""
|
||||
PENDING = "pending"
|
||||
SIGNED = "signed"
|
||||
REJECTED = "rejected"
|
||||
EXPIRED = "expired"
|
||||
|
||||
|
||||
class SignatureRequest(Base):
|
||||
"""Signature request model."""
|
||||
|
||||
__tablename__ = "signature_requests"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
contract_id: Mapped[int] = mapped_column(Integer, ForeignKey("contracts.id"), index=True)
|
||||
requester_id: Mapped[int] = mapped_column(Integer, ForeignKey("users.id"), index=True)
|
||||
signer_name: Mapped[str] = mapped_column(String(100))
|
||||
signer_email: Mapped[str] = mapped_column(String(100))
|
||||
status: Mapped[SignatureStatus] = mapped_column(
|
||||
SQLEnum(SignatureStatus),
|
||||
default=SignatureStatus.PENDING
|
||||
)
|
||||
token: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
||||
expires_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
contract_id: int,
|
||||
requester_id: int,
|
||||
signer_name: str,
|
||||
signer_email: str,
|
||||
token: str,
|
||||
expires_at: datetime,
|
||||
status: SignatureStatus = SignatureStatus.PENDING,
|
||||
**kwargs
|
||||
):
|
||||
self.contract_id = contract_id
|
||||
self.requester_id = requester_id
|
||||
self.signer_name = signer_name
|
||||
self.signer_email = signer_email
|
||||
self.token = token
|
||||
self.expires_at = expires_at
|
||||
self.status = status
|
||||
self.created_at = datetime.utcnow()
|
||||
|
||||
|
||||
class Signature(Base):
|
||||
"""Signature record model."""
|
||||
|
||||
__tablename__ = "signatures"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
request_id: Mapped[int] = mapped_column(Integer, ForeignKey("signature_requests.id"), index=True)
|
||||
signer_name: Mapped[str] = mapped_column(String(100))
|
||||
signature_data: Mapped[str] = mapped_column(Text) # Base64 image or coordinates
|
||||
ip_address: Mapped[Optional[str]] = mapped_column(String(50), nullable=True)
|
||||
user_agent: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
|
||||
verification_hash: Mapped[str] = mapped_column(String(64)) # Document fingerprint
|
||||
signed_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
request_id: int,
|
||||
signer_name: str,
|
||||
signature_data: str,
|
||||
verification_hash: str,
|
||||
ip_address: Optional[str] = None,
|
||||
user_agent: Optional[str] = None,
|
||||
**kwargs
|
||||
):
|
||||
self.request_id = request_id
|
||||
self.signer_name = signer_name
|
||||
self.signature_data = signature_data
|
||||
self.verification_hash = verification_hash
|
||||
self.ip_address = ip_address
|
||||
self.user_agent = user_agent
|
||||
self.signed_at = datetime.utcnow()
|
||||
|
||||
|
||||
class SignatureAudit(Base):
|
||||
"""Signature audit log model."""
|
||||
|
||||
__tablename__ = "signature_audits"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
signature_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("signatures.id"), nullable=True)
|
||||
request_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("signature_requests.id"), nullable=True)
|
||||
action: Mapped[str] = mapped_column(String(50))
|
||||
details: Mapped[Optional[dict]] = mapped_column(JSON, nullable=True)
|
||||
ip_address: Mapped[Optional[str]] = mapped_column(String(50), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
action: str,
|
||||
signature_id: Optional[int] = None,
|
||||
request_id: Optional[int] = None,
|
||||
details: Optional[dict] = None,
|
||||
ip_address: Optional[str] = None,
|
||||
**kwargs
|
||||
):
|
||||
self.action = action
|
||||
self.signature_id = signature_id
|
||||
self.request_id = request_id
|
||||
self.details = details
|
||||
self.ip_address = ip_address
|
||||
self.created_at = datetime.utcnow()
|
||||
@@ -0,0 +1,64 @@
|
||||
"""User model for authentication and authorization."""
|
||||
import enum
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import String, Boolean, DateTime, Enum as SQLEnum
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class UserRole(str, enum.Enum):
|
||||
"""User role enumeration."""
|
||||
ADMIN = "admin"
|
||||
LAWYER = "lawyer"
|
||||
REVIEWER = "reviewer"
|
||||
CLIENT = "client"
|
||||
|
||||
|
||||
class User(Base):
|
||||
"""User model for authentication."""
|
||||
|
||||
__tablename__ = "users"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
username: Mapped[str] = mapped_column(String(50), unique=True, index=True)
|
||||
email: Mapped[str] = mapped_column(String(100), unique=True, index=True)
|
||||
hashed_password: Mapped[str] = mapped_column(String(255))
|
||||
full_name: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
|
||||
role: Mapped[UserRole] = mapped_column(
|
||||
SQLEnum(UserRole),
|
||||
nullable=False
|
||||
)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime,
|
||||
nullable=False
|
||||
)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime,
|
||||
nullable=False
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
username: str,
|
||||
email: str,
|
||||
hashed_password: str,
|
||||
full_name: Optional[str] = None,
|
||||
role: UserRole = UserRole.CLIENT,
|
||||
is_active: bool = True,
|
||||
**kwargs
|
||||
):
|
||||
self.username = username
|
||||
self.email = email
|
||||
self.hashed_password = hashed_password
|
||||
self.full_name = full_name
|
||||
self.role = role
|
||||
self.is_active = is_active
|
||||
self.created_at = datetime.utcnow()
|
||||
self.updated_at = datetime.utcnow()
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<User(id={self.id}, username={self.username}, role={self.role})>"
|
||||
Reference in new issue
Block a user