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.1";
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 RegisterPostResponse {
43 Created
45 ,
46 UserWithThatIDDoesAlreadyExist
48}
49
50#[derive(Debug, PartialEq, Serialize, Deserialize)]
51pub enum StatisticsGetResponse {
52 GameResultDetails
54 (Vec<String>)
55}
56
57#[derive(Debug, PartialEq, Serialize, Deserialize)]
58#[must_use]
59pub enum StatisticsUuidGetResponse {
60 GameResultDetails
62 (models::ResultDto)
63 ,
64 ThisStatisticDoesNotExist
66}
67
68#[derive(Debug, PartialEq, Serialize, Deserialize)]
69#[must_use]
70pub enum UserUuidGetResponse {
71 SuccessfullyFetchedUserData
73 (models::UserDto)
74 ,
75 UserWithThatIDDoesExist
77}
78
79#[async_trait]
81#[allow(clippy::too_many_arguments, clippy::ptr_arg)]
82pub trait Api<C: Send + Sync> {
83 fn poll_ready(&self, _cx: &mut Context) -> Poll<Result<(), Box<dyn Error + Send + Sync + 'static>>> {
84 Poll::Ready(Ok(()))
85 }
86
87 async fn bobby_delete(
89 &self,
90 context: &C) -> Result<BobbyDeleteResponse, ApiError>;
91
92 async fn game_post(
94 &self,
95 game_end_dto: models::GameEndDto,
96 context: &C) -> Result<GamePostResponse, ApiError>;
97
98 async fn register_post(
100 &self,
101 create_user_dto: models::CreateUserDto,
102 context: &C) -> Result<RegisterPostResponse, ApiError>;
103
104 async fn statistics_get(
106 &self,
107 context: &C) -> Result<StatisticsGetResponse, ApiError>;
108
109 async fn statistics_uuid_get(
111 &self,
112 uuid: String,
113 context: &C) -> Result<StatisticsUuidGetResponse, ApiError>;
114
115 async fn user_uuid_get(
117 &self,
118 uuid: String,
119 context: &C) -> Result<UserUuidGetResponse, ApiError>;
120
121}
122
123#[async_trait]
125#[allow(clippy::too_many_arguments, clippy::ptr_arg)]
126pub trait ApiNoContext<C: Send + Sync> {
127
128 fn poll_ready(&self, _cx: &mut Context) -> Poll<Result<(), Box<dyn Error + Send + Sync + 'static>>>;
129
130 fn context(&self) -> &C;
131
132 async fn bobby_delete(
134 &self,
135 ) -> Result<BobbyDeleteResponse, ApiError>;
136
137 async fn game_post(
139 &self,
140 game_end_dto: models::GameEndDto,
141 ) -> Result<GamePostResponse, ApiError>;
142
143 async fn register_post(
145 &self,
146 create_user_dto: models::CreateUserDto,
147 ) -> Result<RegisterPostResponse, ApiError>;
148
149 async fn statistics_get(
151 &self,
152 ) -> Result<StatisticsGetResponse, ApiError>;
153
154 async fn statistics_uuid_get(
156 &self,
157 uuid: String,
158 ) -> Result<StatisticsUuidGetResponse, ApiError>;
159
160 async fn user_uuid_get(
162 &self,
163 uuid: String,
164 ) -> Result<UserUuidGetResponse, ApiError>;
165
166}
167
168pub trait ContextWrapperExt<C: Send + Sync> where Self: Sized
170{
171 fn with_context(self, context: C) -> ContextWrapper<Self, C>;
173}
174
175impl<T: Api<C> + Send + Sync, C: Clone + Send + Sync> ContextWrapperExt<C> for T {
176 fn with_context(self: T, context: C) -> ContextWrapper<T, C> {
177 ContextWrapper::<T, C>::new(self, context)
178 }
179}
180
181#[async_trait]
182impl<T: Api<C> + Send + Sync, C: Clone + Send + Sync> ApiNoContext<C> for ContextWrapper<T, C> {
183 fn poll_ready(&self, cx: &mut Context) -> Poll<Result<(), ServiceError>> {
184 self.api().poll_ready(cx)
185 }
186
187 fn context(&self) -> &C {
188 ContextWrapper::context(self)
189 }
190
191 async fn bobby_delete(
193 &self,
194 ) -> Result<BobbyDeleteResponse, ApiError>
195 {
196 let context = self.context().clone();
197 self.api().bobby_delete(&context).await
198 }
199
200 async fn game_post(
202 &self,
203 game_end_dto: models::GameEndDto,
204 ) -> Result<GamePostResponse, ApiError>
205 {
206 let context = self.context().clone();
207 self.api().game_post(game_end_dto, &context).await
208 }
209
210 async fn register_post(
212 &self,
213 create_user_dto: models::CreateUserDto,
214 ) -> Result<RegisterPostResponse, ApiError>
215 {
216 let context = self.context().clone();
217 self.api().register_post(create_user_dto, &context).await
218 }
219
220 async fn statistics_get(
222 &self,
223 ) -> Result<StatisticsGetResponse, ApiError>
224 {
225 let context = self.context().clone();
226 self.api().statistics_get(&context).await
227 }
228
229 async fn statistics_uuid_get(
231 &self,
232 uuid: String,
233 ) -> Result<StatisticsUuidGetResponse, ApiError>
234 {
235 let context = self.context().clone();
236 self.api().statistics_uuid_get(uuid, &context).await
237 }
238
239 async fn user_uuid_get(
241 &self,
242 uuid: String,
243 ) -> Result<UserUuidGetResponse, ApiError>
244 {
245 let context = self.context().clone();
246 self.api().user_uuid_get(uuid, &context).await
247 }
248
249}
250
251
252#[cfg(feature = "client")]
253pub mod client;
254
255#[cfg(feature = "client")]
257pub use client::Client;
258
259#[cfg(feature = "server")]
260pub mod server;
261
262#[cfg(feature = "server")]
264pub use self::server::Service;
265
266#[cfg(feature = "server")]
267pub mod context;
268
269pub mod models;
270
271#[cfg(any(feature = "client", feature = "server"))]
272pub(crate) mod header;