Skip to main content

aj_models/
contests.rs

1//! Structs for contests
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6/// Leaderboard single row
7#[derive(Clone, Debug, Serialize, Deserialize)]
8#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
9pub struct LeaderboardRow {
10    /// User id
11    pub user_id: i64,
12    /// Max scores for each problem
13    pub scores: Vec<i32>,
14    /// Total score
15    pub total_score: i64,
16}
17
18/// Request for creating/updating a contest
19#[derive(Clone, Debug, Serialize, Deserialize)]
20pub struct ContestRequest {
21    /// Contest's name (ru)
22    pub name_ru: String,
23    /// Contest's name (en)
24    pub name_en: String,
25    /// Timestamp of contest beginning
26    pub starts_at: DateTime<Utc>,
27    /// Timestamp of contest ending
28    pub ends_at: DateTime<Utc>,
29    /// Statements url (ru)
30    pub statements_url_ru: String,
31    /// Editorial url (ru)
32    pub editorial_url_ru: String,
33    /// Statements url (en)
34    pub statements_url_en: String,
35    /// Editorial url (en)
36    pub editorial_url_en: String,
37    /// Is contest hidden
38    pub hidden: bool,
39    /// Is upsolving opened
40    pub upsolving_opened: bool,
41    /// Hide solutions' files
42    pub hide_solutions: bool,
43    /// Hide leaderboard till contest's finishing
44    pub hide_leaderboard: bool,
45    /// Contests' co-authors
46    pub co_authors: Vec<i64>,
47}
48
49/// Contest config visible to all users
50#[derive(Clone, Debug, Serialize, Deserialize)]
51pub struct PublicContestConfig {
52    /// Contest's id
53    pub id: i64,
54    /// Contest's owner's user id (optional)
55    pub owner_id: Option<i64>,
56    /// Contest's name (ru)
57    pub name_ru: String,
58    /// Contest's name (en)
59    pub name_en: String,
60    /// Statements url (ru)
61    pub statements_url_ru: String,
62    /// Editorial url (ru)
63    pub editorial_url_ru: String,
64    /// Statements url (en)
65    pub statements_url_en: String,
66    /// Editorial url (en)
67    pub editorial_url_en: String,
68    /// Timestamp of contest beginning
69    pub starts_at: DateTime<Utc>,
70    /// Timestamp of contest ending
71    pub ends_at: DateTime<Utc>,
72    /// Is contest hidden
73    pub hidden: bool,
74    /// Is upsolving opened
75    pub upsolving_opened: bool,
76    /// Hide solutions' files
77    pub hide_solutions: bool,
78    /// Hide leaderboard till contest's finishing
79    pub hide_leaderboard: bool,
80    /// Contests' co-authors
81    pub co_authors: Vec<i64>,
82}
83
84/// Request for creating/updating a post in contest
85#[derive(Clone, Debug, Serialize, Deserialize)]
86pub struct ContestPostRequest {
87    /// Post's title (ru)
88    pub title_ru: String,
89    /// Post's text (ru)
90    pub text_ru: String,
91    /// Post's title (en)
92    pub title_en: String,
93    /// Post's text (en)
94    pub text_en: String,
95}
96
97/// Request for creating a post in contest
98#[derive(Deserialize, Serialize, Clone, Debug)]
99#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
100pub struct ContestPost {
101    /// Post id
102    pub id: i64,
103    /// Owner's id
104    pub owner_id: i64,
105    /// Contest's id
106    pub contest_id: i64,
107    /// Post's title (ru)
108    pub title_ru: String,
109    /// Post's text (ru)
110    pub text_ru: String,
111    /// Post's title (en)
112    pub title_en: String,
113    /// Post's text (en)
114    pub text_en: String,
115    /// Created at
116    pub created_at: DateTime<Utc>,
117}