Sprint 1 : scaffolding complet de Glibredecision
Plateforme de decisions collectives pour Duniter/G1. Backend FastAPI async + PostgreSQL (14 tables, 8 routers, 6 services, moteur de vote avec formule d'inertie WoT/Smith/TechComm). Frontend Nuxt 4 + Nuxt UI v3 + Pinia (9 pages, 5 stores). Infrastructure Docker + Woodpecker CI + Traefik. Documentation technique et utilisateur (15 fichiers). Seed : Licence G1, Engagement Forgeron v2.0.0, 4 protocoles de vote. 30 tests unitaires (formules, mode params, vote nuance) -- tous verts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
71
backend/app/models/vote.py
Normal file
71
backend/app/models/vote.py
Normal file
@@ -0,0 +1,71 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import String, Integer, Float, Boolean, Text, DateTime, ForeignKey, func
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class VoteSession(Base):
|
||||
__tablename__ = "vote_sessions"
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
decision_id: Mapped[uuid.UUID | None] = mapped_column(ForeignKey("decisions.id"))
|
||||
item_version_id: Mapped[uuid.UUID | None] = mapped_column(ForeignKey("item_versions.id"))
|
||||
voting_protocol_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("voting_protocols.id"), nullable=False)
|
||||
|
||||
# Snapshot at session start
|
||||
wot_size: Mapped[int] = mapped_column(Integer, default=0)
|
||||
smith_size: Mapped[int] = mapped_column(Integer, default=0)
|
||||
techcomm_size: Mapped[int] = mapped_column(Integer, default=0)
|
||||
|
||||
# Dates
|
||||
starts_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
ends_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
|
||||
|
||||
# Status
|
||||
status: Mapped[str] = mapped_column(String(32), default="open") # open, closed, tallied
|
||||
|
||||
# Tallies
|
||||
votes_for: Mapped[int] = mapped_column(Integer, default=0)
|
||||
votes_against: Mapped[int] = mapped_column(Integer, default=0)
|
||||
votes_total: Mapped[int] = mapped_column(Integer, default=0)
|
||||
smith_votes_for: Mapped[int] = mapped_column(Integer, default=0)
|
||||
techcomm_votes_for: Mapped[int] = mapped_column(Integer, default=0)
|
||||
threshold_required: Mapped[float] = mapped_column(Float, default=0.0)
|
||||
result: Mapped[str | None] = mapped_column(String(32)) # adopted, rejected, null
|
||||
|
||||
# Chain recording
|
||||
chain_recorded: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
chain_tx_hash: Mapped[str | None] = mapped_column(String(128))
|
||||
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
votes: Mapped[list["Vote"]] = relationship(back_populates="session", cascade="all, delete-orphan")
|
||||
|
||||
|
||||
class Vote(Base):
|
||||
__tablename__ = "votes"
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
session_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("vote_sessions.id"), nullable=False)
|
||||
voter_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("duniter_identities.id"), nullable=False)
|
||||
vote_value: Mapped[str] = mapped_column(String(32), nullable=False) # for, against, or nuanced levels
|
||||
nuanced_level: Mapped[int | None] = mapped_column(Integer) # 0-5 for nuanced votes
|
||||
comment: Mapped[str | None] = mapped_column(Text)
|
||||
|
||||
# Cryptographic proof
|
||||
signature: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
signed_payload: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
|
||||
# Voter status snapshot
|
||||
voter_wot_status: Mapped[str] = mapped_column(String(32), default="member")
|
||||
voter_is_smith: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
voter_is_techcomm: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
||||
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
session: Mapped["VoteSession"] = relationship(back_populates="votes")
|
||||
Reference in New Issue
Block a user