algohub_server/models/
contest.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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use serde::{Deserialize, Serialize};
use surrealdb::sql::Thing;

use super::{OwnedCredentials, UserRecordId};

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Visibility {
    Public,
    Internal,
    Private,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub enum Mode {
    #[default]
    ICPC,
    OI,
}

#[derive(Serialize, Deserialize)]
pub struct Contest {
    pub id: Option<Thing>,

    pub name: String,
    pub mode: Mode,
    pub visibility: Visibility,
    pub description: String,
    pub announcement: Option<String>,

    pub start_time: chrono::NaiveDateTime,
    pub end_time: chrono::NaiveDateTime,

    pub owner: Thing,
    pub creator: Thing,
    pub updaters: Vec<Thing>,
    pub participants: Vec<Thing>,

    pub created_at: chrono::NaiveDateTime,
    pub updated_at: chrono::NaiveDateTime,
}

#[derive(Serialize, Deserialize)]
pub struct ContestData {
    pub name: String,
    pub mode: Mode,
    pub visibility: Visibility,
    pub description: String,
    pub start_time: chrono::NaiveDateTime,
    pub end_time: chrono::NaiveDateTime,
    pub owner: UserRecordId,
}

#[derive(Serialize, Deserialize)]
pub struct CreateContest {
    pub auth: OwnedCredentials,
    pub data: ContestData,
}

#[derive(Serialize, Deserialize)]
pub struct AddProblems<'a> {
    pub auth: OwnedCredentials,
    pub contest_id: &'a str,
    pub problem_ids: Vec<&'a str>,
}

#[derive(Serialize, Deserialize)]
pub struct RemoveProblem {
    pub auth: OwnedCredentials,
    pub contest_id: Thing,
    pub problem_id: Thing,
}

#[derive(Serialize, Deserialize)]
pub struct UserContest {
    pub id: String,

    pub name: String,
    pub mode: Mode,
    pub visibility: Visibility,
    pub description: String,
    pub announcement: Option<String>,

    pub start_time: chrono::NaiveDateTime,
    pub end_time: chrono::NaiveDateTime,

    pub owner: UserRecordId,
    pub creator: String,
    pub updaters: Vec<String>,
    pub participants: Vec<String>,

    pub created_at: chrono::NaiveDateTime,
    pub updated_at: chrono::NaiveDateTime,
}

impl From<Contest> for UserContest {
    fn from(value: Contest) -> Self {
        UserContest {
            id: value.id.unwrap().id.to_string(),
            name: value.name,
            mode: value.mode,
            visibility: value.visibility,
            description: value.description,
            announcement: value.announcement,
            start_time: value.start_time,
            end_time: value.end_time,
            owner: value.owner.into(),
            creator: value.creator.to_string(),
            updaters: value.updaters.iter().map(|x| x.id.to_string()).collect(),
            participants: value
                .participants
                .iter()
                .map(|x| x.id.to_string())
                .collect(),
            created_at: value.created_at,
            updated_at: value.updated_at,
        }
    }
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ContestProblem {
    pub id: String,
    pub title: String,
    pub solved: bool,
    pub submitted_count: u32,
    pub accepted_count: u32,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ContestRank {
    name: String,
    problem_id: String,
    accepted: bool,
    wrongs: u32,
}