1#![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, unused_attributes, non_camel_case_types)]
2#![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)]
3
4use async_trait::async_trait;
5use futures::Stream;
6use std::error::Error;
7use std::collections::BTreeSet;
8use std::task::{Poll, Context};
9use swagger::{ApiError, ContextWrapper};
10use serde::{Serialize, Deserialize};
11use crate::server::Authorization;
12
13
14type ServiceError = Box<dyn Error + Send + Sync + 'static>;
15
16pub const BASE_PATH: &str = "";
17pub const API_VERSION: &str = "1.0.2";
18
19mod auth;
20pub use auth::{AuthenticationApi, Claims};
21
22
23#[derive(Debug, PartialEq, Serialize, Deserialize)]
24#[must_use]
25pub enum BobbyDeleteResponse {
26 DroppedAllData
28 ,
29 WrongPassphraseProvided
31}
32
33#[derive(Debug, PartialEq, Serialize, Deserialize)]
34pub enum GamePostResponse {
35 GameResultDetails
37 (models::ResultDto)
38}
39
40#[derive(Debug, PartialEq, Serialize, Deserialize)]
41#[must_use]
42pub enum MapsGetResponse {
43 ListOfTheIdsOfAllExistingMaps
45 (Vec<String>)
46 ,
47 NoMapsInDatabase
49}
50
51#[derive(Debug, PartialEq, Serialize, Deserialize)]
52#[must_use]
53pub enum RegisterPostResponse {
54 Created
56 ,
57 UserWithThatIDDoesAlreadyExist
59}
60
61#[derive(Debug, PartialEq, Serialize, Deserialize)]
62pub enum StatisticsGetResponse {
63 GameResultDetails
65 (Vec<String>)
66}
67
68#[derive(Debug, PartialEq, Serialize, Deserialize)]
69#[must_use]
70pub enum MapLevelGetResponse {
71 BeatMap
73 (Vec<models::MapDto>)
74 ,
75 ThisMapDoesNotExist
77}
78
79#[derive(Debug, PartialEq, Serialize, Deserialize)]
80#[must_use]
81pub enum StatisticsUuidGetResponse {
82 GameResultDetails
84 (models::ResultDto)
85 ,
86 ThisStatisticDoesNotExist
88}
89
90#[derive(Debug, PartialEq, Serialize, Deserialize)]
91#[must_use]
92pub enum UserUuidGetResponse {
93 SuccessfullyFetchedUserData
95 (models::UserDto)
96 ,
97 UserWithThatIDDoesExist
99}
100
101#[async_trait]
103#[allow(clippy::too_many_arguments, clippy::ptr_arg)]
104pub trait Api<C: Send + Sync> {
105 fn poll_ready(&self, _cx: &mut Context) -> Poll<Result<(), Box<dyn Error + Send + Sync + 'static>>> {
106 Poll::Ready(Ok(()))
107 }
108
109 async fn bobby_delete(
111 &self,
112 context: &C) -> Result<BobbyDeleteResponse, ApiError>;
113
114 async fn game_post(
116 &self,
117 game_end_dto: models::GameEndDto,
118 context: &C) -> Result<GamePostResponse, ApiError>;
119
120 async fn maps_get(
122 &self,
123 context: &C) -> Result<MapsGetResponse, ApiError>;
124
125 async fn register_post(
127 &self,
128 create_user_dto: models::CreateUserDto,
129 context: &C) -> Result<RegisterPostResponse, ApiError>;
130
131 async fn statistics_get(
133 &self,
134 context: &C) -> Result<StatisticsGetResponse, ApiError>;
135
136 async fn map_level_get(
138 &self,
139 level: String,
140 context: &C) -> Result<MapLevelGetResponse, ApiError>;
141
142 async fn statistics_uuid_get(
144 &self,
145 uuid: String,
146 context: &C) -> Result<StatisticsUuidGetResponse, ApiError>;
147
148 async fn user_uuid_get(
150 &self,
151 uuid: String,
152 context: &C) -> Result<UserUuidGetResponse, ApiError>;
153
154}
155
156#[async_trait]
158#[allow(clippy::too_many_arguments, clippy::ptr_arg)]
159pub trait ApiNoContext<C: Send + Sync> {
160
161 fn poll_ready(&self, _cx: &mut Context) -> Poll<Result<(), Box<dyn Error + Send + Sync + 'static>>>;
162
163 fn context(&self) -> &C;
164
165 async fn bobby_delete(
167 &self,
168 ) -> Result<BobbyDeleteResponse, ApiError>;
169
170 async fn game_post(
172 &self,
173 game_end_dto: models::GameEndDto,
174 ) -> Result<GamePostResponse, ApiError>;
175
176 async fn maps_get(
178 &self,
179 ) -> Result<MapsGetResponse, ApiError>;
180
181 async fn register_post(
183 &self,
184 create_user_dto: models::CreateUserDto,
185 ) -> Result<RegisterPostResponse, ApiError>;
186
187 async fn statistics_get(
189 &self,
190 ) -> Result<StatisticsGetResponse, ApiError>;
191
192 async fn map_level_get(
194 &self,
195 level: String,
196 ) -> Result<MapLevelGetResponse, ApiError>;
197
198 async fn statistics_uuid_get(
200 &self,
201 uuid: String,
202 ) -> Result<StatisticsUuidGetResponse, ApiError>;
203
204 async fn user_uuid_get(
206 &self,
207 uuid: String,
208 ) -> Result<UserUuidGetResponse, ApiError>;
209
210}
211
212pub trait ContextWrapperExt<C: Send + Sync> where Self: Sized
214{
215 fn with_context(self, context: C) -> ContextWrapper<Self, C>;
217}
218
219impl<T: Api<C> + Send + Sync, C: Clone + Send + Sync> ContextWrapperExt<C> for T {
220 fn with_context(self: T, context: C) -> ContextWrapper<T, C> {
221 ContextWrapper::<T, C>::new(self, context)
222 }
223}
224
225#[async_trait]
226impl<T: Api<C> + Send + Sync, C: Clone + Send + Sync> ApiNoContext<C> for ContextWrapper<T, C> {
227 fn poll_ready(&self, cx: &mut Context) -> Poll<Result<(), ServiceError>> {
228 self.api().poll_ready(cx)
229 }
230
231 fn context(&self) -> &C {
232 ContextWrapper::context(self)
233 }
234
235 async fn bobby_delete(
237 &self,
238 ) -> Result<BobbyDeleteResponse, ApiError>
239 {
240 let context = self.context().clone();
241 self.api().bobby_delete(&context).await
242 }
243
244 async fn game_post(
246 &self,
247 game_end_dto: models::GameEndDto,
248 ) -> Result<GamePostResponse, ApiError>
249 {
250 let context = self.context().clone();
251 self.api().game_post(game_end_dto, &context).await
252 }
253
254 async fn maps_get(
256 &self,
257 ) -> Result<MapsGetResponse, ApiError>
258 {
259 let context = self.context().clone();
260 self.api().maps_get(&context).await
261 }
262
263 async fn register_post(
265 &self,
266 create_user_dto: models::CreateUserDto,
267 ) -> Result<RegisterPostResponse, ApiError>
268 {
269 let context = self.context().clone();
270 self.api().register_post(create_user_dto, &context).await
271 }
272
273 async fn statistics_get(
275 &self,
276 ) -> Result<StatisticsGetResponse, ApiError>
277 {
278 let context = self.context().clone();
279 self.api().statistics_get(&context).await
280 }
281
282 async fn map_level_get(
284 &self,
285 level: String,
286 ) -> Result<MapLevelGetResponse, ApiError>
287 {
288 let context = self.context().clone();
289 self.api().map_level_get(level, &context).await
290 }
291
292 async fn statistics_uuid_get(
294 &self,
295 uuid: String,
296 ) -> Result<StatisticsUuidGetResponse, ApiError>
297 {
298 let context = self.context().clone();
299 self.api().statistics_uuid_get(uuid, &context).await
300 }
301
302 async fn user_uuid_get(
304 &self,
305 uuid: String,
306 ) -> Result<UserUuidGetResponse, ApiError>
307 {
308 let context = self.context().clone();
309 self.api().user_uuid_get(uuid, &context).await
310 }
311
312}
313
314
315#[cfg(feature = "client")]
316pub mod client;
317
318#[cfg(feature = "client")]
320pub use client::Client;
321
322#[cfg(feature = "server")]
323pub mod server;
324
325#[cfg(feature = "server")]
327pub use self::server::Service;
328
329#[cfg(feature = "server")]
330pub mod context;
331
332pub mod models;
333
334#[cfg(any(feature = "client", feature = "server"))]
335pub(crate) mod header;