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
80    pub title: String,
81    /// Post's text
82    pub text: String,
83    /// Created at
84    pub created_at: DateTime<Utc>,
85}
86
87/// Request for creating a post in contest
88#[derive(Deserialize, Serialize, Clone, Debug)]
89#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
90pub struct ContestPost {
91    /// Post id
92    pub id: i64,
93    /// Owner's id
94    pub owner_id: i64,
95    /// Contest's id
96    pub contest_id: i64,
97    /// Post's title
98    pub title: String,
99    /// Post's text
100    pub text: String,
101    /// Created at
102    pub created_at: DateTime<Utc>,
103}