koprogo_api/application/dto/
vote_dto.rs1use crate::domain::entities::{Vote, VoteChoice};
2use chrono::{DateTime, Utc};
3use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6#[derive(Debug, Serialize, Deserialize, Clone)]
8pub struct VoteResponse {
9 pub id: Uuid,
10 pub resolution_id: Uuid,
11 pub owner_id: Uuid,
12 pub unit_id: Uuid,
13 pub vote_choice: VoteChoice,
14 pub voting_power: f64,
15 pub proxy_owner_id: Option<Uuid>,
16 pub voted_at: DateTime<Utc>,
17 pub is_proxy_vote: bool,
18}
19
20impl From<Vote> for VoteResponse {
21 fn from(vote: Vote) -> Self {
22 Self {
23 id: vote.id,
24 resolution_id: vote.resolution_id,
25 owner_id: vote.owner_id,
26 unit_id: vote.unit_id,
27 vote_choice: vote.vote_choice.clone(),
28 voting_power: vote.voting_power,
29 proxy_owner_id: vote.proxy_owner_id,
30 voted_at: vote.voted_at,
31 is_proxy_vote: vote.is_proxy_vote(),
32 }
33 }
34}
35
36#[derive(Debug, Deserialize)]
38pub struct CastVoteRequest {
39 pub owner_id: Uuid,
40 pub unit_id: Uuid,
41 pub vote_choice: VoteChoice,
42 pub voting_power: f64,
43 pub proxy_owner_id: Option<Uuid>,
44}
45
46#[derive(Debug, Deserialize)]
48pub struct ChangeVoteRequest {
49 pub vote_choice: VoteChoice,
50}