Skip to main content

koprogo_api/application/dto/
vote_dto.rs

1use crate::domain::entities::{Vote, VoteAuthMethod, VoteChoice};
2use chrono::{DateTime, Utc};
3use rust_decimal::Decimal;
4use serde::{Deserialize, Serialize};
5use uuid::Uuid;
6
7/// Response DTO for Vote
8#[derive(Debug, Serialize, Deserialize, Clone, utoipa::ToSchema)]
9pub struct VoteResponse {
10    pub id: Uuid,
11    pub resolution_id: Uuid,
12    pub owner_id: Uuid,
13    pub unit_id: Uuid,
14    pub vote_choice: VoteChoice,
15    /// Tantièmes/millièmes — Decimal exact (ADR-0008), sérialisé en string JSON.
16    pub voting_power: Decimal,
17    pub proxy_owner_id: Option<Uuid>,
18    pub voted_at: DateTime<Utc>,
19    pub is_proxy_vote: bool,
20    /// Story 4.2 (#48) — comment le votant a été authentifié.
21    pub auth_method: VoteAuthMethod,
22}
23
24impl From<Vote> for VoteResponse {
25    fn from(vote: Vote) -> Self {
26        Self {
27            id: vote.id,
28            resolution_id: vote.resolution_id,
29            owner_id: vote.owner_id,
30            unit_id: vote.unit_id,
31            vote_choice: vote.vote_choice.clone(),
32            voting_power: vote.voting_power,
33            proxy_owner_id: vote.proxy_owner_id,
34            voted_at: vote.voted_at,
35            is_proxy_vote: vote.is_proxy_vote(),
36            auth_method: vote.auth_method,
37        }
38    }
39}
40
41/// Request DTO for casting a vote
42#[derive(Debug, Deserialize, utoipa::ToSchema)]
43pub struct CastVoteRequest {
44    pub owner_id: Uuid,
45    pub unit_id: Uuid,
46    pub vote_choice: VoteChoice,
47    /// **Ignoré par le serveur depuis #850.**
48    ///
49    /// La puissance de vote d'un lot est sa quotité dans l'acte de base
50    /// (Art. 3.87 § 2 et § 8 CC) : elle n'est pas déclarative. Le serveur la
51    /// relit sur le lot et n'accorde aucune valeur à ce champ.
52    ///
53    /// Il reste accepté pour ne pas casser les appelants existants, et sera
54    /// retiré du contrat quand l'arbitrage de #850 — qui peut saisir un vote,
55    /// et pour qui — aura tranché le reste de la route.
56    #[serde(default)]
57    pub voting_power: Option<Decimal>,
58    pub proxy_owner_id: Option<Uuid>,
59    /// Story 4.2 (#48) — comment le votant a été authentifié. Obligatoire
60    /// (absent → 422 `VOTE_AUTH_METHOD_REQUIRED`) : `Option` ici seulement
61    /// pour distinguer « absent » (422 typé) d'un JSON malformé (400 générique
62    /// de désérialisation). Le cas d'usage `cast_vote` le valide contre la
63    /// modalité de l'AG (`assert_vote_auth_sufficient`).
64    #[serde(default)]
65    pub auth_method: Option<VoteAuthMethod>,
66}
67
68/// Request DTO for changing a vote
69#[derive(Debug, Deserialize, utoipa::ToSchema)]
70pub struct ChangeVoteRequest {
71    pub vote_choice: VoteChoice,
72}