diff --git a/backend-actix/Cargo.lock b/backend-actix/Cargo.lock index e4ff000..95bdba6 100644 --- a/backend-actix/Cargo.lock +++ b/backend-actix/Cargo.lock @@ -1243,9 +1243,9 @@ checksum = "e8a5a9a0ff0086c7a148acb942baaabeadf9504d10400b5a05645853729b9cd2" [[package]] name = "indexmap" -version = "2.12.1" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ad4bb2b565bca0645f4d68c5c9af97fba094e9791da685bf83cb5f3ce74acf2" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", "hashbrown", @@ -2175,9 +2175,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.113" +version = "2.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678faa00651c9eb72dd2020cbdf275d92eccb2400d568e419efdd64838145cb4" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" dependencies = [ "proc-macro2", "quote", @@ -2781,18 +2781,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.31" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd74ec98b9250adb3ca554bdde269adf631549f51d8a8f8f0a10b50f1cb298c3" +checksum = "668f5168d10b9ee831de31933dc111a459c97ec93225beb307aed970d1372dfd" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.31" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8a8d209fdf45cf5138cbb5a506f6b52522a25afccc534d1475dad8e31105c6a" +checksum = "2c7962b26b0a8685668b671ee4b54d007a67d4eaf05fda79ac0ecf41e32270f1" dependencies = [ "proc-macro2", "quote", diff --git a/backend-actix/gamenight-api.yaml b/backend-actix/gamenight-api.yaml index d150a01..7ff2946 100644 --- a/backend-actix/gamenight-api.yaml +++ b/backend-actix/gamenight-api.yaml @@ -337,6 +337,8 @@ components: type: string name: type: string + location_id: + type: string datetime: type: string owner_id: @@ -408,6 +410,16 @@ components: type: string required: - user_id + OwnedGame: + title: OwnedGame + type: object + properties: + game_id: + type: string + location_id: + type: string + required: + - game_id LocationId: title: LocationId type: object @@ -499,7 +511,7 @@ components: GameIdsResponse: type: array items: - type: string + $ref: "#/components/schemas/OwnedGame" UserIdsResponse: type: array items: diff --git a/backend-actix/src/request/game.rs b/backend-actix/src/request/game.rs index 4628b38..ddf814c 100644 --- a/backend-actix/src/request/game.rs +++ b/backend-actix/src/request/game.rs @@ -1,8 +1,8 @@ +use gamenight_database::owned_game::OwnedGame; use crate::game::rename_game; use crate::owned_game::own_game; use crate::owned_game::owned_games; use crate::owned_game::disown_game; -use crate::owned_game::OwnedGame; use gamenight_database::game::load_game; use crate::game::insert_game; use uuid::Uuid; @@ -13,13 +13,10 @@ use gamenight_database::{ DbPool, GetConnection, }; -use crate::{ - models::{ - add_game_request_body::AddGameRequestBody, game::Game, game_id::GameId, - rename_game_request_body::RenameGameRequestBody, own_game_request_body::OwnGameRequestBody - }, - request::{authorization::AuthUser, error::ApiError}, -}; +use crate::{models, models::{ + add_game_request_body::AddGameRequestBody, game::Game, game_id::GameId, + rename_game_request_body::RenameGameRequestBody, own_game_request_body::OwnGameRequestBody +}, request::{authorization::AuthUser, error::ApiError}}; #[get("/games")] pub async fn get_games( @@ -162,7 +159,11 @@ pub async fn get_owned_games( let mut conn = pool.get_conn(); let game_ids = owned_games(&mut conn, user.0.id)?; - let model: Vec = game_ids.iter().map(|x| x.to_string()).collect(); + + let model = game_ids.iter().map(|(u, l)| models::owned_game::OwnedGame { + game_id: u.to_string(), + location_id: l.map(|x| x.to_string()) + }).collect::>(); Ok(HttpResponse::Ok() .content_type(ContentType::json()) diff --git a/backend-actix/src/request/gamenight_handlers.rs b/backend-actix/src/request/gamenight_handlers.rs index 3196fec..4540a43 100644 --- a/backend-actix/src/request/gamenight_handlers.rs +++ b/backend-actix/src/request/gamenight_handlers.rs @@ -43,6 +43,7 @@ pub async fn gamenights( .map(|x| Gamenight { id: x.id.to_string(), name: x.name.clone(), + location_id: x.location_id.map(|x| x.to_string()), datetime: x.datetime.to_rfc3339(), owner_id: x.owner_id.to_string(), }) @@ -77,6 +78,7 @@ pub async fn gamenight_get( let model = Gamenight { id: gamenight.id.to_string(), datetime: gamenight.datetime.to_rfc3339(), + location_id: gamenight.location_id.map(|x| x.to_string()), name: gamenight.name, owner_id: gamenight.owner_id.to_string(), }; diff --git a/gamenight-api-client-rs/.openapi-generator/FILES b/gamenight-api-client-rs/.openapi-generator/FILES index 0a33990..0b53035 100644 --- a/gamenight-api-client-rs/.openapi-generator/FILES +++ b/gamenight-api-client-rs/.openapi-generator/FILES @@ -17,6 +17,7 @@ docs/Location.md docs/LocationId.md docs/Login.md docs/OwnGameRequestBody.md +docs/OwnedGame.md docs/Participants.md docs/Registration.md docs/RenameGameRequestBody.md @@ -43,6 +44,7 @@ src/models/location_id.rs src/models/login.rs src/models/mod.rs src/models/own_game_request_body.rs +src/models/owned_game.rs src/models/participants.rs src/models/registration.rs src/models/rename_game_request_body.rs diff --git a/gamenight-api-client-rs/Cargo.toml b/gamenight-api-client-rs/Cargo.toml index 4191276..4b53a34 100644 --- a/gamenight-api-client-rs/Cargo.toml +++ b/gamenight-api-client-rs/Cargo.toml @@ -11,8 +11,8 @@ serde = { version = "^1.0", features = ["derive"] } serde_json = "^1.0" serde_repr = "^0.1" url = "^2.5" -reqwest = { version = "^0.12", default-features = false, features = ["json", "multipart"] } - +async-trait = "^0.1" +reqwest = { version = "^0.12", default-features = false, features = ["json", "multipart", "stream"] } [features] default = ["native-tls"] native-tls = ["reqwest/native-tls"] diff --git a/gamenight-api-client-rs/README.md b/gamenight-api-client-rs/README.md index e4f17de..f5f0bcb 100644 --- a/gamenight-api-client-rs/README.md +++ b/gamenight-api-client-rs/README.md @@ -69,6 +69,7 @@ Class | Method | HTTP request | Description - [LocationId](docs/LocationId.md) - [Login](docs/Login.md) - [OwnGameRequestBody](docs/OwnGameRequestBody.md) + - [OwnedGame](docs/OwnedGame.md) - [Participants](docs/Participants.md) - [Registration](docs/Registration.md) - [RenameGameRequestBody](docs/RenameGameRequestBody.md) diff --git a/gamenight-api-client-rs/build.rs b/gamenight-api-client-rs/build.rs index 03784c1..dc4b452 100644 --- a/gamenight-api-client-rs/build.rs +++ b/gamenight-api-client-rs/build.rs @@ -4,7 +4,20 @@ fn main() { println!("cargo::rerun-if-changed=../backend-actix/gamenight-api.yaml"); let _ = Command::new("openapi-generator") - .args(["generate", "-i", "../backend-actix/gamenight-api.yaml", "-g", "rust", "--additional-properties=withSeparateModelsAndApi=true,modelPackage=gamenight_model,apiPackage=gamenight_api,packageName=gamenight-api-client-rs,packageVersion=0.1.0"]) + .args([ + "generate", + "-i", + "../backend-actix/gamenight-api.yaml", + "-g", + "rust", + "--additional-properties=\ + withSeparateModelsAndApi=true,\ + library=reqwest-trait,\ + modelPackage=gamenight_model,\ + apiPackage=gamenight_api,\ + packageName=gamenight-api-client-rs,\ + packageVersion=0.1.0" + ]) .output() .expect("Failed to generate models sources for the gamenight API"); } \ No newline at end of file diff --git a/gamenight-api-client-rs/docs/DefaultApi.md b/gamenight-api-client-rs/docs/DefaultApi.md index 703f377..a23c781 100644 --- a/gamenight-api-client-rs/docs/DefaultApi.md +++ b/gamenight-api-client-rs/docs/DefaultApi.md @@ -476,7 +476,7 @@ Name | Type | Description | Required | Notes ## owned_games_get -> Vec owned_games_get(user_id) +> Vec owned_games_get(user_id) ### Parameters @@ -488,7 +488,7 @@ Name | Type | Description | Required | Notes ### Return type -**Vec** +[**Vec**](OwnedGame.md) ### Authorization diff --git a/gamenight-api-client-rs/docs/Gamenight.md b/gamenight-api-client-rs/docs/Gamenight.md index 87a131d..65988fc 100644 --- a/gamenight-api-client-rs/docs/Gamenight.md +++ b/gamenight-api-client-rs/docs/Gamenight.md @@ -6,6 +6,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **id** | **String** | | **name** | **String** | | +**location_id** | Option<**String**> | | [optional] **datetime** | **String** | | **owner_id** | **String** | | diff --git a/gamenight-api-client-rs/docs/OwnedGame.md b/gamenight-api-client-rs/docs/OwnedGame.md new file mode 100644 index 0000000..ee2055e --- /dev/null +++ b/gamenight-api-client-rs/docs/OwnedGame.md @@ -0,0 +1,12 @@ +# OwnedGame + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**game_id** | **String** | | +**location_id** | Option<**String**> | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/gamenight-api-client-rs/src/apis/default_api.rs b/gamenight-api-client-rs/src/apis/default_api.rs index 7cf1253..40d4169 100644 --- a/gamenight-api-client-rs/src/apis/default_api.rs +++ b/gamenight-api-client-rs/src/apis/default_api.rs @@ -9,13 +9,1048 @@ */ +use async_trait::async_trait; use reqwest; +use std::sync::Arc; use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration, ContentType}; +use super::{Error, configuration}; +use crate::apis::ContentType; + +#[async_trait] +pub trait DefaultApi: Send + Sync { + + /// GET /authorized_location_user_ids + /// + /// + async fn authorized_location_user_ids_get<'location_id>(&self, location_id: Option) -> Result, Error>; + + /// POST /disown + /// + /// + async fn disown_post<'game_id>(&self, game_id: Option) -> Result<(), Error>; + + /// DELETE /game + /// + /// + async fn game_delete<'game_id>(&self, game_id: Option) -> Result<(), Error>; + + /// GET /game + /// + /// + async fn game_get<'game_id>(&self, game_id: Option) -> Result>; + + /// POST /game + /// + /// + async fn game_post<'add_game_request_body>(&self, add_game_request_body: Option) -> Result>; + + /// GET /games + /// + /// + async fn games_get<>(&self, ) -> Result, Error>; + + /// GET /gamenight + /// + /// + async fn get_gamenight<'get_gamenight_request_body>(&self, get_gamenight_request_body: Option) -> Result>; + + /// GET /gamenights + /// + /// Retrieve the list of gamenights on this gamenight server. Requires authorization. + async fn get_gamenights<>(&self, ) -> Result, Error>; + + /// GET /token + /// + /// Submit your credentials to get a JWT-token to use with the rest of the api. + async fn get_token<'login>(&self, login: Option) -> Result>; + + /// POST /join + /// + /// + async fn join_post<'gamenight_id>(&self, gamenight_id: Option) -> Result<(), Error>; + + /// POST /leave + /// + /// + async fn leave_post<'gamenight_id>(&self, gamenight_id: Option) -> Result<(), Error>; + + /// POST /location_authorize + /// + /// + async fn location_authorize_post<'authorize_location_request_body>(&self, authorize_location_request_body: Option) -> Result<(), Error>; + + /// GET /location + /// + /// + async fn location_get<'location_id>(&self, location_id: Option) -> Result>; + + /// POST /location + /// + /// + async fn location_post<'add_location_request_body>(&self, add_location_request_body: Option) -> Result>; + + /// GET /locations + /// + /// + async fn locations_get<>(&self, ) -> Result, Error>; + + /// POST /own + /// + /// + async fn own_post<'own_game_request_body>(&self, own_game_request_body: Option) -> Result<(), Error>; + + /// GET /owned_games + /// + /// + async fn owned_games_get<'user_id>(&self, user_id: Option) -> Result, Error>; + + /// GET /participants + /// + /// Retrieve the participants of a single gamenight by id. + async fn participants_get<'gamenight_id>(&self, gamenight_id: Option) -> Result>; + + /// POST /gamenight + /// + /// Add a gamenight by providing a name and a date, only available when providing an JWT token. + async fn post_gamenight<'add_gamenight_request_body>(&self, add_gamenight_request_body: Option) -> Result<(), Error>; + + /// POST /user + /// + /// Create a new user given a registration token and user information, username and email must be unique, and password and password_repeat must match. + async fn post_register<'registration>(&self, registration: Option) -> Result<(), Error>; + + /// POST /token + /// + /// Refresh your JWT-token without logging in again. + async fn post_token<>(&self, ) -> Result>; + + /// POST /rename_game + /// + /// + async fn rename_game_post<'rename_game_request_body>(&self, rename_game_request_body: Option) -> Result<(), Error>; + + /// GET /user + /// + /// Get a user from primary id + async fn user_get<'user_id>(&self, user_id: Option) -> Result>; + + /// GET /users + /// + /// + async fn users_get<>(&self, ) -> Result, Error>; +} + +pub struct DefaultApiClient { + configuration: Arc +} + +impl DefaultApiClient { + pub fn new(configuration: Arc) -> Self { + Self { configuration } + } +} -/// struct for typed errors of method [`authorized_location_user_ids_get`] + +#[async_trait] +impl DefaultApi for DefaultApiClient { + async fn authorized_location_user_ids_get<'location_id>(&self, location_id: Option) -> Result, Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/authorized_location_user_ids", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&location_id); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::UserId>`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<models::UserId>`")))), + } + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + async fn disown_post<'game_id>(&self, game_id: Option) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/disown", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&game_id); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + async fn game_delete<'game_id>(&self, game_id: Option) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/game", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&game_id); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + async fn game_get<'game_id>(&self, game_id: Option) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/game", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&game_id); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Game`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::Game`")))), + } + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + async fn game_post<'add_game_request_body>(&self, add_game_request_body: Option) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/game", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&add_game_request_body); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GameId`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::GameId`")))), + } + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + async fn games_get<>(&self, ) -> Result, Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/games", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Game>`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<models::Game>`")))), + } + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + async fn get_gamenight<'get_gamenight_request_body>(&self, get_gamenight_request_body: Option) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/gamenight", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&get_gamenight_request_body); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Gamenight`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::Gamenight`")))), + } + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// Retrieve the list of gamenights on this gamenight server. Requires authorization. + async fn get_gamenights<>(&self, ) -> Result, Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/gamenights", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Gamenight>`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<models::Gamenight>`")))), + } + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// Submit your credentials to get a JWT-token to use with the rest of the api. + async fn get_token<'login>(&self, login: Option) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/token", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + local_var_req_builder = local_var_req_builder.json(&login); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Token`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::Token`")))), + } + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + async fn join_post<'gamenight_id>(&self, gamenight_id: Option) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/join", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&gamenight_id); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + async fn leave_post<'gamenight_id>(&self, gamenight_id: Option) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/leave", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&gamenight_id); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + async fn location_authorize_post<'authorize_location_request_body>(&self, authorize_location_request_body: Option) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/location_authorize", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&authorize_location_request_body); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + async fn location_get<'location_id>(&self, location_id: Option) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/location", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&location_id); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Location`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::Location`")))), + } + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + async fn location_post<'add_location_request_body>(&self, add_location_request_body: Option) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/location", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&add_location_request_body); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LocationId`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::LocationId`")))), + } + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + async fn locations_get<>(&self, ) -> Result, Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/locations", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Location>`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<models::Location>`")))), + } + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + async fn own_post<'own_game_request_body>(&self, own_game_request_body: Option) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/own", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&own_game_request_body); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + async fn owned_games_get<'user_id>(&self, user_id: Option) -> Result, Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/owned_games", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&user_id); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::OwnedGame>`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<models::OwnedGame>`")))), + } + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// Retrieve the participants of a single gamenight by id. + async fn participants_get<'gamenight_id>(&self, gamenight_id: Option) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/participants", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&gamenight_id); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Participants`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::Participants`")))), + } + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// Add a gamenight by providing a name and a date, only available when providing an JWT token. + async fn post_gamenight<'add_gamenight_request_body>(&self, add_gamenight_request_body: Option) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/gamenight", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&add_gamenight_request_body); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// Create a new user given a registration token and user information, username and email must be unique, and password and password_repeat must match. + async fn post_register<'registration>(&self, registration: Option) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/user", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(®istration); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// Refresh your JWT-token without logging in again. + async fn post_token<>(&self, ) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/token", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Token`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::Token`")))), + } + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + async fn rename_game_post<'rename_game_request_body>(&self, rename_game_request_body: Option) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/rename_game", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&rename_game_request_body); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + Ok(()) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + /// Get a user from primary id + async fn user_get<'user_id>(&self, user_id: Option) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/user", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + local_var_req_builder = local_var_req_builder.json(&user_id); + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::User`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::User`")))), + } + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + + async fn users_get<>(&self, ) -> Result, Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/users", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { + local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + }; + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::User>`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<models::User>`")))), + } + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } + } + +} + +/// struct for typed errors of method [`DefaultApi::authorized_location_user_ids_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum AuthorizedLocationUserIdsGetError { @@ -24,7 +1059,7 @@ pub enum AuthorizedLocationUserIdsGetError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`disown_post`] +/// struct for typed errors of method [`DefaultApi::disown_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum DisownPostError { @@ -33,7 +1068,7 @@ pub enum DisownPostError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`game_delete`] +/// struct for typed errors of method [`DefaultApi::game_delete`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GameDeleteError { @@ -42,7 +1077,7 @@ pub enum GameDeleteError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`game_get`] +/// struct for typed errors of method [`DefaultApi::game_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GameGetError { @@ -51,7 +1086,7 @@ pub enum GameGetError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`game_post`] +/// struct for typed errors of method [`DefaultApi::game_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GamePostError { @@ -60,7 +1095,7 @@ pub enum GamePostError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`games_get`] +/// struct for typed errors of method [`DefaultApi::games_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GamesGetError { @@ -69,7 +1104,7 @@ pub enum GamesGetError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`get_gamenight`] +/// struct for typed errors of method [`DefaultApi::get_gamenight`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetGamenightError { @@ -78,7 +1113,7 @@ pub enum GetGamenightError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`get_gamenights`] +/// struct for typed errors of method [`DefaultApi::get_gamenights`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetGamenightsError { @@ -87,7 +1122,7 @@ pub enum GetGamenightsError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`get_token`] +/// struct for typed errors of method [`DefaultApi::get_token`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum GetTokenError { @@ -95,7 +1130,7 @@ pub enum GetTokenError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`join_post`] +/// struct for typed errors of method [`DefaultApi::join_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum JoinPostError { @@ -104,7 +1139,7 @@ pub enum JoinPostError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`leave_post`] +/// struct for typed errors of method [`DefaultApi::leave_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum LeavePostError { @@ -113,7 +1148,7 @@ pub enum LeavePostError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`location_authorize_post`] +/// struct for typed errors of method [`DefaultApi::location_authorize_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum LocationAuthorizePostError { @@ -122,7 +1157,7 @@ pub enum LocationAuthorizePostError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`location_get`] +/// struct for typed errors of method [`DefaultApi::location_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum LocationGetError { @@ -131,7 +1166,7 @@ pub enum LocationGetError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`location_post`] +/// struct for typed errors of method [`DefaultApi::location_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum LocationPostError { @@ -140,7 +1175,7 @@ pub enum LocationPostError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`locations_get`] +/// struct for typed errors of method [`DefaultApi::locations_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum LocationsGetError { @@ -149,7 +1184,7 @@ pub enum LocationsGetError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`own_post`] +/// struct for typed errors of method [`DefaultApi::own_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum OwnPostError { @@ -158,7 +1193,7 @@ pub enum OwnPostError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`owned_games_get`] +/// struct for typed errors of method [`DefaultApi::owned_games_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum OwnedGamesGetError { @@ -167,7 +1202,7 @@ pub enum OwnedGamesGetError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`participants_get`] +/// struct for typed errors of method [`DefaultApi::participants_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum ParticipantsGetError { @@ -176,7 +1211,7 @@ pub enum ParticipantsGetError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`post_gamenight`] +/// struct for typed errors of method [`DefaultApi::post_gamenight`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum PostGamenightError { @@ -185,7 +1220,7 @@ pub enum PostGamenightError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`post_register`] +/// struct for typed errors of method [`DefaultApi::post_register`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum PostRegisterError { @@ -193,7 +1228,7 @@ pub enum PostRegisterError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`post_token`] +/// struct for typed errors of method [`DefaultApi::post_token`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum PostTokenError { @@ -201,7 +1236,7 @@ pub enum PostTokenError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`rename_game_post`] +/// struct for typed errors of method [`DefaultApi::rename_game_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum RenameGamePostError { @@ -210,7 +1245,7 @@ pub enum RenameGamePostError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`user_get`] +/// struct for typed errors of method [`DefaultApi::user_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UserGetError { @@ -220,7 +1255,7 @@ pub enum UserGetError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`users_get`] +/// struct for typed errors of method [`DefaultApi::users_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum UsersGetError { @@ -229,854 +1264,3 @@ pub enum UsersGetError { UnknownValue(serde_json::Value), } - -pub async fn authorized_location_user_ids_get(configuration: &configuration::Configuration, location_id: Option) -> Result, Error> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_location_id = location_id; - - let uri_str = format!("{}/authorized_location_user_ids", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_body_location_id); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); - - if !status.is_client_error() && !status.is_server_error() { - let content = resp.text().await?; - match content_type { - ContentType::Json => serde_json::from_str(&content).map_err(Error::from), - ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::UserId>`"))), - ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::UserId>`")))), - } - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -pub async fn disown_post(configuration: &configuration::Configuration, game_id: Option) -> Result<(), Error> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_game_id = game_id; - - let uri_str = format!("{}/disown", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_body_game_id); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - - if !status.is_client_error() && !status.is_server_error() { - Ok(()) - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -pub async fn game_delete(configuration: &configuration::Configuration, game_id: Option) -> Result<(), Error> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_game_id = game_id; - - let uri_str = format!("{}/game", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_body_game_id); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - - if !status.is_client_error() && !status.is_server_error() { - Ok(()) - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -pub async fn game_get(configuration: &configuration::Configuration, game_id: Option) -> Result> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_game_id = game_id; - - let uri_str = format!("{}/game", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_body_game_id); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); - - if !status.is_client_error() && !status.is_server_error() { - let content = resp.text().await?; - match content_type { - ContentType::Json => serde_json::from_str(&content).map_err(Error::from), - ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Game`"))), - ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Game`")))), - } - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -pub async fn game_post(configuration: &configuration::Configuration, add_game_request_body: Option) -> Result> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_add_game_request_body = add_game_request_body; - - let uri_str = format!("{}/game", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_body_add_game_request_body); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); - - if !status.is_client_error() && !status.is_server_error() { - let content = resp.text().await?; - match content_type { - ContentType::Json => serde_json::from_str(&content).map_err(Error::from), - ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GameId`"))), - ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GameId`")))), - } - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -pub async fn games_get(configuration: &configuration::Configuration, ) -> Result, Error> { - - let uri_str = format!("{}/games", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); - - if !status.is_client_error() && !status.is_server_error() { - let content = resp.text().await?; - match content_type { - ContentType::Json => serde_json::from_str(&content).map_err(Error::from), - ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Game>`"))), - ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Game>`")))), - } - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -pub async fn get_gamenight(configuration: &configuration::Configuration, get_gamenight_request_body: Option) -> Result> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_get_gamenight_request_body = get_gamenight_request_body; - - let uri_str = format!("{}/gamenight", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_body_get_gamenight_request_body); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); - - if !status.is_client_error() && !status.is_server_error() { - let content = resp.text().await?; - match content_type { - ContentType::Json => serde_json::from_str(&content).map_err(Error::from), - ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Gamenight`"))), - ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Gamenight`")))), - } - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -/// Retrieve the list of gamenights on this gamenight server. Requires authorization. -pub async fn get_gamenights(configuration: &configuration::Configuration, ) -> Result, Error> { - - let uri_str = format!("{}/gamenights", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); - - if !status.is_client_error() && !status.is_server_error() { - let content = resp.text().await?; - match content_type { - ContentType::Json => serde_json::from_str(&content).map_err(Error::from), - ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Gamenight>`"))), - ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Gamenight>`")))), - } - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -/// Submit your credentials to get a JWT-token to use with the rest of the api. -pub async fn get_token(configuration: &configuration::Configuration, login: Option) -> Result> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_login = login; - - let uri_str = format!("{}/token", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - req_builder = req_builder.json(&p_body_login); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); - - if !status.is_client_error() && !status.is_server_error() { - let content = resp.text().await?; - match content_type { - ContentType::Json => serde_json::from_str(&content).map_err(Error::from), - ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Token`"))), - ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Token`")))), - } - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -pub async fn join_post(configuration: &configuration::Configuration, gamenight_id: Option) -> Result<(), Error> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_gamenight_id = gamenight_id; - - let uri_str = format!("{}/join", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_body_gamenight_id); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - - if !status.is_client_error() && !status.is_server_error() { - Ok(()) - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -pub async fn leave_post(configuration: &configuration::Configuration, gamenight_id: Option) -> Result<(), Error> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_gamenight_id = gamenight_id; - - let uri_str = format!("{}/leave", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_body_gamenight_id); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - - if !status.is_client_error() && !status.is_server_error() { - Ok(()) - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -pub async fn location_authorize_post(configuration: &configuration::Configuration, authorize_location_request_body: Option) -> Result<(), Error> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_authorize_location_request_body = authorize_location_request_body; - - let uri_str = format!("{}/location_authorize", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_body_authorize_location_request_body); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - - if !status.is_client_error() && !status.is_server_error() { - Ok(()) - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -pub async fn location_get(configuration: &configuration::Configuration, location_id: Option) -> Result> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_location_id = location_id; - - let uri_str = format!("{}/location", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_body_location_id); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); - - if !status.is_client_error() && !status.is_server_error() { - let content = resp.text().await?; - match content_type { - ContentType::Json => serde_json::from_str(&content).map_err(Error::from), - ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Location`"))), - ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Location`")))), - } - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -pub async fn location_post(configuration: &configuration::Configuration, add_location_request_body: Option) -> Result> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_add_location_request_body = add_location_request_body; - - let uri_str = format!("{}/location", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_body_add_location_request_body); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); - - if !status.is_client_error() && !status.is_server_error() { - let content = resp.text().await?; - match content_type { - ContentType::Json => serde_json::from_str(&content).map_err(Error::from), - ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LocationId`"))), - ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::LocationId`")))), - } - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -pub async fn locations_get(configuration: &configuration::Configuration, ) -> Result, Error> { - - let uri_str = format!("{}/locations", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); - - if !status.is_client_error() && !status.is_server_error() { - let content = resp.text().await?; - match content_type { - ContentType::Json => serde_json::from_str(&content).map_err(Error::from), - ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Location>`"))), - ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Location>`")))), - } - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -pub async fn own_post(configuration: &configuration::Configuration, own_game_request_body: Option) -> Result<(), Error> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_own_game_request_body = own_game_request_body; - - let uri_str = format!("{}/own", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_body_own_game_request_body); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - - if !status.is_client_error() && !status.is_server_error() { - Ok(()) - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -pub async fn owned_games_get(configuration: &configuration::Configuration, user_id: Option) -> Result, Error> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_user_id = user_id; - - let uri_str = format!("{}/owned_games", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_body_user_id); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); - - if !status.is_client_error() && !status.is_server_error() { - let content = resp.text().await?; - match content_type { - ContentType::Json => serde_json::from_str(&content).map_err(Error::from), - ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<String>`"))), - ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<String>`")))), - } - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -/// Retrieve the participants of a single gamenight by id. -pub async fn participants_get(configuration: &configuration::Configuration, gamenight_id: Option) -> Result> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_gamenight_id = gamenight_id; - - let uri_str = format!("{}/participants", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_body_gamenight_id); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); - - if !status.is_client_error() && !status.is_server_error() { - let content = resp.text().await?; - match content_type { - ContentType::Json => serde_json::from_str(&content).map_err(Error::from), - ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Participants`"))), - ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Participants`")))), - } - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -/// Add a gamenight by providing a name and a date, only available when providing an JWT token. -pub async fn post_gamenight(configuration: &configuration::Configuration, add_gamenight_request_body: Option) -> Result<(), Error> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_add_gamenight_request_body = add_gamenight_request_body; - - let uri_str = format!("{}/gamenight", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_body_add_gamenight_request_body); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - - if !status.is_client_error() && !status.is_server_error() { - Ok(()) - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -/// Create a new user given a registration token and user information, username and email must be unique, and password and password_repeat must match. -pub async fn post_register(configuration: &configuration::Configuration, registration: Option) -> Result<(), Error> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_registration = registration; - - let uri_str = format!("{}/user", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_body_registration); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - - if !status.is_client_error() && !status.is_server_error() { - Ok(()) - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -/// Refresh your JWT-token without logging in again. -pub async fn post_token(configuration: &configuration::Configuration, ) -> Result> { - - let uri_str = format!("{}/token", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); - - if !status.is_client_error() && !status.is_server_error() { - let content = resp.text().await?; - match content_type { - ContentType::Json => serde_json::from_str(&content).map_err(Error::from), - ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Token`"))), - ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Token`")))), - } - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -pub async fn rename_game_post(configuration: &configuration::Configuration, rename_game_request_body: Option) -> Result<(), Error> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_rename_game_request_body = rename_game_request_body; - - let uri_str = format!("{}/rename_game", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_body_rename_game_request_body); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - - if !status.is_client_error() && !status.is_server_error() { - Ok(()) - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -/// Get a user from primary id -pub async fn user_get(configuration: &configuration::Configuration, user_id: Option) -> Result> { - // add a prefix to parameters to efficiently prevent name collisions - let p_body_user_id = user_id; - - let uri_str = format!("{}/user", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_body_user_id); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); - - if !status.is_client_error() && !status.is_server_error() { - let content = resp.text().await?; - match content_type { - ContentType::Json => serde_json::from_str(&content).map_err(Error::from), - ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::User`"))), - ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::User`")))), - } - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -pub async fn users_get(configuration: &configuration::Configuration, ) -> Result, Error> { - - let uri_str = format!("{}/users", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); - - if !status.is_client_error() && !status.is_server_error() { - let content = resp.text().await?; - match content_type { - ContentType::Json => serde_json::from_str(&content).map_err(Error::from), - ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::User>`"))), - ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::User>`")))), - } - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - diff --git a/gamenight-api-client-rs/src/apis/mod.rs b/gamenight-api-client-rs/src/apis/mod.rs index fdcc89b..dd668b0 100644 --- a/gamenight-api-client-rs/src/apis/mod.rs +++ b/gamenight-api-client-rs/src/apis/mod.rs @@ -114,3 +114,4 @@ impl From<&str> for ContentType { pub mod default_api; pub mod configuration; + diff --git a/gamenight-api-client-rs/src/lib.rs b/gamenight-api-client-rs/src/lib.rs index e152062..edc482e 100644 --- a/gamenight-api-client-rs/src/lib.rs +++ b/gamenight-api-client-rs/src/lib.rs @@ -5,7 +5,6 @@ extern crate serde_repr; extern crate serde; extern crate serde_json; extern crate url; -extern crate reqwest; pub mod apis; pub mod models; diff --git a/gamenight-api-client-rs/src/models/gamenight.rs b/gamenight-api-client-rs/src/models/gamenight.rs index d01667d..a4bffe3 100644 --- a/gamenight-api-client-rs/src/models/gamenight.rs +++ b/gamenight-api-client-rs/src/models/gamenight.rs @@ -17,6 +17,8 @@ pub struct Gamenight { pub id: String, #[serde(rename = "name")] pub name: String, + #[serde(rename = "location_id", skip_serializing_if = "Option::is_none")] + pub location_id: Option, #[serde(rename = "datetime")] pub datetime: String, #[serde(rename = "owner_id")] @@ -28,6 +30,7 @@ impl Gamenight { Gamenight { id, name, + location_id: None, datetime, owner_id, } diff --git a/gamenight-api-client-rs/src/models/mod.rs b/gamenight-api-client-rs/src/models/mod.rs index a2d86dd..8189728 100644 --- a/gamenight-api-client-rs/src/models/mod.rs +++ b/gamenight-api-client-rs/src/models/mod.rs @@ -26,6 +26,8 @@ pub mod login; pub use self::login::Login; pub mod own_game_request_body; pub use self::own_game_request_body::OwnGameRequestBody; +pub mod owned_game; +pub use self::owned_game::OwnedGame; pub mod participants; pub use self::participants::Participants; pub mod registration; diff --git a/gamenight-api-client-rs/src/models/owned_game.rs b/gamenight-api-client-rs/src/models/owned_game.rs new file mode 100644 index 0000000..e329344 --- /dev/null +++ b/gamenight-api-client-rs/src/models/owned_game.rs @@ -0,0 +1,30 @@ +/* + * Gamenight + * + * Api specification for a Gamenight server + * + * The version of the OpenAPI document: 1.0 + * Contact: dennis@brentj.es + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct OwnedGame { + #[serde(rename = "game_id")] + pub game_id: String, + #[serde(rename = "location_id", skip_serializing_if = "Option::is_none")] + pub location_id: Option, +} + +impl OwnedGame { + pub fn new(game_id: String) -> OwnedGame { + OwnedGame { + game_id, + location_id: None, + } + } +} + diff --git a/gamenight-cli/Cargo.lock b/gamenight-cli/Cargo.lock index f44a2b8..0ac300e 100644 --- a/gamenight-cli/Cargo.lock +++ b/gamenight-cli/Cargo.lock @@ -108,6 +108,15 @@ dependencies = [ "cc", ] +[[package]] +name = "colored" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -221,21 +230,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "futures" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - [[package]] name = "futures-channel" version = "0.3.31" @@ -243,7 +237,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", - "futures-sink", ] [[package]] @@ -252,17 +245,6 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" -[[package]] -name = "futures-executor" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - [[package]] name = "futures-io" version = "0.3.31" @@ -298,7 +280,6 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ - "futures-channel", "futures-core", "futures-io", "futures-macro", @@ -332,6 +313,7 @@ dependencies = [ name = "gamenight-api-client-rs" version = "0.1.0" dependencies = [ + "async-trait", "reqwest", "serde", "serde_json", @@ -346,8 +328,8 @@ dependencies = [ "async-trait", "chrono", "clear_screen", + "colored", "dyn-clone", - "futures", "gamenight-api-client-rs", "inquire", "jsonwebtoken", @@ -996,12 +978,14 @@ dependencies = [ "sync_wrapper", "tokio", "tokio-native-tls", + "tokio-util", "tower", "tower-http", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", + "wasm-streams", "web-sys", ] @@ -1236,9 +1220,9 @@ checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" [[package]] name = "syn" -version = "2.0.113" +version = "2.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678faa00651c9eb72dd2020cbdf275d92eccb2400d568e419efdd64838145cb4" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" dependencies = [ "proc-macro2", "quote", @@ -1386,6 +1370,19 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-util" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + [[package]] name = "tower" version = "0.5.2" @@ -1604,6 +1601,19 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "wasm-streams" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15053d8d85c7eccdbefef60f06769760a563c7f0a9d6902a13d35c7800b0ad65" +dependencies = [ + "futures-util", + "js-sys", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "web-sys" version = "0.3.83" diff --git a/gamenight-cli/Cargo.toml b/gamenight-cli/Cargo.toml index 953f815..87326ca 100644 --- a/gamenight-cli/Cargo.toml +++ b/gamenight-cli/Cargo.toml @@ -15,4 +15,4 @@ jsonwebtoken = "9.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" clear_screen = "0.1" -futures = "0.3" +colored = "3.0" diff --git a/gamenight-cli/src/domain/eligable_games.rs b/gamenight-cli/src/domain/eligable_games.rs new file mode 100644 index 0000000..6228e24 --- /dev/null +++ b/gamenight-cli/src/domain/eligable_games.rs @@ -0,0 +1,20 @@ +use std::fmt::Display; +use colored::Colorize; +use crate::domain::location::Location; +use crate::domain::owned_games::OwnedGames; + +pub struct EligableGames<'a>(pub &'a OwnedGames, pub &'a Location); + +impl Display for EligableGames<'_> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + for (k, v) in self.0.0.iter() { + writeln!(f, "{}:", k)?; + for (g, l) in v.iter() { + if l.as_ref().is_none_or(|x| x.id == self.1.id) { + writeln!(f, "\t{}", g.name.green())?; + } + } + } + Ok(()) + } +} \ No newline at end of file diff --git a/gamenight-cli/src/domain/gamenight.rs b/gamenight-cli/src/domain/gamenight.rs index 88a7d52..49fb1b4 100644 --- a/gamenight-cli/src/domain/gamenight.rs +++ b/gamenight-cli/src/domain/gamenight.rs @@ -1,6 +1,8 @@ use std::fmt::{Display, Formatter}; use chrono::{DateTime, Local}; use uuid::Uuid; +use crate::domain::eligable_games::EligableGames; +use crate::domain::location::Location; use crate::domain::owned_games::OwnedGames; use crate::domain::participants::Participants; use crate::domain::user::User; @@ -9,6 +11,7 @@ use crate::domain::user::User; pub struct Gamenight { pub id: Uuid, pub name: String, + pub location: Option, pub start_time: DateTime, pub organizer: User, pub participants: Participants, @@ -21,7 +24,12 @@ impl Display for Gamenight { writeln!(f, "Organizer: {}", self.organizer)?; writeln!(f, "Start: {}", self.start_time.to_rfc3339())?; writeln!(f, "Participants: {}", self.participants)?; - write!(f, "Owned games:\n{}", self.owned_games)?; + if let Some(location) = &self.location { + write!(f, "Eligable games:\n{}", EligableGames(&self.owned_games, location))?; + } else { + write!(f, "Owned games: \n{}", self.owned_games)?; + } + Ok(()) } } \ No newline at end of file diff --git a/gamenight-cli/src/domain/gamenight_select_data.rs b/gamenight-cli/src/domain/gamenight_select_data.rs index 04bf39b..730cd47 100644 --- a/gamenight-cli/src/domain/gamenight_select_data.rs +++ b/gamenight-cli/src/domain/gamenight_select_data.rs @@ -7,6 +7,7 @@ use uuid::Uuid; pub struct GamenightSelectData { pub id: Uuid, pub name: String, + pub location_id: Option, pub start_time: DateTime, pub owner_id: Uuid, } diff --git a/gamenight-cli/src/domain/location.rs b/gamenight-cli/src/domain/location.rs index 81a4d46..00a026a 100644 --- a/gamenight-cli/src/domain/location.rs +++ b/gamenight-cli/src/domain/location.rs @@ -2,6 +2,7 @@ use std::fmt::Display; use gamenight_api_client_rs::models; use uuid::Uuid; +use crate::flows::FlowError; #[derive(Clone)] pub struct Location { @@ -11,14 +12,15 @@ pub struct Location { pub note: Option, } -impl From for Location { - fn from(location: models::Location) -> Self { - Self { - id: Uuid::parse_str(&location.id).unwrap(), - name: location.name, - address: location.address, - note: location.note - } +impl TryFrom for Location { + type Error = FlowError; + fn try_from(value: models::Location) -> Result { + Ok(Self { + id: Uuid::parse_str(&value.id)?, + name: value.name, + address: value.address, + note: value.note + }) } } diff --git a/gamenight-cli/src/domain/mod.rs b/gamenight-cli/src/domain/mod.rs index 5642de2..5f9fb24 100644 --- a/gamenight-cli/src/domain/mod.rs +++ b/gamenight-cli/src/domain/mod.rs @@ -6,4 +6,5 @@ pub mod game; pub mod owned_games; pub mod location; pub mod location_select_data; -pub mod gamenight; \ No newline at end of file +pub mod gamenight; +mod eligable_games; \ No newline at end of file diff --git a/gamenight-cli/src/domain/owned_games.rs b/gamenight-cli/src/domain/owned_games.rs index 834ebe4..2b076e9 100644 --- a/gamenight-cli/src/domain/owned_games.rs +++ b/gamenight-cli/src/domain/owned_games.rs @@ -1,15 +1,16 @@ use std::{collections::HashMap, fmt::Display}; use crate::domain::game::Game; +use crate::domain::location::Location; #[derive(Clone)] -pub struct OwnedGames(pub HashMap>); +pub struct OwnedGames (pub HashMap)>>); impl Display for OwnedGames { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { for (k,v) in &self.0 { write!(f, "{k}:\n")?; - for g in v { + for (g, _) in v { write!(f, "\t{}\n", g.name)?; } } diff --git a/gamenight-cli/src/flows/add_game.rs b/gamenight-cli/src/flows/add_game.rs index 4e671a9..7b2327a 100644 --- a/gamenight-cli/src/flows/add_game.rs +++ b/gamenight-cli/src/flows/add_game.rs @@ -3,7 +3,7 @@ use std::fmt::Display; use super::*; use crate::flows::own::Own; use async_trait::async_trait; -use gamenight_api_client_rs::{apis::default_api::game_post, models::AddGameRequestBody}; +use gamenight_api_client_rs::models::AddGameRequestBody; use inquire::Text; @@ -24,7 +24,7 @@ impl<'a> Flow<'a> for AddGame { let add_game_request = AddGameRequestBody { name }; - let game_id_response = game_post(&state.api_configuration, Some(add_game_request)).await?; + let game_id_response = state.api.game_post(Some(add_game_request)).await?; let own_flow = Own::new(Uuid::parse_str(&game_id_response.game_id)?); return self.continue_with(state, &own_flow).await; diff --git a/gamenight-cli/src/flows/add_gamenight.rs b/gamenight-cli/src/flows/add_gamenight.rs index 58791f1..3564705 100644 --- a/gamenight-cli/src/flows/add_gamenight.rs +++ b/gamenight-cli/src/flows/add_gamenight.rs @@ -1,8 +1,7 @@ -use gamenight_api_client_rs::{apis::default_api::post_gamenight, models}; use inquire::{CustomType, DateSelect, Text}; use chrono::{self, Local, NaiveTime}; - +use gamenight_api_client_rs::models; use super::*; #[derive(Clone)] @@ -32,7 +31,7 @@ impl<'a> Flow<'a> for AddGamenight { .to_utc() .to_rfc3339(); let add_gamenight = models::AddGamenightRequestBody::new(name, datetime); - post_gamenight(&state.api_configuration, Some(add_gamenight)).await?; + state.api.post_gamenight(Some(add_gamenight)).await?; clear_screen::clear(); return Ok((FlowOutcome::Successful, state)) diff --git a/gamenight-cli/src/flows/add_location.rs b/gamenight-cli/src/flows/add_location.rs index 9c0e5a3..27b9a38 100644 --- a/gamenight-cli/src/flows/add_location.rs +++ b/gamenight-cli/src/flows/add_location.rs @@ -1,7 +1,7 @@ use std::{ffi::OsStr, fmt::Display}; use async_trait::async_trait; -use gamenight_api_client_rs::{apis::default_api::{location_authorize_post, location_post}, models::{authorize_location_request_body::Op::Grant, AddLocationRequestBody, AuthorizeLocationRequestBody}}; +use gamenight_api_client_rs::models::{authorize_location_request_body::Op::Grant, AddLocationRequestBody, AuthorizeLocationRequestBody}; use inquire::{Editor, Text}; @@ -44,7 +44,7 @@ impl<'a> Flow<'a> for AddLocation { note }; - let location_id = location_post(&state.api_configuration, Some(add_location_request)).await?; + let location_id = state.api.location_post(Some(add_location_request)).await?; let add_authorize_request = AuthorizeLocationRequestBody { location_id: location_id.location_id.to_string(), @@ -52,7 +52,7 @@ impl<'a> Flow<'a> for AddLocation { op: Grant }; - location_authorize_post(&state.api_configuration, Some(add_authorize_request)).await?; + state.api.location_authorize_post(Some(add_authorize_request)).await?; } Ok((FlowOutcome::Cancelled, state)) } diff --git a/gamenight-cli/src/flows/connect.rs b/gamenight-cli/src/flows/connect.rs index 9f189f2..950d364 100644 --- a/gamenight-cli/src/flows/connect.rs +++ b/gamenight-cli/src/flows/connect.rs @@ -1,12 +1,9 @@ use std::fmt::Display; -use async_trait::async_trait; -use gamenight_api_client_rs::apis::configuration::Configuration; -use inquire::Text; - -use crate::{domain::config::{Config, Instance}, flows::{gamenight_menu::GamenightMenu, login::Login, FlowError}}; - use super::{Flow, FlowOutcome, FlowResult, GamenightState}; +use crate::{domain::config::{Config, Instance}, flows::{gamenight_menu::GamenightMenu, login::Login, FlowError}}; +use async_trait::async_trait; +use inquire::Text; #[derive(Clone)] pub struct Connect { @@ -50,37 +47,37 @@ impl Connect { } - pub async fn try_refresh_token_if_exists(&self, instance: &mut Instance, api_configuration: &mut Configuration, config: &mut Config, instance_name: &String) -> Result { + pub async fn try_refresh_token_if_exists<'a>(&self, instance: &mut Instance, state: &'a mut GamenightState, instance_name: &String) -> Result<(bool, &'a mut GamenightState), FlowError> { if let Some(token) = &instance.token { - api_configuration.bearer_access_token = Some(token.clone()); - let result = gamenight_api_client_rs::apis::default_api::post_token(api_configuration).await; + let state = state.set_bearer_access_token(Some(token.clone())); + let result = state.api.post_token().await; if let Ok(token) = result { - let instance = config.instances.iter_mut().find(|x| x.name == *instance_name).unwrap(); + let instance = state.gamenight_configuration.instances.iter_mut().find(|x| x.name == *instance_name).unwrap(); instance.token = token.jwt_token.clone(); - api_configuration.bearer_access_token = token.jwt_token.clone(); - Config::save(config)?; - Ok(true) + let state = state.set_bearer_access_token(token.jwt_token.clone()); + Config::save(&state.gamenight_configuration)?; + Ok((true, state)) } else { - Ok(false) + Ok((false, state)) } } else { - Ok(false) + Ok((false, state)) } } - pub fn update_state_on_logon(&self, instance: &mut Instance, api_configuration: &mut Configuration, config: &mut Config, instance_name: &String) -> Result<(), FlowError> { + pub fn update_state_on_logon(&self, instance: &mut Instance, state: &mut GamenightState, instance_name: &String) -> Result<(), FlowError> { if self.instance.is_none() { - instance.token = Some(api_configuration.bearer_access_token.clone().unwrap()); - config.instances.push(instance.clone()); + instance.token = Some(state.api_configuration.bearer_access_token.clone().unwrap()); + state.gamenight_configuration.instances.push(instance.clone()); } else { - let instance = config.instances.iter_mut().find(|x| x.name == *instance_name).unwrap(); - instance.token = Some(api_configuration.bearer_access_token.clone().unwrap()); + let instance = state.gamenight_configuration.instances.iter_mut().find(|x| x.name == *instance_name).unwrap(); + instance.token = Some(state.api_configuration.bearer_access_token.clone().unwrap()); } - config.last_instance = Some(instance_name.clone()); + state.gamenight_configuration.last_instance = Some(instance_name.clone()); - Config::save(config)?; + Config::save(&state.gamenight_configuration)?; Ok(()) } } @@ -98,9 +95,10 @@ impl<'a> Flow<'a> for Connect { }; let instance_name = instance.name.clone(); - state.api_configuration.base_path = instance.url.clone(); + let state = state.set_api_base_path(instance.url.clone()); - if self.try_refresh_token_if_exists(&mut instance, &mut state.api_configuration, &mut state.gamenight_configuration, &instance_name).await? { + let (token_refreshed, state) = self.try_refresh_token_if_exists(&mut instance, state, &instance_name).await?; + if token_refreshed { let gamenight_menu_flow = GamenightMenu::new(); gamenight_menu_flow.run(state).await } @@ -109,7 +107,7 @@ impl<'a> Flow<'a> for Connect { let (outcome, state) = login_flow.run(state).await?; if outcome == FlowOutcome::Successful { - self.update_state_on_logon(&mut instance, &mut state.api_configuration, &mut state.gamenight_configuration, &instance_name)?; + self.update_state_on_logon(&mut instance, state, &instance_name)?; let gamenight_menu_flow = GamenightMenu::new(); gamenight_menu_flow.run(state).await diff --git a/gamenight-cli/src/flows/disown.rs b/gamenight-cli/src/flows/disown.rs index bb1d4be..05b566f 100644 --- a/gamenight-cli/src/flows/disown.rs +++ b/gamenight-cli/src/flows/disown.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use async_trait::async_trait; -use gamenight_api_client_rs::{apis::default_api::disown_post, models::GameId}; +use gamenight_api_client_rs::models::GameId; use uuid::Uuid; use super::{Flow, FlowOutcome, FlowResult, GamenightState}; @@ -22,7 +22,7 @@ impl Disown { #[async_trait] impl<'a> Flow<'a> for Disown { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { - let _ = disown_post(&state.api_configuration, Some(GameId{game_id: self.game_id.to_string()})).await?; + let _ = state.api.disown_post(Some(GameId{game_id: self.game_id.to_string()})).await?; clear_screen::clear(); Ok((FlowOutcome::Successful, state)) diff --git a/gamenight-cli/src/flows/join.rs b/gamenight-cli/src/flows/join.rs index 12cf4d5..68c1d6f 100644 --- a/gamenight-cli/src/flows/join.rs +++ b/gamenight-cli/src/flows/join.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use async_trait::async_trait; -use gamenight_api_client_rs::{apis::default_api::join_post, models::GamenightId}; +use gamenight_api_client_rs::models::GamenightId; use uuid::Uuid; use super::{Flow, FlowOutcome, FlowResult, GamenightState}; @@ -22,7 +22,7 @@ impl Join { #[async_trait] impl<'a> Flow<'a> for Join { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { - let _ = join_post(&state.api_configuration, Some(GamenightId{gamenight_id: self.gamenight_id.to_string()})).await?; + let _ = state.api.join_post(Some(GamenightId{gamenight_id: self.gamenight_id.to_string()})).await?; clear_screen::clear(); Ok((FlowOutcome::Successful, state)) diff --git a/gamenight-cli/src/flows/leave.rs b/gamenight-cli/src/flows/leave.rs index 3db820a..b475d89 100644 --- a/gamenight-cli/src/flows/leave.rs +++ b/gamenight-cli/src/flows/leave.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use async_trait::async_trait; -use gamenight_api_client_rs::{apis::default_api::leave_post, models::GamenightId}; +use gamenight_api_client_rs::models::GamenightId; use uuid::Uuid; use super::{Flow, FlowOutcome, FlowResult, GamenightState}; @@ -22,7 +22,7 @@ impl Leave { #[async_trait] impl<'a> Flow<'a> for Leave { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { - let _ = leave_post(&state.api_configuration, Some(GamenightId{gamenight_id: self.gamenight_id.to_string()})).await?; + let _ = state.api.leave_post(Some(GamenightId{gamenight_id: self.gamenight_id.to_string()})).await?; clear_screen::clear(); Ok((FlowOutcome::Successful, state)) diff --git a/gamenight-cli/src/flows/list_gamenights.rs b/gamenight-cli/src/flows/list_gamenights.rs index a4010f7..131dcb6 100644 --- a/gamenight-cli/src/flows/list_gamenights.rs +++ b/gamenight-cli/src/flows/list_gamenights.rs @@ -1,6 +1,5 @@ use chrono::DateTime; -use gamenight_api_client_rs::apis::default_api::get_gamenights; use inquire::Select; use uuid::Uuid; @@ -22,7 +21,7 @@ impl ListGamenights { #[async_trait] impl<'a> Flow<'a> for ListGamenights { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { - let response = get_gamenights(&state.api_configuration).await?; + let response = state.api.get_gamenights().await?; let mut view_flows: Vec + Send>> = vec![]; @@ -30,6 +29,10 @@ impl<'a> Flow<'a> for ListGamenights { let gamenight = GamenightSelectData { id: Uuid::parse_str(&response.id)?, name: response.name.clone(), + location_id: match &response.location_id { + None => None, + Some(x) => Some(Uuid::parse_str(x)?) + }, start_time:DateTime::parse_from_rfc3339(&response.datetime)?.into(), owner_id: Uuid::parse_str(&response.owner_id)? }; diff --git a/gamenight-cli/src/flows/list_games.rs b/gamenight-cli/src/flows/list_games.rs index c9c1fa4..22d2595 100644 --- a/gamenight-cli/src/flows/list_games.rs +++ b/gamenight-cli/src/flows/list_games.rs @@ -1,7 +1,6 @@ use std::fmt::Display; use async_trait::async_trait; -use gamenight_api_client_rs::apis::default_api::games_get; use inquire::{ui::RenderConfig, Select}; use crate::flows::{view_game::ViewGame, exit::Exit}; @@ -22,7 +21,7 @@ impl ListGames { #[async_trait] impl<'a> Flow<'a> for ListGames { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { - let games = games_get(&state.api_configuration).await?; + let games = state.api.games_get().await?; let mut flows = games.into_iter().map(|game| -> Box { Box::new(ViewGame::new(game.into())) diff --git a/gamenight-cli/src/flows/list_locations.rs b/gamenight-cli/src/flows/list_locations.rs index 020d51f..f341707 100644 --- a/gamenight-cli/src/flows/list_locations.rs +++ b/gamenight-cli/src/flows/list_locations.rs @@ -1,7 +1,6 @@ use std::fmt::Display; use async_trait::async_trait; -use gamenight_api_client_rs::apis::default_api::locations_get; use inquire::{ui::RenderConfig, Select}; use crate::flows::{exit::Exit, view_location::ViewLocation}; @@ -22,10 +21,10 @@ impl ListLocations { #[async_trait] impl<'a> Flow<'a> for ListLocations { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { - let locations = locations_get(&state.api_configuration).await?; + let locations = state.api.locations_get().await?; let mut flows = locations.into_iter().map(|location| -> Box { - Box::new(ViewLocation::new(location.into())) + Box::new(ViewLocation::new(location.try_into().unwrap())) }).collect::>>(); flows.push(Box::new(Exit::new())); diff --git a/gamenight-cli/src/flows/location_authorize.rs b/gamenight-cli/src/flows/location_authorize.rs index b4ab0e5..9208436 100644 --- a/gamenight-cli/src/flows/location_authorize.rs +++ b/gamenight-cli/src/flows/location_authorize.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use async_trait::async_trait; -use gamenight_api_client_rs::{apis::default_api::{self, authorized_location_user_ids_get, users_get}, models::{AuthorizeLocationRequestBody, LocationId, User}}; +use gamenight_api_client_rs::models::{AuthorizeLocationRequestBody, LocationId, User}; use inquire::MultiSelect; use uuid::Uuid; @@ -47,11 +47,11 @@ impl<'a> TryFrom<&'a User> for AuthorizeMultiSelectStruct<'a> { #[async_trait] impl<'a> Flow<'a> for LocationAuthorize { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { - let users = users_get(&state.api_configuration).await?; + let users = state.api.users_get().await?; let location_id = LocationId { location_id: self.location_id.to_string() }; - let authorized_user_ids = authorized_location_user_ids_get(&state.api_configuration, Some(location_id)).await?; + let authorized_user_ids = state.api.authorized_location_user_ids_get(Some(location_id)).await?; let authorized_user_ids : Vec = authorized_user_ids.into_iter().map(|x| x.user_id).collect(); let options: Vec = users.iter().map(|x| {x.try_into()}).collect::, FlowError>>()?; @@ -67,7 +67,7 @@ impl<'a> Flow<'a> for LocationAuthorize { if let Some(selections) = &selections { for selection in selections { if authorized_users.iter().find(|x| {x.id == selection.id.to_string()}).is_none() { - default_api::location_authorize_post(&state.api_configuration, Some( + state.api.location_authorize_post(Some( AuthorizeLocationRequestBody { location_id: self.location_id.to_string(), user_id: selection.id.to_string(), @@ -78,7 +78,7 @@ impl<'a> Flow<'a> for LocationAuthorize { } for authorized_user in authorized_users { if selections.iter().find(|x| {x.id.to_string() == authorized_user.id}).is_none() { - default_api::location_authorize_post(&state.api_configuration, Some( + state.api.location_authorize_post(Some( AuthorizeLocationRequestBody { location_id: self.location_id.to_string(), user_id: authorized_user.id.to_string(), diff --git a/gamenight-cli/src/flows/login.rs b/gamenight-cli/src/flows/login.rs index d4d4352..a5f8579 100644 --- a/gamenight-cli/src/flows/login.rs +++ b/gamenight-cli/src/flows/login.rs @@ -1,5 +1,5 @@ use async_trait::async_trait; -use gamenight_api_client_rs::{apis::{configuration::Configuration, default_api::get_token}, models}; +use gamenight_api_client_rs::models; use inquire::{Password, Text}; use super::*; @@ -18,7 +18,6 @@ impl Login { #[async_trait] impl<'a> Flow<'a> for Login { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { - let configuration = Configuration::new(); let username = Text::new("What is your login?").prompt()?; let password = Password::new("what is your password?") @@ -27,11 +26,11 @@ impl<'a> Flow<'a> for Login { let login = models::Login::new(username, password); - let result = get_token(&configuration, Some(login)).await?; + let result = state.api.get_token(Some(login)).await?; clear_screen::clear(); if let Some(token) = result.jwt_token { - state.api_configuration.bearer_access_token = Some(token); + state.set_bearer_access_token(Some(token)); Ok((FlowOutcome::Successful, state)) } else { Err(FlowError{error: "Unexpected response".to_string()}) diff --git a/gamenight-cli/src/flows/mod.rs b/gamenight-cli/src/flows/mod.rs index f03daf5..fd58132 100644 --- a/gamenight-cli/src/flows/mod.rs +++ b/gamenight-cli/src/flows/mod.rs @@ -1,5 +1,6 @@ +use gamenight_api_client_rs::apis::default_api::{DefaultApi, DefaultApiClient}; use std::{fmt::Display, num::ParseIntError}; - +use std::sync::{Arc, MutexGuard, PoisonError}; use async_trait::async_trait; use chrono::ParseError; use gamenight_api_client_rs::apis::{configuration::Configuration, Error}; @@ -38,10 +39,12 @@ mod location_authorize; mod remove_game; pub struct GamenightState { - api_configuration: Configuration, + api_configuration: Arc, + api: Box, gamenight_configuration: Config, } + #[derive(Debug, Serialize, Deserialize)] pub struct Claims { exp: i64, @@ -50,8 +53,10 @@ pub struct Claims { impl GamenightState { pub fn new() -> Self{ + let config = Arc::new(Configuration::new()); Self { - api_configuration: Configuration::new(), + api_configuration: config.clone(), + api: Box::new(DefaultApiClient::new(config.clone())), gamenight_configuration: Config::new() } } @@ -67,6 +72,22 @@ impl GamenightState { Ok(claims.uid) } + + pub fn set_bearer_access_token(&mut self, token: Option) -> &mut Self { + let mut config : Configuration = Arc::::into_inner(self.api_configuration.clone()).unwrap_or(Configuration::new()); + config.bearer_access_token = token; + self.api_configuration = Arc::from(config); + self.api = Box::new(DefaultApiClient::new(self.api_configuration.clone())); + self + } + + pub fn set_api_base_path(&mut self, base_path: String) -> &mut Self { + let mut config : Configuration = Arc::::into_inner(self.api_configuration.clone()).unwrap_or(Configuration::new()); + config.base_path = base_path; + self.api_configuration = Arc::from(config); + self.api = Box::new(DefaultApiClient::new(self.api_configuration.clone())); + self + } } impl Default for GamenightState { @@ -136,6 +157,30 @@ impl From for FlowError { } } +impl From> for FlowError { + fn from(value: PoisonError<&mut Configuration>) -> Self { + Self { + error: value.to_string() + } + } +} + +impl From> for FlowError { + fn from(value: PoisonError) -> Self { + Self { + error: value.to_string() + } + } +} + +impl From>> for FlowError { + fn from(value: PoisonError>) -> Self { + Self { + error: value.to_string() + } + } +} + #[derive(PartialEq)] pub enum FlowOutcome { Successful, diff --git a/gamenight-cli/src/flows/own.rs b/gamenight-cli/src/flows/own.rs index b25db0b..b80aa0b 100644 --- a/gamenight-cli/src/flows/own.rs +++ b/gamenight-cli/src/flows/own.rs @@ -3,9 +3,7 @@ use std::fmt::Display; use super::{Flow, FlowError, FlowOutcome, FlowResult, GamenightState}; use crate::domain::location_select_data::LocationSelectData; use async_trait::async_trait; -use gamenight_api_client_rs::apis::default_api::locations_get; use gamenight_api_client_rs::models::OwnGameRequestBody; -use gamenight_api_client_rs::apis::default_api::own_post; use inquire::{Confirm, Select}; use uuid::Uuid; @@ -35,13 +33,13 @@ impl<'a> Flow<'a> for Own { if owned { if let Some(willing_to_travel) = Confirm::new("Are you willing to travel with this game?").prompt_skippable()? { if !willing_to_travel { - let locations = locations_get(&state.api_configuration).await?.iter().map(|x| { x.try_into() }).collect::, FlowError>>()?; + let locations = state.api.locations_get().await?.iter().map(|x| { x.try_into() }).collect::, FlowError>>()?; if let Some(location) = Select::new("What location can this game be played?", locations).prompt_skippable()? { own_game_request.location_id = Some(location.id.to_string()); } } } - let _ = own_post(&state.api_configuration, Some(own_game_request)).await?; + let _ = state.api.own_post(Some(own_game_request)).await?; } } diff --git a/gamenight-cli/src/flows/remove_game.rs b/gamenight-cli/src/flows/remove_game.rs index 63bd1a9..72205cd 100644 --- a/gamenight-cli/src/flows/remove_game.rs +++ b/gamenight-cli/src/flows/remove_game.rs @@ -25,7 +25,7 @@ impl<'a> Flow<'a> for RemoveGame { let req = GameId { game_id: self.game.id.to_string() }; - gamenight_api_client_rs::apis::default_api::game_delete(&state.api_configuration, Some(req)).await?; + state.api.game_delete(Some(req)).await?; //Hack to return to right stack item, skipping detail view that doesn't exist. Ok((FlowOutcome::Abort, state)) } diff --git a/gamenight-cli/src/flows/rename_game.rs b/gamenight-cli/src/flows/rename_game.rs index 813ad76..3da8b04 100644 --- a/gamenight-cli/src/flows/rename_game.rs +++ b/gamenight-cli/src/flows/rename_game.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use async_trait::async_trait; -use gamenight_api_client_rs::{apis::default_api::rename_game_post, models::RenameGameRequestBody}; +use gamenight_api_client_rs::models::RenameGameRequestBody; use inquire::Text; use crate::domain::game::Game; @@ -32,7 +32,7 @@ impl<'a> Flow<'a> for RenameGame { id: self.game.id.to_string(), name }; - rename_game_post(&state.api_configuration, Some(req)).await?; + state.api.rename_game_post(Some(req)).await?; return Ok((FlowOutcome::Successful, state)) } diff --git a/gamenight-cli/src/flows/view_game.rs b/gamenight-cli/src/flows/view_game.rs index cbdff29..9451007 100644 --- a/gamenight-cli/src/flows/view_game.rs +++ b/gamenight-cli/src/flows/view_game.rs @@ -1,5 +1,5 @@ -use gamenight_api_client_rs::{apis::default_api::{game_get, owned_games_get}, models::{GameId, UserId}}; +use gamenight_api_client_rs::models::{GameId, UserId}; use inquire::Select; use uuid::Uuid; @@ -24,15 +24,15 @@ impl ViewGame { impl<'a> Flow<'a> for ViewGame { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { let game_id = GameId{ game_id: self.game.id.to_string() }; - let game: Game = game_get(&state.api_configuration, Some(game_id)).await?.into(); + let game: Game = state.api.game_get(Some(game_id)).await?.into(); println!("{}", game); let my_uid = state.get_user_id()?; let request = UserId{ user_id: my_uid.to_string() }; - let owned_games: Vec = owned_games_get(&state.api_configuration, Some(request)).await? + let owned_games: Vec = state.api.owned_games_get(Some(request)).await? .iter().map(|x| -> Result { - Ok(Uuid::parse_str(x)?) + Ok(Uuid::parse_str(&x.game_id)?) }).collect::, FlowError>>()?; let own_or_disown: Box + Send> = diff --git a/gamenight-cli/src/flows/view_gamenight.rs b/gamenight-cli/src/flows/view_gamenight.rs index 07e0d16..90ae61e 100644 --- a/gamenight-cli/src/flows/view_gamenight.rs +++ b/gamenight-cli/src/flows/view_gamenight.rs @@ -1,13 +1,11 @@ use crate::domain::gamenight::Gamenight; use std::collections::HashMap; -use futures::future::join_all; -use gamenight_api_client_rs::{apis::default_api::{game_get, owned_games_get, participants_get, user_get, GameGetError}, models::{self, GameId, GamenightId, UserId}}; +use gamenight_api_client_rs::models::{GameId, GamenightId, LocationId, OwnedGame, UserId}; use inquire::Select; -use crate::{domain::{game::Game, gamenight_select_data::GamenightSelectData, owned_games::OwnedGames, participants::Participants}, flows::{exit::Exit, join::Join, leave::Leave}}; - use super::*; +use crate::{domain::{gamenight_select_data::GamenightSelectData, owned_games::OwnedGames, participants::Participants}, flows::{exit::Exit, join::Join, leave::Leave}}; #[derive(Clone)] pub struct ViewGamenight { @@ -30,25 +28,35 @@ impl<'a> Flow<'a> for ViewGamenight { id: self.gamenight_select_data.id, start_time: self.gamenight_select_data.start_time, name: self.gamenight_select_data.name.clone(), - organizer: user_get(&state.api_configuration, Some(UserId{user_id: self.gamenight_select_data.owner_id.to_string()})).await?.try_into()?, + location: None, + organizer: state.api.user_get(Some(UserId{user_id: self.gamenight_select_data.owner_id.to_string()})).await?.try_into()?, participants: Participants(vec![]), owned_games: OwnedGames(HashMap::new()) }; - let participants = participants_get(&state.api_configuration, Some(GamenightId{gamenight_id: gamenight.id.to_string()})).await?; + gamenight.location = match self.gamenight_select_data.location_id { + None => None, + Some(l) => Some(state.api.location_get(Some(LocationId{location_id: l.to_string()})).await?.try_into()?) + }; + let participants = state.api.participants_get(Some(GamenightId{gamenight_id: gamenight.id.to_string()})).await?; for participant in participants.participants.iter() { - gamenight.participants.0.push(user_get(&state.api_configuration, Some(UserId{user_id: participant.clone()})).await?.try_into()?); + gamenight.participants.0.push(state.api.user_get(Some(UserId{user_id: participant.clone()})).await?.try_into()?); } for user in &gamenight.participants.0 { let request = UserId{ user_id: user.id.to_string() }; - let games: Vec = join_all(owned_games_get(&state.api_configuration, Some(request)).await? - .iter().map(async |game_id| -> Result> { - let request = GameId{ game_id: game_id.clone() }; - game_get(&state.api_configuration, Some(request)).await - })).await.into_iter().collect::, Error>>()?.into_iter().map(Into::into).collect(); - gamenight.owned_games.0.insert(user.username.clone(), games); + let owned_games_refs: Vec = state.api.owned_games_get(Some(request)).await?; + let mut owned_games = vec![]; + for owned_games_ref in owned_games_refs { + let game = state.api.game_get(Some(GameId{ game_id: owned_games_ref.game_id.clone()})).await?.into(); + let location = match owned_games_ref.location_id { + None => None, + Some(x) => Some(state.api.location_get(Some(LocationId{location_id: x})).await?.try_into()?) + }; + owned_games.push((game, location)); + } + gamenight.owned_games.0.insert(user.username.clone(), owned_games); } println!("{}", gamenight); diff --git a/gamenight-cli/src/main.rs b/gamenight-cli/src/main.rs index 6bfbe32..6af50f9 100644 --- a/gamenight-cli/src/main.rs +++ b/gamenight-cli/src/main.rs @@ -6,9 +6,9 @@ use flows::{main::Main, Flow, GamenightState}; #[tokio::main] async fn main() { let mut state = GamenightState::new(); - let mainflow = Main::new(); + let main_flow = Main::new(); clear_screen::clear(); - if let Err(x) = mainflow.run(&mut state).await { + if let Err(x) = main_flow.run(&mut state).await { println!("{}", x.error); } } diff --git a/gamenight-database/src/owned_game.rs b/gamenight-database/src/owned_game.rs index dc40b83..a76925d 100644 --- a/gamenight-database/src/owned_game.rs +++ b/gamenight-database/src/owned_game.rs @@ -33,9 +33,9 @@ pub fn disown_game(conn: &mut PgConnection, owned_game: OwnedGame) -> Result Result, DatabaseError> { +pub fn owned_games(conn: &mut PgConnection, uuid: Uuid) -> Result)>, DatabaseError> { Ok(owned_game::table - .select(owned_game::game_id) + .select((owned_game::game_id, owned_game::location_id)) .filter(owned_game::user_id.eq(uuid)) .get_results(conn)?) }