cat_gateway/service/common/objects/legacy/
voter_group_id.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//! Defines the allowable groups for a Voter
use poem_openapi::{types::Example, Enum};

/// The kind of voter group foes the voter belong.
#[derive(Enum)]
pub(crate) enum VoterGroupId {
    /// Delegated Representative.
    #[oai(rename = "rep")]
    Rep,

    /// Direct voter.
    #[oai(rename = "direct")]
    Direct,
}

impl Example for VoterGroupId {
    fn example() -> Self {
        Self::Rep
    }
}

impl TryFrom<crate::db::event::legacy::types::registration::VoterGroupId> for VoterGroupId {
    type Error = String;

    fn try_from(
        value: crate::db::event::legacy::types::registration::VoterGroupId,
    ) -> Result<Self, Self::Error> {
        match value.0.as_str() {
            "rep" => Ok(Self::Rep),
            "direct" => Ok(Self::Direct),
            value => Err(format!("Unknown VoterGroupId: {value}")),
        }
    }
}