codewars_api/rest_api/models.rs
1//! Models that represent the data returned by the API
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6/// Represents a Codewars user
7///
8/// Read more at [Codewars documentation](https://dev.codewars.com/#get-user)
9#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
10pub struct User {
11 /// Username of the user
12 pub username: String,
13 /// Name of the user
14 pub name: String,
15 /// Total honor points earned by the user
16 pub honor: u64,
17 /// Name of the clan
18 pub clan: String,
19 /// The user's position on the overall leaderboard
20 #[serde(rename = "leaderboardPosition")]
21 pub leaderboard_position: u64,
22 /// Array of skills entered by the user
23 pub skills: Vec<String>,
24 /// Ranks object with overall and language ranks
25 pub ranks: Ranks,
26 /// Object with fields for the number of authored and completed kata respectively
27 #[serde(rename = "codeChallenges")]
28 pub code_challenges: CodeChallenges,
29}
30
31/// Represents an object with fields for the number of authored and completed kata respectively
32///
33/// Read more at [Codewars documentation](https://dev.codewars.com/#get-user)
34#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Default, Clone)]
35pub struct CodeChallenges {
36 /// Total number of authored challenges
37 #[serde(rename = "totalAuthored")]
38 pub total_authored: u64,
39 /// Total number of completed challenges
40 #[serde(rename = "totalCompleted")]
41 pub total_completed: u64,
42}
43
44/// Represents a ranks object with overall and language ranks
45///
46/// Read more at [Codewars documentation](https://dev.codewars.com/#get-user)
47#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
48pub struct Ranks {
49 /// Overall rank
50 pub overall: Rank,
51 /// Ranks for each language trained
52 pub languages: HashMap<String, Rank>,
53}
54
55/// Represents a rank object
56///
57/// Read more at [Codewars documentation](https://dev.codewars.com/#get-user)
58#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
59pub struct Rank {
60 /// Rank in integer. [-8, -1] maps to kyu, [1, 8] maps to dan
61 pub rank: i8,
62 /// Either {-rank} kyu or {rank} dan
63 pub name: String,
64 /// The color of the rank. Possible colors are white (7-8 kyu), yellow (5-6 kyu), blue (3-4 kyu), purple (1-2 kyu), black (1-4 dan), and red (5-8 dan)
65 pub color: Color,
66 /// The total score earned. This is the number that determines the rank
67 pub score: u64,
68}
69
70/// Represents a color of the rank
71///
72/// Read more at [Codewars documentation](https://dev.codewars.com/#get-user)
73#[derive(
74 Serialize,
75 Deserialize,
76 Debug,
77 PartialEq,
78 Eq,
79 Hash,
80 Clone,
81 strum::Display,
82 strum::IntoStaticStr,
83 strum::AsRefStr,
84 strum::EnumString,
85 strum::EnumCount,
86 strum::EnumIter,
87)]
88pub enum Color {
89 /// White (7-8 kyu)
90 #[serde(rename = "white")]
91 White,
92 /// Yellow (5-6 kyu)
93 #[serde(rename = "yellow")]
94 Yellow,
95 /// Blue (3-4 kyu)
96 #[serde(rename = "blue")]
97 Blue,
98 /// Purple (1-2 kyu)
99 #[serde(rename = "purple")]
100 Purple,
101 /// Black (1-4 dan)
102 #[serde(rename = "black")]
103 Black,
104 /// Red (5-8 dan)
105 #[serde(rename = "red")]
106 Red,
107}
108
109
110/// Represents an authored challenge
111///
112/// Read more at [Codewars documentation](https://dev.codewars.com/#list-authored-challenges)
113#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Default, Clone)]
114pub struct AuthoredChallenge {
115 /// ID of the kata
116 pub id: String,
117 /// Name of the kata
118 pub name: String,
119 /// Description of the kata in Markdown
120 pub description: String,
121 /// Rank of the kata if approved
122 #[serde(flatten)]
123 pub rank: Option<i8>,
124 /// Rank name of the kata if approved
125 #[serde(rename = "rankName", flatten)]
126 pub rank_name: Option<String>,
127 /// Array of tags associated with the kata
128 pub tags: Vec<String>,
129 /// Array of language names the kata is available in
130 pub languages: Vec<String>,
131}
132
133/// Represents list of authored challenges
134///
135/// Read more at [Codewars documentation](https://dev.codewars.com/#list-authored-challenges)
136#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Default, Clone)]
137pub struct AuthoredChallenges {
138 /// Vector of authored challenges
139 pub data: Vec<AuthoredChallenge>,
140}
141
142/// Represents a code challenge
143///
144/// Read more at [Codewars documentation](https://dev.codewars.com/#get-code-challenge)
145#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Default, Clone)]
146pub struct CodeChallenge {
147 /// ID of the kata
148 pub id: String,
149 /// Name of the kata
150 pub name: String,
151 /// Slug of the kata
152 pub slug: String,
153 /// URL of the kata
154 pub url: String,
155 /// Category of the kata
156 pub category: String,
157 /// Description of the kata in Markdown
158 pub description: String,
159 /// Array of tags associated with the kata
160 pub tags: Vec<String>,
161 /// Array of language names the kata is available in
162 pub languages: Vec<String>,
163 /// Object describing the rank of the kata if approved
164 #[serde(flatten)]
165 pub rank: Option<Rank>,
166 /// The author of the kata
167 #[serde(rename = "createdBy")]
168 pub created_by: Author,
169 /// Date and time when the kata was first published
170 #[serde(rename = "publishedAt")]
171 pub published_at: String,
172 /// The approver of the kata
173 #[serde(rename = "approvedBy", flatten)]
174 pub approved_by: Option<Author>,
175 /// Date and time when the kata was approved
176 #[serde(rename = "approvedAt")]
177 pub approved_at: String,
178 /// Total number of completions
179 #[serde(rename = "totalCompleted")]
180 pub total_completed: u64,
181 /// Total number of attempts
182 #[serde(rename = "totalAttempts")]
183 pub total_attempts: u64,
184 /// The number of bookmarks
185 #[serde(rename = "totalStars")]
186 pub total_stars: u64,
187 /// The sum of all votes casted
188 #[serde(rename = "voteScore")]
189 pub vote_score: u64,
190 /// Whether to allow contributions
191 #[serde(rename = "contributorsWanted")]
192 pub contributors_wanted: bool,
193 /// Object with fields for the number of unresolved issues and suggestions respectively
194 pub unresolved: Unresolved,
195}
196
197/// Represents an author of code challenge
198///
199/// Read more at [Codewars documentation](https://dev.codewars.com/#get-code-challenge)
200#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Default, Clone)]
201pub struct Author {
202 /// Username of the user
203 pub username: String,
204 /// URL of the user's profile
205 pub url: String,
206}
207
208/// Represents an object with fields for the number of unresolved issues and suggestions respectively
209///
210/// Read more at [Codewars documentation](https://dev.codewars.com/#get-code-challenge)
211#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Default, Clone)]
212pub struct Unresolved {
213 /// Number of unresolved issues
214 pub issues: u64,
215 /// Number of unresolved suggestions
216 pub suggestions: u64,
217}
218
219/// Represents a list of completed code challenges
220///
221/// Read more at [Codewars documentation](https://dev.codewars.com/#list-completed-challenges)
222#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Default, Clone)]
223pub struct CompletedChallenges {
224 /// Total number of pages
225 #[serde(rename = "totalPages")]
226 pub total_pages: u64,
227 /// Total number of items
228 #[serde(rename = "totalItems")]
229 pub total_items: u64,
230 /// Array of completed code challenges
231 pub data: Vec<CompletedChallenge>,
232}
233
234/// Represents a completed code challenge
235///
236/// Read more at [Codewars documentation](https://dev.codewars.com/#list-completed-challenges)
237#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Default, Clone)]
238pub struct CompletedChallenge {
239 /// ID of the kata
240 pub id: String,
241 /// Name of the kata
242 pub name: String,
243 /// Slug of the kata
244 pub slug: String,
245 /// Date and time of the completion
246 #[serde(rename = "completedAt")]
247 pub completed_at: String,
248 /// Array of languages a kata completed in
249 #[serde(rename = "completedLanguages")]
250 pub completed_languages: Vec<String>,
251}