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}
44
45/// Contest config visible to all users
46#[derive(Clone, Debug, Serialize, Deserialize)]
47pub struct PublicContestConfig {
48    /// Contest's id
49    pub id: i64,
50    /// Contest's owner's user id (optional)
51    pub owner_id: Option<i64>,
52    /// Contest's name (ru)
53    pub name_ru: String,
54    /// Contest's name (en)
55    pub name_en: String,
56    /// Statements url (ru)
57    pub statements_url_ru: String,
58    /// Editorial url (ru)
59    pub editorial_url_ru: String,
60    /// Statements url (en)
61    pub statements_url_en: String,
62    /// Editorial url (en)
63    pub editorial_url_en: String,
64    /// Timestamp of contest beginning
65    pub starts_at: DateTime<Utc>,
66    /// Timestamp of contest ending
67    pub ends_at: DateTime<Utc>,
68    /// Is contest hidden
69    pub hidden: bool,
70    /// Is upsolving opened
71    pub upsolving_opened: bool,
72    /// Hide solutions' files
73    pub hide_solutions: bool,
74}
75
76/// Request for creating/updating a post in contest
77#[derive(Clone, Debug, Serialize, Deserialize)]
78pub struct ContestPostRequest {
79    /// Post's title (ru)
80    pub title_ru: String,
81    /// Post's text (ru)
82    pub text_ru: String,
83    /// Post's title (en)
84    pub title_en: String,
85    /// Post's text (en)
86    pub text_en: String,
87    /// Created at
88    pub created_at: DateTime<Utc>,
89}
90
91/// Request for creating a post in contest
92#[derive(Deserialize, Serialize, Clone, Debug)]
93#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
94pub struct ContestPost {
95    /// Post id
96    pub id: i64,
97    /// Owner's id
98    pub owner_id: i64,
99    /// Contest's id
100    pub contest_id: i64,
101    /// Post's title (ru)
102    pub title_ru: String,
103    /// Post's text (ru)
104    pub text_ru: String,
105    /// Post's title (en)
106    pub title_en: String,
107    /// Post's text (en)
108    pub text_en: String,
109    /// Created at
110    pub created_at: DateTime<Utc>,
111}