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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum SessionStatus {
Creating,
Active,
Complete
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct EstimateSession {
key: String,
title: String,
choices: Vec<String>,
options: std::collections::HashMap<String, String>,
status: SessionStatus
}
impl EstimateSession {
pub fn new(title: String) -> EstimateSession {
EstimateSession {
key: slug_for(&title),
title,
choices: default_choices(),
options: std::collections::HashMap::new(),
status: SessionStatus::Creating
}
}
pub fn key(&self) -> &String {
&self.key
}
pub fn title(&self) -> &String {
&self.title
}
}
fn slug_for(title: &str) -> String {
title.into()
}
fn default_choices() -> Vec<String> {
vec![
"0".into(),
"0.5".into(),
"1".into(),
"2".into(),
"3".into(),
"5".into(),
"8".into(),
"13".into(),
"20".into(),
"40".into(),
"100".into(),
"?".into(),
]
}
#[derive(Debug, Deserialize, Serialize)]
pub struct SessionContext {
session: EstimateSession,
members: std::collections::HashMap<Uuid, crate::member::Member>,
connected_members: std::collections::HashSet<Uuid>,
polls: std::collections::HashMap<Uuid, crate::poll::Poll>,
votes: std::collections::HashMap<(Uuid, Uuid), crate::poll::Vote>
}