From 9d3c5afb07ffa7152f38c6bd20f85da2e735c6d7 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Thu, 22 Jan 2026 22:51:03 +0100 Subject: [PATCH] Converted the Api to a Restful api. --- backend-actix/gamenight-api.yaml | 512 +++--- backend-actix/src/main.rs | 52 +- backend-actix/src/request/game.rs | 143 +- backend-actix/src/request/game_owner.rs | 26 + backend-actix/src/request/game_owners.rs | 27 + backend-actix/src/request/gamenight.rs | 32 + .../src/request/gamenight_participant.rs | 28 + .../src/request/gamenight_participants.rs | 54 + .../{gamenight_handlers.rs => gamenights.rs} | 52 +- backend-actix/src/request/games.rs | 54 + backend-actix/src/request/join_gamenight.rs | 55 - backend-actix/src/request/location.rs | 67 +- .../src/request/location_authorized_user.rs | 23 + .../src/request/location_authorized_users.rs | 60 + backend-actix/src/request/location_owner.rs | 79 - backend-actix/src/request/locations.rs | 62 + backend-actix/src/request/mod.rs | 48 +- .../src/request/participant_handlers.rs | 31 - backend-actix/src/request/token.rs | 54 + backend-actix/src/request/user.rs | 37 + backend-actix/src/request/user_owned_games.rs | 28 + .../request/{user_handlers.rs => users.rs} | 138 +- .../.openapi-generator/FILES | 12 +- gamenight-api-client-rs/README.md | 53 +- gamenight-api-client-rs/docs/DefaultApi.md | 754 ++++----- .../docs/EditGameRequestBody.md | 12 + gamenight-api-client-rs/docs/OwnGame.md | 12 + gamenight-api-client-rs/docs/OwnedGame.md | 1 + .../src/apis/default_api.rs | 1432 +++++++++-------- .../src/models/edit_game_request_body.rs | 30 + gamenight-api-client-rs/src/models/mod.rs | 12 +- .../src/models/own_game.rs | 30 + .../src/models/owned_game.rs | 5 +- gamenight-cli/src/flows/add_game.rs | 2 +- gamenight-cli/src/flows/add_gamenight.rs | 2 +- gamenight-cli/src/flows/add_location.rs | 12 +- gamenight-cli/src/flows/connect.rs | 2 +- gamenight-cli/src/flows/disown.rs | 3 +- gamenight-cli/src/flows/join.rs | 4 +- gamenight-cli/src/flows/leave.rs | 3 +- gamenight-cli/src/flows/list_games.rs | 2 +- gamenight-cli/src/flows/list_locations.rs | 2 +- gamenight-cli/src/flows/location_authorize.rs | 27 +- gamenight-cli/src/flows/login.rs | 2 +- gamenight-cli/src/flows/own.rs | 10 +- gamenight-cli/src/flows/remove_game.rs | 6 +- gamenight-cli/src/flows/rename_game.rs | 6 +- gamenight-cli/src/flows/view_game.rs | 14 +- gamenight-cli/src/flows/view_gamenight.rs | 17 +- gamenight-database/src/owned_game.rs | 4 +- 50 files changed, 2194 insertions(+), 1939 deletions(-) create mode 100644 backend-actix/src/request/game_owner.rs create mode 100644 backend-actix/src/request/game_owners.rs create mode 100644 backend-actix/src/request/gamenight.rs create mode 100644 backend-actix/src/request/gamenight_participant.rs create mode 100644 backend-actix/src/request/gamenight_participants.rs rename backend-actix/src/request/{gamenight_handlers.rs => gamenights.rs} (55%) create mode 100644 backend-actix/src/request/games.rs delete mode 100644 backend-actix/src/request/join_gamenight.rs create mode 100644 backend-actix/src/request/location_authorized_user.rs create mode 100644 backend-actix/src/request/location_authorized_users.rs delete mode 100644 backend-actix/src/request/location_owner.rs create mode 100644 backend-actix/src/request/locations.rs delete mode 100644 backend-actix/src/request/participant_handlers.rs create mode 100644 backend-actix/src/request/token.rs create mode 100644 backend-actix/src/request/user.rs create mode 100644 backend-actix/src/request/user_owned_games.rs rename backend-actix/src/request/{user_handlers.rs => users.rs} (54%) create mode 100644 gamenight-api-client-rs/docs/EditGameRequestBody.md create mode 100644 gamenight-api-client-rs/docs/OwnGame.md create mode 100644 gamenight-api-client-rs/src/models/edit_game_request_body.rs create mode 100644 gamenight-api-client-rs/src/models/own_game.rs diff --git a/backend-actix/gamenight-api.yaml b/backend-actix/gamenight-api.yaml index 7ff2946..9891bbd 100644 --- a/backend-actix/gamenight-api.yaml +++ b/backend-actix/gamenight-api.yaml @@ -14,9 +14,9 @@ servers: description: Gamenight paths: /token: - get: - summary: '' - operationId: get-token + post: + summary: 'Login a user.' + operationId: post-token responses: '200': $ref: '#/components/responses/TokenResponse' @@ -26,9 +26,10 @@ paths: $ref: '#/components/requestBodies/LoginRequest' description: Submit your credentials to get a JWT-token to use with the rest of the api. parameters: [] + /refresh_token: post: - summary: '' - operationId: post-token + summary: 'Refresh a user token' + operationId: post-refresh-token responses: '200': $ref: '#/components/responses/TokenResponse' @@ -40,6 +41,8 @@ paths: - JWT-Auth: [] /users: get: + summary: 'Get all users' + operationId: get-users responses: '200': $ref: '#/components/responses/UsersResponse' @@ -48,11 +51,10 @@ paths: '401': $ref: '#/components/responses/FailureResponse' security: - - JWT-Auth: [] - /user: + - JWT-Auth: [] post: - summary: '' - operationId: post-register + summary: 'Registers a user into gamenight.' + operationId: post-users requestBody: $ref: '#/components/requestBodies/RegisterRequest' responses: @@ -61,18 +63,24 @@ paths: '422': $ref: '#/components/responses/FailureResponse' description: 'Create a new user given a registration token and user information, username and email must be unique, and password and password_repeat must match.' - parameters: [] + parameters: [ ] security: - - JWT-Auth: [] + - JWT-Auth: [ ] + /user/{userId}: get: description: 'Get a user from primary id' - requestBody: - $ref: '#/components/requestBodies/GetUserRequest' - parameters: [] + operationId: 'get-user' + parameters: + - in: path + name: userId + schema: + type: string + required: true + description: Uuid of user to get responses: '200': $ref: '#/components/responses/UserResponse' - '401': + '401': $ref: '#/components/responses/FailureResponse' '404': $ref: '#/components/responses/FailureResponse' @@ -80,9 +88,30 @@ paths: $ref: '#/components/responses/FailureResponse' security: - JWT-Auth: [] + /user/{userId}/owned_games: + get: + summary: Get owned games of user + operationId: get-user-owned_games + parameters: + - in: path + name: userId + schema: + type: string + required: true + description: Uuid of user to get owned games for. + responses: + '200': + $ref: '#/components/responses/OwnedGamesResponse' + '401': + $ref: '#/components/responses/FailureResponse' + '422': + $ref: '#/components/responses/FailureResponse' + security: + - JWT-Auth: [ ] /gamenights: get: summary: Get a all gamenights + operationId: get-gamenights responses: '200': $ref: '#/components/responses/GamenightsResponse' @@ -90,29 +119,12 @@ paths: $ref: '#/components/responses/FailureResponse' '401': $ref: '#/components/responses/FailureResponse' - operationId: get-gamenights security: - JWT-Auth: [] description: Retrieve the list of gamenights on this gamenight server. Requires authorization. - /participants: - get: - summary: Get all participants for a gamenight - responses: - '200': - $ref: '#/components/responses/ParticipantsResponse' - '400': - $ref: '#/components/responses/FailureResponse' - '401': - $ref: '#/components/responses/FailureResponse' - requestBody: - $ref: '#/components/requestBodies/GetParticipants' - security: - - JWT-Auth: [] - description: Retrieve the participants of a single gamenight by id. - /gamenight: post: - summary: '' - operationId: post-gamenight + summary: 'Gets the gamenight' + operationId: post-gamenights responses: '200': description: OK @@ -121,13 +133,21 @@ paths: '422': $ref: '#/components/responses/FailureResponse' security: - - JWT-Auth: [] + - JWT-Auth: [ ] requestBody: $ref: '#/components/requestBodies/AddGamenight' description: 'Add a gamenight by providing a name and a date, only available when providing an JWT token.' + /gamenight/{gamenightId}: get: - summary: '' + summary: 'get the specified gamenight' operationId: get-gamenight + parameters: + - in: path + name: gamenightId + schema: + type: string + required: true + description: Uuid of gamenight to get. responses: '200': $ref: '#/components/responses/GamenightResponse' @@ -135,12 +155,39 @@ paths: $ref: '#/components/responses/FailureResponse' '422': $ref: '#/components/responses/FailureResponse' - requestBody: - $ref: '#/components/requestBodies/GetGamenight' security: - JWT-Auth: [] - /join: + /gamenight/{gamenightId}/participants: + get: + summary: Get all participants for a gamenight + operationId: get-gamenight-participants + parameters: + - in: path + name: gamenightId + schema: + type: string + required: true + description: Uuid of gamenight to get participants for. + responses: + '200': + $ref: '#/components/responses/ParticipantsResponse' + '400': + $ref: '#/components/responses/FailureResponse' + '401': + $ref: '#/components/responses/FailureResponse' + security: + - JWT-Auth: [ ] + description: Retrieve the participants of a single gamenight by id. post: + summary: Add a participant + operationId: post-gamenight-participants + parameters: + - in: path + name: gamenightId + schema: + type: string + required: true + description: Uuid of gamenight to add participants for. responses: '200': description: OK @@ -149,11 +196,26 @@ paths: '422': $ref: '#/components/responses/FailureResponse' requestBody: - $ref: '#/components/requestBodies/JoinGamenight' + $ref: '#/components/requestBodies/UserIdRequestBody' security: - JWT-Auth: [] - /leave: - post: + /gamenight/{gamenightId}/participant/{userId}: + delete: + summary: deletes a gamenight participant + operationId: delete-gamenight-participant + parameters: + - in: path + name: gamenightId + schema: + type: string + required: true + description: Uuid of gamenight to delete participant for + - in: path + name: userId + schema: + type: string + required: true + description: Uuid of the of the participant to remove responses: '200': description: "OK" @@ -161,12 +223,12 @@ paths: $ref: '#/components/responses/FailureResponse' '422': $ref: '#/components/responses/FailureResponse' - requestBody: - $ref: '#/components/requestBodies/LeaveGamenight' security: - - JWT-Auth: [] + - JWT-Auth: [ ] /games: get: + summary: get all games + operationId: get-games responses: '200': $ref: '#/components/responses/GamesResponse' @@ -176,21 +238,10 @@ paths: $ref: '#/components/responses/FailureResponse' security: - JWT-Auth: [] - /game: - get: - responses: - '200': - $ref: '#/components/responses/GameResponse' - '401': - $ref: '#/components/responses/FailureResponse' - '422': - $ref: '#/components/responses/FailureResponse' - requestBody: - $ref: '#/components/requestBodies/GetGameRequest' - security: - - JWT-Auth: [] post: - responses: + summary: add a game + operationId: post-games + responses: '200': $ref: '#/components/responses/GameIdResponse' '401': @@ -199,9 +250,38 @@ paths: $ref: '#/components/responses/FailureResponse' requestBody: $ref: '#/components/requestBodies/AddGameRequest' + security: + - JWT-Auth: [ ] + /game/{gameId}: + get: + summary: Get this specific game + operationId: get-game + parameters: + - in: path + name: gameId + schema: + type: string + required: true + description: Uuid of game to get. + responses: + '200': + $ref: '#/components/responses/GameResponse' + '401': + $ref: '#/components/responses/FailureResponse' + '422': + $ref: '#/components/responses/FailureResponse' security: - JWT-Auth: [] delete: + summary: Delete this game. + operationId: delete-game + parameters: + - in: path + name: gameId + schema: + type: string + required: true + description: Uuid of game to delete. responses: '200': description: "Ok" @@ -209,12 +289,18 @@ paths: $ref: '#/components/responses/FailureResponse' '422': $ref: '#/components/responses/FailureResponse' - requestBody: - $ref: '#/components/requestBodies/RemoveGameRequest' security: - JWT-Auth: [ ] - /rename_game: - post: + put: + summary: Changes this game resource + operationId: put-game + parameters: + - in: path + name: gameId + schema: + type: string + required: true + description: Uuid of game to change. responses: '200': description: "OK" @@ -223,62 +309,73 @@ paths: '422': $ref: '#/components/responses/FailureResponse' requestBody: - $ref: '#/components/requestBodies/RenameGameRequest' + $ref: '#/components/requestBodies/EditGameRequest' security: - JWT-Auth: [] - /own: + /game/{gameId}/owners: post: - responses: - '200': - description: "OK" - '401': - $ref: '#/components/responses/FailureResponse' - '422': - $ref: '#/components/responses/FailureResponse' + summary: Own this game + operationId: post-game-owners + parameters: + - in: path + name: gameId + schema: + type: string + required: true + description: Uuid of game to own. requestBody: - $ref: '#/components/requestBodies/OwnGameRequest' - security: - - JWT-Auth: [] - /disown: - post: - responses: - '200': - description: "OK" - '401': - $ref: '#/components/responses/FailureResponse' - '422': - $ref: '#/components/responses/FailureResponse' - requestBody: - $ref: '#/components/requestBodies/DisownGameRequest' - security: - - JWT-Auth: [] - /owned_games: - get: - responses: - '200': - $ref: "#/components/responses/GameIdsResponse" - '401': - $ref: '#/components/responses/FailureResponse' - '422': - $ref: '#/components/responses/FailureResponse' - requestBody: - $ref: '#/components/requestBodies/OwnedGamesRequest' - security: - - JWT-Auth: [] - /location: - get: + $ref: '#/components/requestBodies/OwnGameRequestBody' responses: '200': - $ref: '#/components/responses/LocationResponse' + description: "OK" '401': $ref: '#/components/responses/FailureResponse' '422': $ref: '#/components/responses/FailureResponse' - requestBody: - $ref: '#/components/requestBodies/GetLocationRequest' security: - JWT-Auth: [] + /game/{gameId}/owner/{userId}: + delete: + summary: no longer own this game + operationId: delete-game-owner + parameters: + - in: path + name: gameId + schema: + type: string + required: true + description: Uuid of game that user no longer owns. + - in: path + name: userId + schema: + type: string + required: true + description: Uuid of user that no longer owns. + responses: + '200': + description: "OK" + '401': + $ref: '#/components/responses/FailureResponse' + '422': + $ref: '#/components/responses/FailureResponse' + security: + - JWT-Auth: [] + /locations: + get: + summary: get all locations + operationId: get-locations + responses: + '200': + $ref: '#/components/responses/LocationsResponse' + '401': + $ref: '#/components/responses/FailureResponse' + '422': + $ref: '#/components/responses/FailureResponse' + security: + - JWT-Auth: [ ] post: + summary: add a location + operationId: post-locations responses: '200': $ref: '#/components/responses/LocationIdResponse' @@ -289,20 +386,57 @@ paths: requestBody: $ref: '#/components/requestBodies/AddLocationRequest' security: - - JWT-Auth: [] - /locations: + - JWT-Auth: [ ] + /location/{locationId}: get: + summary: gets this location + operationId: get-location + parameters: + - in: path + name: locationId + schema: + type: string + required: true + description: Uuid of location to get. responses: '200': - $ref: '#/components/responses/LocationsResponse' + $ref: '#/components/responses/LocationResponse' '401': $ref: '#/components/responses/FailureResponse' '422': $ref: '#/components/responses/FailureResponse' security: - JWT-Auth: [] - /location_authorize: + /location/{locationId}/authorized_users/: + get: + summary: gets this locations authorized users + operationId: get-location-authorized_users + parameters: + - in: path + name: locationId + schema: + type: string + required: true + description: Uuid of location to get authorized users for. + responses: + '200': + $ref: "#/components/responses/UserIdsResponse" + '401': + $ref: '#/components/responses/FailureResponse' + '422': + $ref: '#/components/responses/FailureResponse' + security: + - JWT-Auth: [ ] post: + summary: Authorize a user + operationId: post-location-authorized_users + parameters: + - in: path + name: locationId + schema: + type: string + required: true + description: Uuid location to authorize for. responses: '200': description: 'Ok' @@ -311,22 +445,36 @@ paths: '422': $ref: '#/components/responses/FailureResponse' requestBody: - $ref: '#/components/requestBodies/AuthorizeLocationRequest' + $ref: '#/components/requestBodies/UserIdRequestBody' security: - JWT-Auth: [] - /authorized_location_user_ids: - get: - responses: + /location/{locationId}/authorized_user/{userId}: + delete: + summary: remove an authorized user from a location + operationId: delete-location-authorized_user + parameters: + - in: path + name: locationId + schema: + type: string + required: true + description: Uuid of location to deauthorize for. + - in: path + name: userId + schema: + type: string + required: true + description: Uuid of user ot deauthorize. + responses: '200': - $ref: "#/components/responses/UserIdsResponse" + description: 'Ok' '401': $ref: '#/components/responses/FailureResponse' '422': $ref: '#/components/responses/FailureResponse' - requestBody: - $ref: '#/components/requestBodies/AuthorizedLocationUserIdsRequest' security: - - JWT-Auth: [] + - JWT-Auth: [ ] + components: schemas: Gamenight: @@ -410,15 +558,28 @@ components: type: string required: - user_id + OwnGame: + title: OwnGame + type: object + properties: + user_id: + type: string + location_id: + type: string + required: + - user_id OwnedGame: title: OwnedGame type: object properties: + user_id: + type: string game_id: type: string location_id: type: string required: + - user_id - game_id LocationId: title: LocationId @@ -455,11 +616,6 @@ components: type: string required: - game_id - GetGamenightRequestBody: - type: object - properties: - id: - type: string User: type: object properties: @@ -489,7 +645,7 @@ components: type: string required: - name - RenameGameRequestBody: + EditGameRequestBody: type: object properties: id: @@ -499,19 +655,10 @@ components: required: - id - name - OwnGameRequestBody: - type: object - properties: - game_id: - type: string - location_id: - type: string - required: - - game_id GameIdsResponse: type: array items: - $ref: "#/components/schemas/OwnedGame" + $ref: "#/components/schemas/GameId" UserIdsResponse: type: array items: @@ -541,21 +688,17 @@ components: required: - id - name - AuthorizeLocationRequestBody: - type: object - properties: - location_id: - type: string - user_id: - type: string - op: - type: string - enum: [grant, revoke] - required: - - location_id - - user_id - - op requestBodies: + UserIdRequestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/UserId' + OwnGameRequestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/OwnGame' LoginRequest: content: application/json: @@ -566,91 +709,31 @@ components: application/json: schema: $ref: '#/components/schemas/Registration' - GetUserRequest: - content: - application/json: - schema: - $ref: '#/components/schemas/UserId' AddGamenight: content: application/json: schema: $ref: '#/components/schemas/AddGamenightRequestBody' - GetGamenight: - content: - application/json: - schema: - $ref: '#/components/schemas/GetGamenightRequestBody' GetParticipants: content: application/json: schema: $ref: '#/components/schemas/GamenightId' - JoinGamenight: - content: - application/json: - schema: - $ref: '#/components/schemas/GamenightId' - LeaveGamenight: - content: - application/json: - schema: - $ref: '#/components/schemas/GamenightId' - GetGameRequest: - content: - application/json: - schema: - $ref: '#/components/schemas/GameId' AddGameRequest: content: application/json: schema: $ref: '#/components/schemas/AddGameRequestBody' - RenameGameRequest: + EditGameRequest: content: application/json: schema: - $ref: '#/components/schemas/RenameGameRequestBody' - RemoveGameRequest: - content: - application/json: - schema: - $ref: '#/components/schemas/GameId' - OwnGameRequest: - content: - application/json: - schema: - $ref: '#/components/schemas/OwnGameRequestBody' - DisownGameRequest: - content: - application/json: - schema: - $ref: '#/components/schemas/GameId' - OwnedGamesRequest: - content: - application/json: - schema: - $ref: '#/components/schemas/UserId' - GetLocationRequest: - content: - application/json: - schema: - $ref: '#/components/schemas/LocationId' + $ref: '#/components/schemas/EditGameRequestBody' AddLocationRequest: content: application/json: schema: $ref: '#/components/schemas/AddLocationRequestBody' - AuthorizeLocationRequest: - content: - application/json: - schema: - $ref: '#/components/schemas/AuthorizeLocationRequestBody' - AuthorizedLocationUserIdsRequest: - content: - application/json: - schema: - $ref: '#/components/schemas/LocationId' responses: TokenResponse: @@ -743,7 +826,6 @@ components: application/json: schema: $ref: '#/components/schemas/LocationId' - LocationsResponse: description: A list of all LocationsResponse content: @@ -752,6 +834,14 @@ components: type: array items: $ref: '#/components/schemas/Location' + OwnedGamesResponse: + description: A list of OwnedGames + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/OwnedGame' securitySchemes: JWT-Auth: diff --git a/backend-actix/src/main.rs b/backend-actix/src/main.rs index 4da5319..5b1c3d0 100644 --- a/backend-actix/src/main.rs +++ b/backend-actix/src/main.rs @@ -8,8 +8,8 @@ use actix_web::middleware::Logger; use actix_web::web; use actix_web::App; use actix_web::HttpServer; -use gamenight_database::*; -use request::{gamenights, login, register, *}; +use gamenight_database::{get_connection_pool, run_migration, GetConnection}; +use request::*; use tracing_actix_web::TracingLogger; #[actix_web::main] @@ -37,30 +37,30 @@ async fn main() -> std::io::Result<()> { .wrap(Logger::default()) .wrap(TracingLogger::default()) .app_data(web::Data::new(pool.clone())) - .service(login) - .service(refresh) - .service(register) - .service(gamenights) - .service(gamenight_post) - .service(gamenight_get) - .service(get_user) - .service(get_users) - .service(get_user_unauthenticated) - .service(post_join_gamenight) - .service(post_leave_gamenight) - .service(get_get_participants) - .service(get_games) - .service(get_game) - .service(post_game) - .service(post_rename_game) - .service(post_own_game) - .service(post_disown_game) - .service(get_owned_games) - .service(delete_game) - .service(get_locations) - .service(post_location) - .service(post_location_authorize) - .service(get_authorized_location_user_ids) + .service(token::post_token) + .service(token::post_refresh_token) + .service(users::get_users) + .service(users::post_users) + .service(user::get_user) + .service(user_owned_games::get_user_owned_games) + .service(gamenights::get_gamenights) + .service(gamenights::post_gamenights) + .service(gamenight::get_gamenight) + .service(gamenight_participants::get_gamenight_participants) + .service(gamenight_participants::post_gamenight_participants) + .service(gamenight_participant::delete_gamenight_participant) + .service(games::get_games) + .service(games::post_games) + .service(game::get_game) + .service(game::delete_game) + .service(game::put_game) + .service(game_owners::post_game_owners) + .service(game_owner::delete_game_owner) + .service(locations::get_locations) + .service(locations::post_locations) + .service(location_authorized_users::get_location_authorized_users) + .service(location_authorized_users::post_location_authorized_users) + .service(location_authorized_user::delete_location_authorized_user) }) .bind(("::1", 8080))? .run() diff --git a/backend-actix/src/request/game.rs b/backend-actix/src/request/game.rs index ddf814c..f57d69e 100644 --- a/backend-actix/src/request/game.rs +++ b/backend-actix/src/request/game.rs @@ -1,60 +1,24 @@ -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 gamenight_database::game::load_game; -use crate::game::insert_game; -use uuid::Uuid; -use crate::game::remove_game; -use actix_web::{delete, get, http::header::ContentType, post, web, HttpResponse, Responder}; +use actix_web::{delete, get, http::header::ContentType, put, web, HttpResponse, Responder}; +use gamenight_database::game::{load_game, remove_game, rename_game}; use gamenight_database::{ user::Role, DbPool, GetConnection, }; +use uuid::Uuid; -use crate::{models, models::{ - add_game_request_body::AddGameRequestBody, game::Game, game_id::GameId, - rename_game_request_body::RenameGameRequestBody, own_game_request_body::OwnGameRequestBody +use crate::{models::{ + edit_game_request_body::EditGameRequestBody, game::Game + , }, request::{authorization::AuthUser, error::ApiError}}; -#[get("/games")] -pub async fn get_games( - pool: web::Data, - _user: AuthUser, -) -> Result { - let mut conn = pool.get_conn(); - let games: Vec = gamenight_database::games(&mut conn)?; - let model: Vec = games - .iter() - .map(|x| Game { - id: x.id.to_string(), - name: x.name.clone(), - }) - .collect(); - - Ok(HttpResponse::Ok() - .content_type(ContentType::json()) - .body(serde_json::to_string(&model)?)) -} - -impl From for gamenight_database::game::Game { - fn from(value: AddGameRequestBody) -> Self { - Self { - id: Uuid::new_v4(), - name: value.name, - } - } -} - -#[get("/game")] +#[get("/game/{game_id}")] pub async fn get_game( pool: web::Data, _user: AuthUser, - game_id: web::Json, + game_id: web::Path ) -> Result { let mut conn = pool.get_conn(); - let db_game = load_game(&mut conn, Uuid::parse_str(&game_id.0.game_id)?)?; + let db_game = load_game(&mut conn, game_id.into_inner())?; let model = Game { id: db_game.id.to_string(), @@ -66,106 +30,35 @@ pub async fn get_game( .body(serde_json::to_string(&model)?)) } -#[post("/game")] -pub async fn post_game( - pool: web::Data, - _user: AuthUser, - game_data: web::Json, -) -> Result { - let mut conn = pool.get_conn(); - let game = game_data.0.into(); - insert_game(&mut conn, &game)?; - - Ok(HttpResponse::Ok() - .content_type(ContentType::json()) - .body(serde_json::to_string(&GameId{game_id: game.id.to_string()})?)) -} - -#[delete("/game")] +#[delete("/game/{game_id}")] pub async fn delete_game( pool: web::Data, user: AuthUser, - game_id: web::Json, + game_id: web::Path, ) -> Result { if user.0.role != Role::Admin { Ok(HttpResponse::Unauthorized()) } else { let mut conn = pool.get_conn(); - remove_game(&mut conn, Uuid::parse_str(&game_id.0.game_id)?)?; + remove_game(&mut conn, game_id.into_inner())?; Ok(HttpResponse::Ok()) } } -#[post("/rename_game")] -pub async fn post_rename_game( +#[put("/game/{gameId}")] +pub async fn put_game( pool: web::Data, _user: AuthUser, - game_data: web::Json, + game_id: web::Path, + edit_data: web::Json, ) -> Result { let mut conn = pool.get_conn(); rename_game( &mut conn, - Uuid::parse_str(&game_data.0.id)?, - game_data.0.name, + game_id.into_inner(), + edit_data.name.clone(), )?; Ok(HttpResponse::Ok()) } - -#[post("/own")] -pub async fn post_own_game( - pool: web::Data, - user: AuthUser, - own_data: web::Json, -) -> Result { - let mut conn = pool.get_conn(); - own_game( - &mut conn, - OwnedGame { - user_id: user.0.id, - game_id: Uuid::parse_str(&own_data.game_id)?, - location_id: own_data.location_id.clone().map(|x| Uuid::parse_str(&x).unwrap()), - }, - )?; - - Ok(HttpResponse::Ok()) -} - -#[post("/disown")] -pub async fn post_disown_game( - pool: web::Data, - user: AuthUser, - game_id: web::Json, -) -> Result { - let mut conn = pool.get_conn(); - disown_game( - &mut conn, - OwnedGame { - user_id: user.0.id, - game_id: Uuid::parse_str(&game_id.0.game_id)?, - location_id: None - }, - )?; - - Ok(HttpResponse::Ok()) -} - -#[get("/owned_games")] -pub async fn get_owned_games( - pool: web::Data, - user: AuthUser, -) -> Result { - let mut conn = pool.get_conn(); - let game_ids = owned_games(&mut conn, user.0.id)?; - - - 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()) - .body(serde_json::to_string(&model)?)) -} diff --git a/backend-actix/src/request/game_owner.rs b/backend-actix/src/request/game_owner.rs new file mode 100644 index 0000000..e666819 --- /dev/null +++ b/backend-actix/src/request/game_owner.rs @@ -0,0 +1,26 @@ +use crate::request::authorization::AuthUser; +use crate::request::error::ApiError; +use actix_web::{delete, web, HttpResponse, Responder}; +use gamenight_database::owned_game::{disown_game, OwnedGame}; +use gamenight_database::{DbPool, GetConnection}; +use uuid::Uuid; + +#[delete("/game/{gameId}/owner/{ownerId}")] +pub async fn delete_game_owner( + pool: web::Data, + _user: AuthUser, + game_id: web::Path, + owner_id: web::Path, +) -> Result { + let mut conn = pool.get_conn(); + disown_game( + &mut conn, + OwnedGame { + user_id: owner_id.into_inner(), + game_id: game_id.into_inner(), + location_id: None + }, + )?; + + Ok(HttpResponse::Ok()) +} \ No newline at end of file diff --git a/backend-actix/src/request/game_owners.rs b/backend-actix/src/request/game_owners.rs new file mode 100644 index 0000000..27cdb55 --- /dev/null +++ b/backend-actix/src/request/game_owners.rs @@ -0,0 +1,27 @@ +use actix_web::{post, web, HttpResponse, Responder}; +use gamenight_database::{DbPool, GetConnection}; +use gamenight_database::owned_game::{own_game, OwnedGame}; +use uuid::Uuid; +use crate::models::game_id::GameId; +use crate::request::authorization::AuthUser; +use crate::request::error::ApiError; + +#[post("/game/{gameId}/owned_games")] +pub async fn post_game_owners( + pool: web::Data, + _user: AuthUser, + game_id: web::Path, + own_data: web::Json, +) -> Result { + let mut conn = pool.get_conn(); + own_game( + &mut conn, + OwnedGame { + user_id: own_data.user_id, + game_id: Uuid::parse_str(&game_id.game_id)?, + location_id: own_data.location_id, + }, + )?; + + Ok(HttpResponse::Ok()) +} \ No newline at end of file diff --git a/backend-actix/src/request/gamenight.rs b/backend-actix/src/request/gamenight.rs new file mode 100644 index 0000000..b4d89ad --- /dev/null +++ b/backend-actix/src/request/gamenight.rs @@ -0,0 +1,32 @@ +use actix_web::{get, http::header::ContentType, web, HttpResponse, Responder}; +use uuid::Uuid; + +use gamenight_database::{gamenight, DbPool, GetConnection}; + +use crate::models::gamenight_id::GamenightId; +use crate::request::error::ApiError; +use crate::{ + models::gamenight::Gamenight, + request::authorization::AuthUser, +}; + +#[get("/gamenight/{gamenightId}")] +pub async fn get_gamenight( + pool: web::Data, + _user: AuthUser, + path: web::Path +) -> Result { + let mut conn = pool.get_conn(); + let gamenight = gamenight::get_gamenight(&mut conn, Uuid::parse_str(&path.gamenight_id)?)?; + 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(), + }; + + Ok(HttpResponse::Ok() + .content_type(ContentType::json()) + .body(serde_json::to_string(&model)?)) +} diff --git a/backend-actix/src/request/gamenight_participant.rs b/backend-actix/src/request/gamenight_participant.rs new file mode 100644 index 0000000..5e064ce --- /dev/null +++ b/backend-actix/src/request/gamenight_participant.rs @@ -0,0 +1,28 @@ +use actix_web::{delete, web, HttpResponse, Responder}; +use gamenight_database::{DbPool, GetConnection}; +use gamenight_database::gamenight_participants::GamenightParticipant; +use uuid::Uuid; +use crate::request::authorization::AuthUser; +use crate::request::error::ApiError; + +#[delete("/gamenight/{gamenightId}/participant/{userId}")] +pub async fn delete_gamenight_participant( + pool: web::Data, + _user: AuthUser, + gamenight_id: web::Path, + user_id: web::Path +) -> Result { + web::block(move || -> Result { + let mut conn = pool.get_conn(); + let participant = GamenightParticipant { + gamenight_id: gamenight_id.into_inner(), + user_id: user_id.into_inner(), + }; + let x = gamenight_database::gamenight_participants::delete_gamenight_participant(&mut conn, participant)?; + + Ok(x) + }) + .await??; + + Ok(HttpResponse::Ok()) +} \ No newline at end of file diff --git a/backend-actix/src/request/gamenight_participants.rs b/backend-actix/src/request/gamenight_participants.rs new file mode 100644 index 0000000..e777792 --- /dev/null +++ b/backend-actix/src/request/gamenight_participants.rs @@ -0,0 +1,54 @@ +use crate::models::participants::Participants; +use crate::models::user_id::UserId; +use crate::request::authorization::AuthUser; +use crate::request::error::ApiError; +use actix_web::http::header::ContentType; +use actix_web::{get, post, web, HttpResponse, Responder}; +use gamenight_database::gamenight_participants::{insert_gamenight_participant, GamenightParticipant}; +use gamenight_database::{DbPool, GetConnection}; +use uuid::Uuid; + +#[get("/gamenight/{gamenightId}/participants")] +pub async fn get_gamenight_participants( + pool: web::Data, + _user: AuthUser, + gamenight_id: web::Path +) -> Result { + let mut conn = pool.get_conn(); + + let users = gamenight_database::get_participants( + &mut conn, + &gamenight_id.into_inner(), + )? + .iter() + .map(|x| x.to_string()) + .collect(); + + Ok(HttpResponse::Ok() + .content_type(ContentType::json()) + .body(serde_json::to_string(&Participants { + participants: users, + })?)) +} + +#[post("/gamenight/{gamenightId}/participants")] +pub async fn post_gamenight_participants( + pool: web::Data, + _user: AuthUser, + gamenight_id: web::Path, + user_id: web::Json, +) -> Result { + web::block(move || -> Result { + let mut conn = pool.get_conn(); + Ok(insert_gamenight_participant( + &mut conn, + GamenightParticipant { + gamenight_id: gamenight_id.into_inner(), + user_id: Uuid::parse_str(&user_id.user_id)?, + }, + )?) + }) + .await??; + + Ok(HttpResponse::Ok()) +} \ No newline at end of file diff --git a/backend-actix/src/request/gamenight_handlers.rs b/backend-actix/src/request/gamenights.rs similarity index 55% rename from backend-actix/src/request/gamenight_handlers.rs rename to backend-actix/src/request/gamenights.rs index 4540a43..66054f1 100644 --- a/backend-actix/src/request/gamenight_handlers.rs +++ b/backend-actix/src/request/gamenights.rs @@ -1,17 +1,12 @@ -use actix_web::{get, http::header::ContentType, post, web, HttpResponse, Responder}; +use actix_web::{get, post, web, HttpResponse, Responder}; +use actix_web::http::header::ContentType; use chrono::{DateTime, ParseError}; -use uuid::Uuid; - use gamenight_database::{gamenight, DbPool, GetConnection}; - +use uuid::Uuid; +use crate::models::add_gamenight_request_body::AddGamenightRequestBody; +use crate::models::gamenight::Gamenight; +use crate::request::authorization::AuthUser; use crate::request::error::ApiError; -use crate::{ - models::{ - add_gamenight_request_body::AddGamenightRequestBody, gamenight::Gamenight, - get_gamenight_request_body::GetGamenightRequestBody, - }, - request::authorization::AuthUser, -}; impl AddGamenightRequestBody { pub fn into_with_user(&self, user: AuthUser) -> Result { @@ -25,14 +20,8 @@ impl AddGamenightRequestBody { } } -impl From for Uuid { - fn from(value: GetGamenightRequestBody) -> Self { - Uuid::parse_str(value.id.unwrap().as_str()).unwrap() - } -} - #[get("/gamenights")] -pub async fn gamenights( +pub async fn get_gamenights( pool: web::Data, _user: AuthUser, ) -> Result { @@ -54,8 +43,8 @@ pub async fn gamenights( .body(serde_json::to_string(&model)?)) } -#[post("/gamenight")] -pub async fn gamenight_post( +#[post("/gamenights")] +pub async fn post_gamenights( pool: web::Data, user: AuthUser, gamenight_data: web::Json, @@ -65,25 +54,4 @@ pub async fn gamenight_post( gamenight::add_gamenight(&mut conn, gamenight_data.into_with_user(user)?)?; Ok(HttpResponse::Ok()) -} - -#[get("/gamenight")] -pub async fn gamenight_get( - pool: web::Data, - _user: AuthUser, - gamenight_data: web::Json, -) -> Result { - let mut conn = pool.get_conn(); - let gamenight = gamenight::get_gamenight(&mut conn, gamenight_data.into_inner().into())?; - 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(), - }; - - Ok(HttpResponse::Ok() - .content_type(ContentType::json()) - .body(serde_json::to_string(&model)?)) -} +} \ No newline at end of file diff --git a/backend-actix/src/request/games.rs b/backend-actix/src/request/games.rs new file mode 100644 index 0000000..9e20d81 --- /dev/null +++ b/backend-actix/src/request/games.rs @@ -0,0 +1,54 @@ +use actix_web::{get, post, web, HttpResponse, Responder}; +use actix_web::http::header::ContentType; +use gamenight_database::{DbPool, GetConnection}; +use gamenight_database::game::insert_game; +use uuid::Uuid; +use crate::models::add_game_request_body::AddGameRequestBody; +use crate::models::game::Game; +use crate::models::game_id::GameId; +use crate::request::authorization::AuthUser; +use crate::request::error::ApiError; + +impl From for gamenight_database::game::Game { + fn from(value: AddGameRequestBody) -> Self { + Self { + id: Uuid::new_v4(), + name: value.name, + } + } +} + +#[get("/games")] +pub async fn get_games( + pool: web::Data, + _user: AuthUser, +) -> Result { + let mut conn = pool.get_conn(); + let games: Vec = gamenight_database::games(&mut conn)?; + let model: Vec = games + .iter() + .map(|x| Game { + id: x.id.to_string(), + name: x.name.clone(), + }) + .collect(); + + Ok(HttpResponse::Ok() + .content_type(ContentType::json()) + .body(serde_json::to_string(&model)?)) +} + +#[post("/games")] +pub async fn post_games( + pool: web::Data, + _user: AuthUser, + game_data: web::Json, +) -> Result { + let mut conn = pool.get_conn(); + let game = game_data.0.into(); + insert_game(&mut conn, &game)?; + + Ok(HttpResponse::Ok() + .content_type(ContentType::json()) + .body(serde_json::to_string(&GameId{game_id: game.id.to_string()})?)) +} \ No newline at end of file diff --git a/backend-actix/src/request/join_gamenight.rs b/backend-actix/src/request/join_gamenight.rs deleted file mode 100644 index 922919a..0000000 --- a/backend-actix/src/request/join_gamenight.rs +++ /dev/null @@ -1,55 +0,0 @@ -use actix_web::{post, web, HttpResponse, Responder}; -use gamenight_database::{ - gamenight_participants::{ - delete_gamenight_participant, insert_gamenight_participant, GamenightParticipant, - }, - DbPool, GetConnection, -}; -use uuid::Uuid; - -use crate::{ - models::gamenight_id::GamenightId, - request::{authorization::AuthUser, error::ApiError}, -}; - -#[post("/join")] -pub async fn post_join_gamenight( - pool: web::Data, - user: AuthUser, - gamenight_id: web::Json, -) -> Result { - web::block(move || -> Result { - let mut conn = pool.get_conn(); - Ok(insert_gamenight_participant( - &mut conn, - GamenightParticipant { - gamenight_id: Uuid::parse_str(&gamenight_id.gamenight_id)?, - user_id: user.0.id, - }, - )?) - }) - .await??; - - Ok(HttpResponse::Ok()) -} - -#[post("/leave")] -pub async fn post_leave_gamenight( - pool: web::Data, - user: AuthUser, - gamenight_id: web::Json, -) -> Result { - web::block(move || -> Result { - let mut conn = pool.get_conn(); - let participant = GamenightParticipant { - gamenight_id: Uuid::parse_str(&gamenight_id.gamenight_id)?, - user_id: user.0.id, - }; - let x = delete_gamenight_participant(&mut conn, participant)?; - - Ok(x) - }) - .await??; - - Ok(HttpResponse::Ok()) -} diff --git a/backend-actix/src/request/location.rs b/backend-actix/src/request/location.rs index 1e3e06f..93c8a40 100644 --- a/backend-actix/src/request/location.rs +++ b/backend-actix/src/request/location.rs @@ -1,65 +1,28 @@ -use actix_web::{get, http::header::ContentType, post, web, HttpResponse, Responder}; -use gamenight_database::{ - location::{insert_location, locations}, - DbPool, GetConnection, -}; +use crate::models::location::Location; +use crate::request::authorization::AuthUser; +use crate::request::error::ApiError; +use actix_web::http::header::ContentType; +use actix_web::{get, web, HttpResponse, Responder}; +use gamenight_database::{DbPool, GetConnection}; use uuid::Uuid; -use crate::{ - models::{ - add_location_request_body::AddLocationRequestBody, location::Location, - location_id::LocationId, - }, - request::{authorization::AuthUser, error::ApiError}, -}; - -impl From for gamenight_database::location::Location { - fn from(value: AddLocationRequestBody) -> Self { - Self { - id: Uuid::new_v4(), - name: value.name, - address: value.address, - note: value.note, - } - } -} - -#[get("/locations")] +#[get("/location/{locationId}")] pub async fn get_locations( pool: web::Data, _user: AuthUser, + location_id: web::Path, ) -> Result { let mut conn = pool.get_conn(); - let games: Vec = locations(&mut conn)?; - let model: Vec = games - .iter() - .map(|x| Location { - id: x.id.to_string(), - name: x.name.clone(), - address: x.address.clone(), - note: x.note.clone(), - }) - .collect(); + let location = gamenight_database::location::load_location(&mut conn, location_id.into_inner())?; - Ok(HttpResponse::Ok() - .content_type(ContentType::json()) - .body(serde_json::to_string(&model)?)) -} - -#[post("/location")] -pub async fn post_location( - pool: web::Data, - _user: AuthUser, - game_data: web::Json, -) -> Result { - let mut conn = pool.get_conn(); - let uuid = insert_location(&mut conn, game_data.0.into())?; - - let model = LocationId { - location_id: uuid.to_string(), + let model = Location { + id: location.id.to_string(), + name: location.name.clone(), + note: location.note.clone(), + address: location.address.clone(), }; Ok(HttpResponse::Ok() .content_type(ContentType::json()) .body(serde_json::to_string(&model)?)) -} +} \ No newline at end of file diff --git a/backend-actix/src/request/location_authorized_user.rs b/backend-actix/src/request/location_authorized_user.rs new file mode 100644 index 0000000..b89d090 --- /dev/null +++ b/backend-actix/src/request/location_authorized_user.rs @@ -0,0 +1,23 @@ +use crate::request::authorization::AuthUser; +use crate::request::error::ApiError; +use actix_web::{delete, web, HttpResponse, Responder}; +use gamenight_database::location_owner::{revoke_permission, LocationOwner}; +use gamenight_database::{DbPool, GetConnection}; +use uuid::Uuid; + +#[delete("/location/{location_id}/authorized_users/{user_id}")] +pub async fn delete_location_authorized_user( + pool: web::Data, + _user: AuthUser, + location_id: web::Path, + user_id: web::Path +) -> Result { + let mut conn = pool.get_conn(); + + revoke_permission(&mut conn, LocationOwner { + user_id: user_id.into_inner(), + location_id: location_id.into_inner() + })?; + + Ok(HttpResponse::Ok()) +} \ No newline at end of file diff --git a/backend-actix/src/request/location_authorized_users.rs b/backend-actix/src/request/location_authorized_users.rs new file mode 100644 index 0000000..575b152 --- /dev/null +++ b/backend-actix/src/request/location_authorized_users.rs @@ -0,0 +1,60 @@ +use actix_web::{get, post, web, HttpResponse, Responder}; +use actix_web::http::header::ContentType; +use gamenight_database::{DbPool, GetConnection}; +use gamenight_database::location_owner::{grant_permission, location_permissions, LocationOwner}; +use gamenight_database::user::Role; +use uuid::Uuid; +use crate::models::location_id::LocationId; +use crate::models::user_id::UserId; +use crate::request::authorization::AuthUser; +use crate::request::error::ApiError; + +impl From for UserId { + fn from(uuid: Uuid) -> Self { + Self { + user_id: uuid.into(), + } + } +} + +#[get("/location/{locationId}/authorized_users/")] +pub async fn get_location_authorized_users( + pool: web::Data, + _user: AuthUser, + location_id: web::Path, +) -> Result { + let mut conn = pool.get_conn(); + + let permissions = + location_permissions(&mut conn, location_id.into_inner())?; + + let model: Vec = permissions.into_iter().map(Into::into).collect(); + + Ok(HttpResponse::Ok() + .content_type(ContentType::json()) + .body(serde_json::to_string(&model)?)) +} + +#[post("/location/{locationId}/authorized_users/")] +pub async fn post_location_authorized_users( + pool: web::Data, + user: AuthUser, + location_id1: web::Path, + user_id: web::Json, +) -> Result { + let mut conn = pool.get_conn(); + + let location_uuid = Uuid::parse_str(&location_id1.location_id)?; + let user_uuid = Uuid::parse_str(&user_id.user_id)?; + let authorized = location_permissions(&mut conn, location_uuid)?; + if user.0.role != Role::Admin && !authorized.contains(&user.0.id) { + Ok(HttpResponse::Unauthorized()) + } else { + grant_permission(&mut conn, LocationOwner { + location_id: location_uuid, + user_id: user_uuid, + })?; + + Ok(HttpResponse::Ok()) + } +} \ No newline at end of file diff --git a/backend-actix/src/request/location_owner.rs b/backend-actix/src/request/location_owner.rs deleted file mode 100644 index 550a937..0000000 --- a/backend-actix/src/request/location_owner.rs +++ /dev/null @@ -1,79 +0,0 @@ -use actix_web::{get, http::header::ContentType, post, web, HttpResponse, Responder}; -use gamenight_database::{ - location_owner::{grant_permission, location_permissions, revoke_permission, LocationOwner}, - user::Role, - DbPool, GetConnection, -}; -use uuid::Uuid; - -use crate::{ - models::{ - authorize_location_request_body::{ - AuthorizeLocationRequestBody, - Op::{Grant, Revoke}, - }, - location_id::LocationId, - user_id::UserId, - }, - request::{authorization::AuthUser, error::ApiError}, -}; - -impl<'a> TryFrom<&'a AuthorizeLocationRequestBody> for LocationOwner { - type Error = ApiError; - - fn try_from(value: &'a AuthorizeLocationRequestBody) -> Result { - Ok(LocationOwner { - location_id: Uuid::parse_str(&value.location_id)?, - user_id: Uuid::parse_str(&value.user_id)?, - }) - } -} - -#[post("/location_authorize")] -pub async fn post_location_authorize( - pool: web::Data, - user: AuthUser, - auth_data: web::Json, -) -> Result { - let mut conn = pool.get_conn(); - - let inner_auth_data = &auth_data.into_inner(); - let location_owner: LocationOwner = inner_auth_data.try_into()?; - let authorized = location_permissions(&mut conn, location_owner.location_id)?; - if user.0.role != Role::Admin && !authorized.contains(&user.0.id) { - Ok(HttpResponse::Unauthorized()) - } else { - match inner_auth_data.op { - Grant => grant_permission(&mut conn, location_owner)?, - Revoke => revoke_permission(&mut conn, location_owner)?, - }; - - Ok(HttpResponse::Ok()) - } -} - -impl From for UserId { - fn from(value: Uuid) -> Self { - Self { - user_id: value.to_string(), - } - } -} - -#[get("/authorized_location_user_ids")] -pub async fn get_authorized_location_user_ids( - pool: web::Data, - _user: AuthUser, - location_id: web::Json, -) -> Result { - let mut conn = pool.get_conn(); - - let permissions = - location_permissions(&mut conn, Uuid::parse_str(&location_id.0.location_id)?)?; - - let model: Vec = permissions.into_iter().map(Into::into).collect(); - - Ok(HttpResponse::Ok() - .content_type(ContentType::json()) - .body(serde_json::to_string(&model)?)) -} diff --git a/backend-actix/src/request/locations.rs b/backend-actix/src/request/locations.rs new file mode 100644 index 0000000..aa21e4f --- /dev/null +++ b/backend-actix/src/request/locations.rs @@ -0,0 +1,62 @@ +use actix_web::{get, post, web, HttpResponse, Responder}; +use actix_web::http::header::ContentType; +use gamenight_database::{DbPool, GetConnection}; +use gamenight_database::location::{insert_location, locations}; +use uuid::Uuid; +use crate::models::add_location_request_body::AddLocationRequestBody; +use crate::models::location::Location; +use crate::models::location_id::LocationId; +use crate::request::authorization::AuthUser; +use crate::request::error::ApiError; + +impl From for gamenight_database::location::Location { + fn from(value: AddLocationRequestBody) -> Self { + Self { + id: Uuid::new_v4(), + name: value.name, + address: value.address, + note: value.note, + } + } +} + +#[get("/locations")] +pub async fn get_locations( + pool: web::Data, + _user: AuthUser, +) -> Result { + let mut conn = pool.get_conn(); + let games: Vec = locations(&mut conn)?; + let model: Vec = games + .iter() + .map(|x| Location { + id: x.id.to_string(), + name: x.name.clone(), + address: x.address.clone(), + note: x.note.clone(), + }) + .collect(); + + Ok(HttpResponse::Ok() + .content_type(ContentType::json()) + .body(serde_json::to_string(&model)?)) +} + +#[post("/locations")] +pub async fn post_locations( + pool: web::Data, + _user: AuthUser, + game_data: web::Json, +) -> Result { + let mut conn = pool.get_conn(); + let uuid = insert_location(&mut conn, game_data.0.into())?; + + let model = LocationId { + location_id: uuid.to_string(), + }; + + Ok(HttpResponse::Ok() + .content_type(ContentType::json()) + .body(serde_json::to_string(&model)?)) +} + diff --git a/backend-actix/src/request/mod.rs b/backend-actix/src/request/mod.rs index 6ae8db0..7cdeeca 100644 --- a/backend-actix/src/request/mod.rs +++ b/backend-actix/src/request/mod.rs @@ -1,34 +1,20 @@ + mod authorization; mod error; -mod game; -mod gamenight_handlers; -mod join_gamenight; -mod location; -mod location_owner; -mod participant_handlers; -mod user_handlers; -pub use game::get_game; -pub use game::get_games; -pub use game::get_owned_games; -pub use game::post_disown_game; -pub use game::post_game; -pub use game::post_own_game; -pub use game::post_rename_game; -pub use game::delete_game; -pub use gamenight_handlers::gamenight_get; -pub use gamenight_handlers::gamenight_post; -pub use gamenight_handlers::gamenights; -pub use join_gamenight::post_join_gamenight; -pub use join_gamenight::post_leave_gamenight; -pub use location::get_locations; -pub use location::post_location; -pub use location_owner::get_authorized_location_user_ids; -pub use location_owner::post_location_authorize; -pub use participant_handlers::get_get_participants; -pub use user_handlers::get_user; -pub use user_handlers::get_user_unauthenticated; -pub use user_handlers::get_users; -pub use user_handlers::login; -pub use user_handlers::refresh; -pub use user_handlers::register; +pub mod token; +pub mod users; +pub mod user; +pub mod user_owned_games; +pub mod gamenights; +pub mod gamenight; +pub mod gamenight_participants; +pub mod gamenight_participant; +pub mod games; +pub mod game; +pub mod game_owners; +pub mod game_owner; +pub mod locations; +pub mod location; +pub mod location_authorized_users; +pub mod location_authorized_user; diff --git a/backend-actix/src/request/participant_handlers.rs b/backend-actix/src/request/participant_handlers.rs deleted file mode 100644 index a890328..0000000 --- a/backend-actix/src/request/participant_handlers.rs +++ /dev/null @@ -1,31 +0,0 @@ -use actix_web::{get, http::header::ContentType, web, HttpResponse, Responder}; -use gamenight_database::{DbPool, GetConnection}; -use uuid::Uuid; - -use crate::{ - models::{gamenight_id::GamenightId, participants::Participants}, - request::{authorization::AuthUser, error::ApiError}, -}; - -#[get("/participants")] -pub async fn get_get_participants( - pool: web::Data, - _user: AuthUser, - gamenight_info: web::Json, -) -> Result { - let mut conn = pool.get_conn(); - - let users = gamenight_database::get_participants( - &mut conn, - &Uuid::parse_str(&gamenight_info.into_inner().gamenight_id)?, - )? - .iter() - .map(|x| x.to_string()) - .collect(); - - Ok(HttpResponse::Ok() - .content_type(ContentType::json()) - .body(serde_json::to_string(&Participants { - participants: users, - })?)) -} diff --git a/backend-actix/src/request/token.rs b/backend-actix/src/request/token.rs new file mode 100644 index 0000000..e627523 --- /dev/null +++ b/backend-actix/src/request/token.rs @@ -0,0 +1,54 @@ +use crate::models::login::Login; +use crate::models::token::Token; +use crate::request::authorization::{get_token, AuthUser}; +use crate::request::error::ApiError; +use actix_web::http::header::ContentType; +use actix_web::{post, web, HttpResponse, Responder}; +use gamenight_database::{DbPool, GetConnection}; + +impl From for gamenight_database::user::LoginUser { + fn from(val: Login) -> Self { + gamenight_database::user::LoginUser { + username: val.username, + password: val.password, + } + } +} +#[post("/token")] +pub async fn post_token( + pool: web::Data, + login_data: web::Json, +) -> Result { + let data = login_data.into_inner(); + + if let Ok(Some(user)) = web::block(move || { + let mut conn = pool.get_conn(); + gamenight_database::login(&mut conn, data.into()) + }) + .await? + { + let token = get_token(&user)?; + let response = Token { + jwt_token: Some(token), + }; + Ok(HttpResponse::Ok() + .content_type(ContentType::json()) + .body(serde_json::to_string(&response)?)) + } else { + Err(ApiError { + status: 401, + message: "User doesn't exist or password doesn't match".to_string(), + }) + } +} + +#[post("/refresh_token")] +pub async fn post_refresh_token(user: AuthUser) -> Result { + let new_token = get_token(&user.0)?; + let response = Token { + jwt_token: Some(new_token), + }; + Ok(HttpResponse::Ok() + .content_type(ContentType::json()) + .body(serde_json::to_string(&response)?)) +} \ No newline at end of file diff --git a/backend-actix/src/request/user.rs b/backend-actix/src/request/user.rs new file mode 100644 index 0000000..5eca7a4 --- /dev/null +++ b/backend-actix/src/request/user.rs @@ -0,0 +1,37 @@ +use crate::models::user::User; +use crate::request::error::ApiError; +use actix_web::{get, http::header::ContentType, web, HttpResponse, Responder}; +use gamenight_database::{DbPool, GetConnection}; +use serde_json; +use uuid::Uuid; + +use super::authorization::AuthUser; + + +impl From for User { + fn from(value: gamenight_database::user::User) -> Self { + Self { + id: value.id.to_string(), + username: value.username, + email: None, + } + } +} + +#[get("/user/{userId}")] +pub async fn get_user( + pool: web::Data, + _user: AuthUser, + user_id: web::Path, +) -> Result { + let mut conn = pool.get_conn(); + + let user = gamenight_database::user::get_user( + &mut conn, + user_id.into_inner() + )?; + + Ok(HttpResponse::Ok() + .content_type(ContentType::json()) + .body(serde_json::to_string(&user)?)) +} \ No newline at end of file diff --git a/backend-actix/src/request/user_owned_games.rs b/backend-actix/src/request/user_owned_games.rs new file mode 100644 index 0000000..1141aa4 --- /dev/null +++ b/backend-actix/src/request/user_owned_games.rs @@ -0,0 +1,28 @@ +use actix_web::{get, web, HttpResponse, Responder}; +use actix_web::http::header::ContentType; +use gamenight_database::{DbPool, GetConnection}; +use gamenight_database::owned_game::owned_games; +use uuid::Uuid; +use crate::models; +use crate::request::authorization::AuthUser; +use crate::request::error::ApiError; + +#[get("/user/{userId}/owned_games")] +pub async fn get_user_owned_games( + pool: web::Data, + _user: AuthUser, + user_id: web::Path +) -> Result { + let mut conn = pool.get_conn(); + let game_ids = owned_games(&mut conn, user_id.into_inner())?; + + let model = game_ids.iter().map(|(u,g , l)| models::owned_game::OwnedGame { + user_id: u.to_string(), + game_id: g.to_string(), + location_id: l.map(|x| x.to_string()) + }).collect::>(); + + Ok(HttpResponse::Ok() + .content_type(ContentType::json()) + .body(serde_json::to_string(&model)?)) +} diff --git a/backend-actix/src/request/user_handlers.rs b/backend-actix/src/request/users.rs similarity index 54% rename from backend-actix/src/request/user_handlers.rs rename to backend-actix/src/request/users.rs index 43b51cc..5700ad3 100644 --- a/backend-actix/src/request/user_handlers.rs +++ b/backend-actix/src/request/users.rs @@ -1,25 +1,13 @@ -use crate::models::{ - login::Login, registration::Registration, token::Token, user::User, user_id::UserId, -}; -use crate::request::{authorization::get_token, error::ApiError}; -use actix_web::{get, http::header::ContentType, post, web, HttpResponse, Responder}; -use gamenight_database::user::{count_users_with_email, count_users_with_username}; +use actix_web::{get, post, web, HttpResponse, Responder}; +use actix_web::http::header::ContentType; use gamenight_database::{DbPool, GetConnection}; +use gamenight_database::user::{count_users_with_email, count_users_with_username}; use serde::{Deserialize, Serialize}; -use serde_json; -use uuid::Uuid; use validator::{Validate, ValidateArgs, ValidationError}; - -use super::authorization::AuthUser; - -impl From for gamenight_database::user::LoginUser { - fn from(val: Login) -> Self { - gamenight_database::user::LoginUser { - username: val.username, - password: val.password, - } - } -} +use crate::models::registration::Registration; +use crate::models::user::User; +use crate::request::authorization::AuthUser; +use crate::request::error::ApiError; impl From for gamenight_database::user::Register { fn from(val: Registration) -> Self { @@ -35,6 +23,7 @@ pub struct RegisterContext<'v_a> { pub pool: &'v_a DbPool, } + pub fn unique_username( username: &String, context: &RegisterContext, @@ -83,100 +72,7 @@ impl From for ValidatableRegistration { } } -#[get("/token")] -pub async fn login( - pool: web::Data, - login_data: web::Json, -) -> Result { - let data = login_data.into_inner(); - - if let Ok(Some(user)) = web::block(move || { - let mut conn = pool.get_conn(); - gamenight_database::login(&mut conn, data.into()) - }) - .await? - { - let token = get_token(&user)?; - let response = Token { - jwt_token: Some(token), - }; - Ok(HttpResponse::Ok() - .content_type(ContentType::json()) - .body(serde_json::to_string(&response)?)) - } else { - Err(ApiError { - status: 401, - message: "User doesn't exist or password doesn't match".to_string(), - }) - } -} - -#[post("/token")] -pub async fn refresh(user: AuthUser) -> Result { - let new_token = get_token(&user.0)?; - let response = Token { - jwt_token: Some(new_token), - }; - Ok(HttpResponse::Ok() - .content_type(ContentType::json()) - .body(serde_json::to_string(&response)?)) -} - -#[post("/user")] -pub async fn register( - pool: web::Data, - register_data: web::Json, -) -> Result { - web::block(move || -> Result<(), ApiError> { - let validatable_registration: ValidatableRegistration = register_data.clone().into(); - validatable_registration.validate_with_args(&RegisterContext { pool: &pool })?; - let register_request = register_data.into_inner().into(); - let mut conn = pool.get_conn(); - gamenight_database::register(&mut conn, register_request)?; - Ok(()) - }) - .await??; - - Ok(HttpResponse::Ok()) -} - -impl From for User { - fn from(value: gamenight_database::user::User) -> Self { - Self { - id: value.id.to_string(), - username: value.username, - email: None, - } - } -} - -#[get("/user")] -pub async fn get_user( - pool: web::Data, - _user: AuthUser, - user_info: web::Json, -) -> Result { - let mut conn = pool.get_conn(); - - let user = gamenight_database::user::get_user( - &mut conn, - Uuid::parse_str(&user_info.into_inner().user_id)?, - )?; - - Ok(HttpResponse::Ok() - .content_type(ContentType::json()) - .body(serde_json::to_string(&user)?)) -} - -#[get("/user")] -pub async fn get_user_unauthenticated( - _path: web::Path, -) -> Result { - Ok(HttpResponse::Forbidden()) -} - #[get("/users")] - pub async fn get_users( pool: web::Data, _user: AuthUser, @@ -190,3 +86,21 @@ pub async fn get_users( .content_type(ContentType::json()) .body(serde_json::to_string(&model)?)) } + +#[post("/users")] +pub async fn post_users( + pool: web::Data, + register_data: web::Json, +) -> Result { + web::block(move || -> Result<(), ApiError> { + let validatable_registration: ValidatableRegistration = register_data.clone().into(); + validatable_registration.validate_with_args(&RegisterContext { pool: &pool })?; + let register_request = register_data.into_inner().into(); + let mut conn = pool.get_conn(); + gamenight_database::register(&mut conn, register_request)?; + Ok(()) + }) + .await??; + + Ok(HttpResponse::Ok()) +} diff --git a/gamenight-api-client-rs/.openapi-generator/FILES b/gamenight-api-client-rs/.openapi-generator/FILES index 0b53035..8363dbd 100644 --- a/gamenight-api-client-rs/.openapi-generator/FILES +++ b/gamenight-api-client-rs/.openapi-generator/FILES @@ -5,22 +5,20 @@ README.md docs/AddGameRequestBody.md docs/AddGamenightRequestBody.md docs/AddLocationRequestBody.md -docs/AuthorizeLocationRequestBody.md docs/DefaultApi.md +docs/EditGameRequestBody.md docs/Failure.md docs/Game.md docs/GameId.md docs/Gamenight.md docs/GamenightId.md -docs/GetGamenightRequestBody.md docs/Location.md docs/LocationId.md docs/Login.md -docs/OwnGameRequestBody.md +docs/OwnGame.md docs/OwnedGame.md docs/Participants.md docs/Registration.md -docs/RenameGameRequestBody.md docs/Token.md docs/User.md docs/UserId.md @@ -32,22 +30,20 @@ src/lib.rs src/models/add_game_request_body.rs src/models/add_gamenight_request_body.rs src/models/add_location_request_body.rs -src/models/authorize_location_request_body.rs +src/models/edit_game_request_body.rs src/models/failure.rs src/models/game.rs src/models/game_id.rs src/models/gamenight.rs src/models/gamenight_id.rs -src/models/get_gamenight_request_body.rs src/models/location.rs src/models/location_id.rs src/models/login.rs src/models/mod.rs -src/models/own_game_request_body.rs +src/models/own_game.rs src/models/owned_game.rs src/models/participants.rs src/models/registration.rs -src/models/rename_game_request_body.rs src/models/token.rs src/models/user.rs src/models/user_id.rs diff --git a/gamenight-api-client-rs/README.md b/gamenight-api-client-rs/README.md index f5f0bcb..636f365 100644 --- a/gamenight-api-client-rs/README.md +++ b/gamenight-api-client-rs/README.md @@ -27,30 +27,31 @@ All URIs are relative to *http://localhost:8080* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- -*DefaultApi* | [**authorized_location_user_ids_get**](docs/DefaultApi.md#authorized_location_user_ids_get) | **GET** /authorized_location_user_ids | -*DefaultApi* | [**disown_post**](docs/DefaultApi.md#disown_post) | **POST** /disown | -*DefaultApi* | [**game_delete**](docs/DefaultApi.md#game_delete) | **DELETE** /game | -*DefaultApi* | [**game_get**](docs/DefaultApi.md#game_get) | **GET** /game | -*DefaultApi* | [**game_post**](docs/DefaultApi.md#game_post) | **POST** /game | -*DefaultApi* | [**games_get**](docs/DefaultApi.md#games_get) | **GET** /games | -*DefaultApi* | [**get_gamenight**](docs/DefaultApi.md#get_gamenight) | **GET** /gamenight | +*DefaultApi* | [**delete_game**](docs/DefaultApi.md#delete_game) | **DELETE** /game/{gameId} | Delete this game. +*DefaultApi* | [**delete_game_owner**](docs/DefaultApi.md#delete_game_owner) | **DELETE** /game/{gameId}/owner/{userId} | no longer own this game +*DefaultApi* | [**delete_gamenight_participant**](docs/DefaultApi.md#delete_gamenight_participant) | **DELETE** /gamenight/{gamenightId}/participant/{userId} | deletes a gamenight participant +*DefaultApi* | [**delete_location_authorized_user**](docs/DefaultApi.md#delete_location_authorized_user) | **DELETE** /location/{locationId}/authorized_user/{userId} | remove an authorized user from a location +*DefaultApi* | [**get_game**](docs/DefaultApi.md#get_game) | **GET** /game/{gameId} | Get this specific game +*DefaultApi* | [**get_gamenight**](docs/DefaultApi.md#get_gamenight) | **GET** /gamenight/{gamenightId} | get the specified gamenight +*DefaultApi* | [**get_gamenight_participants**](docs/DefaultApi.md#get_gamenight_participants) | **GET** /gamenight/{gamenightId}/participants | Get all participants for a gamenight *DefaultApi* | [**get_gamenights**](docs/DefaultApi.md#get_gamenights) | **GET** /gamenights | Get a all gamenights -*DefaultApi* | [**get_token**](docs/DefaultApi.md#get_token) | **GET** /token | -*DefaultApi* | [**join_post**](docs/DefaultApi.md#join_post) | **POST** /join | -*DefaultApi* | [**leave_post**](docs/DefaultApi.md#leave_post) | **POST** /leave | -*DefaultApi* | [**location_authorize_post**](docs/DefaultApi.md#location_authorize_post) | **POST** /location_authorize | -*DefaultApi* | [**location_get**](docs/DefaultApi.md#location_get) | **GET** /location | -*DefaultApi* | [**location_post**](docs/DefaultApi.md#location_post) | **POST** /location | -*DefaultApi* | [**locations_get**](docs/DefaultApi.md#locations_get) | **GET** /locations | -*DefaultApi* | [**own_post**](docs/DefaultApi.md#own_post) | **POST** /own | -*DefaultApi* | [**owned_games_get**](docs/DefaultApi.md#owned_games_get) | **GET** /owned_games | -*DefaultApi* | [**participants_get**](docs/DefaultApi.md#participants_get) | **GET** /participants | Get all participants for a gamenight -*DefaultApi* | [**post_gamenight**](docs/DefaultApi.md#post_gamenight) | **POST** /gamenight | -*DefaultApi* | [**post_register**](docs/DefaultApi.md#post_register) | **POST** /user | -*DefaultApi* | [**post_token**](docs/DefaultApi.md#post_token) | **POST** /token | -*DefaultApi* | [**rename_game_post**](docs/DefaultApi.md#rename_game_post) | **POST** /rename_game | -*DefaultApi* | [**user_get**](docs/DefaultApi.md#user_get) | **GET** /user | -*DefaultApi* | [**users_get**](docs/DefaultApi.md#users_get) | **GET** /users | +*DefaultApi* | [**get_games**](docs/DefaultApi.md#get_games) | **GET** /games | get all games +*DefaultApi* | [**get_location**](docs/DefaultApi.md#get_location) | **GET** /location/{locationId} | gets this location +*DefaultApi* | [**get_location_authorized_users**](docs/DefaultApi.md#get_location_authorized_users) | **GET** /location/{locationId}/authorized_users/ | gets this locations authorized users +*DefaultApi* | [**get_locations**](docs/DefaultApi.md#get_locations) | **GET** /locations | get all locations +*DefaultApi* | [**get_user**](docs/DefaultApi.md#get_user) | **GET** /user/{userId} | +*DefaultApi* | [**get_user_owned_games**](docs/DefaultApi.md#get_user_owned_games) | **GET** /user/{userId}/owned_games | Get owned games of user +*DefaultApi* | [**get_users**](docs/DefaultApi.md#get_users) | **GET** /users | Get all users +*DefaultApi* | [**post_game_owners**](docs/DefaultApi.md#post_game_owners) | **POST** /game/{gameId}/owners | Own this game +*DefaultApi* | [**post_gamenight_participants**](docs/DefaultApi.md#post_gamenight_participants) | **POST** /gamenight/{gamenightId}/participants | Add a participant +*DefaultApi* | [**post_gamenights**](docs/DefaultApi.md#post_gamenights) | **POST** /gamenights | Gets the gamenight +*DefaultApi* | [**post_games**](docs/DefaultApi.md#post_games) | **POST** /games | add a game +*DefaultApi* | [**post_location_authorized_users**](docs/DefaultApi.md#post_location_authorized_users) | **POST** /location/{locationId}/authorized_users/ | Authorize a user +*DefaultApi* | [**post_locations**](docs/DefaultApi.md#post_locations) | **POST** /locations | add a location +*DefaultApi* | [**post_refresh_token**](docs/DefaultApi.md#post_refresh_token) | **POST** /refresh_token | Refresh a user token +*DefaultApi* | [**post_token**](docs/DefaultApi.md#post_token) | **POST** /token | Login a user. +*DefaultApi* | [**post_users**](docs/DefaultApi.md#post_users) | **POST** /users | Registers a user into gamenight. +*DefaultApi* | [**put_game**](docs/DefaultApi.md#put_game) | **PUT** /game/{gameId} | Changes this game resource ## Documentation For Models @@ -58,21 +59,19 @@ Class | Method | HTTP request | Description - [AddGameRequestBody](docs/AddGameRequestBody.md) - [AddGamenightRequestBody](docs/AddGamenightRequestBody.md) - [AddLocationRequestBody](docs/AddLocationRequestBody.md) - - [AuthorizeLocationRequestBody](docs/AuthorizeLocationRequestBody.md) + - [EditGameRequestBody](docs/EditGameRequestBody.md) - [Failure](docs/Failure.md) - [Game](docs/Game.md) - [GameId](docs/GameId.md) - [Gamenight](docs/Gamenight.md) - [GamenightId](docs/GamenightId.md) - - [GetGamenightRequestBody](docs/GetGamenightRequestBody.md) - [Location](docs/Location.md) - [LocationId](docs/LocationId.md) - [Login](docs/Login.md) - - [OwnGameRequestBody](docs/OwnGameRequestBody.md) + - [OwnGame](docs/OwnGame.md) - [OwnedGame](docs/OwnedGame.md) - [Participants](docs/Participants.md) - [Registration](docs/Registration.md) - - [RenameGameRequestBody](docs/RenameGameRequestBody.md) - [Token](docs/Token.md) - [User](docs/User.md) - [UserId](docs/UserId.md) diff --git a/gamenight-api-client-rs/docs/DefaultApi.md b/gamenight-api-client-rs/docs/DefaultApi.md index a23c781..df3b73d 100644 --- a/gamenight-api-client-rs/docs/DefaultApi.md +++ b/gamenight-api-client-rs/docs/DefaultApi.md @@ -4,72 +4,45 @@ All URIs are relative to *http://localhost:8080* Method | HTTP request | Description ------------- | ------------- | ------------- -[**authorized_location_user_ids_get**](DefaultApi.md#authorized_location_user_ids_get) | **GET** /authorized_location_user_ids | -[**disown_post**](DefaultApi.md#disown_post) | **POST** /disown | -[**game_delete**](DefaultApi.md#game_delete) | **DELETE** /game | -[**game_get**](DefaultApi.md#game_get) | **GET** /game | -[**game_post**](DefaultApi.md#game_post) | **POST** /game | -[**games_get**](DefaultApi.md#games_get) | **GET** /games | -[**get_gamenight**](DefaultApi.md#get_gamenight) | **GET** /gamenight | +[**delete_game**](DefaultApi.md#delete_game) | **DELETE** /game/{gameId} | Delete this game. +[**delete_game_owner**](DefaultApi.md#delete_game_owner) | **DELETE** /game/{gameId}/owner/{userId} | no longer own this game +[**delete_gamenight_participant**](DefaultApi.md#delete_gamenight_participant) | **DELETE** /gamenight/{gamenightId}/participant/{userId} | deletes a gamenight participant +[**delete_location_authorized_user**](DefaultApi.md#delete_location_authorized_user) | **DELETE** /location/{locationId}/authorized_user/{userId} | remove an authorized user from a location +[**get_game**](DefaultApi.md#get_game) | **GET** /game/{gameId} | Get this specific game +[**get_gamenight**](DefaultApi.md#get_gamenight) | **GET** /gamenight/{gamenightId} | get the specified gamenight +[**get_gamenight_participants**](DefaultApi.md#get_gamenight_participants) | **GET** /gamenight/{gamenightId}/participants | Get all participants for a gamenight [**get_gamenights**](DefaultApi.md#get_gamenights) | **GET** /gamenights | Get a all gamenights -[**get_token**](DefaultApi.md#get_token) | **GET** /token | -[**join_post**](DefaultApi.md#join_post) | **POST** /join | -[**leave_post**](DefaultApi.md#leave_post) | **POST** /leave | -[**location_authorize_post**](DefaultApi.md#location_authorize_post) | **POST** /location_authorize | -[**location_get**](DefaultApi.md#location_get) | **GET** /location | -[**location_post**](DefaultApi.md#location_post) | **POST** /location | -[**locations_get**](DefaultApi.md#locations_get) | **GET** /locations | -[**own_post**](DefaultApi.md#own_post) | **POST** /own | -[**owned_games_get**](DefaultApi.md#owned_games_get) | **GET** /owned_games | -[**participants_get**](DefaultApi.md#participants_get) | **GET** /participants | Get all participants for a gamenight -[**post_gamenight**](DefaultApi.md#post_gamenight) | **POST** /gamenight | -[**post_register**](DefaultApi.md#post_register) | **POST** /user | -[**post_token**](DefaultApi.md#post_token) | **POST** /token | -[**rename_game_post**](DefaultApi.md#rename_game_post) | **POST** /rename_game | -[**user_get**](DefaultApi.md#user_get) | **GET** /user | -[**users_get**](DefaultApi.md#users_get) | **GET** /users | +[**get_games**](DefaultApi.md#get_games) | **GET** /games | get all games +[**get_location**](DefaultApi.md#get_location) | **GET** /location/{locationId} | gets this location +[**get_location_authorized_users**](DefaultApi.md#get_location_authorized_users) | **GET** /location/{locationId}/authorized_users/ | gets this locations authorized users +[**get_locations**](DefaultApi.md#get_locations) | **GET** /locations | get all locations +[**get_user**](DefaultApi.md#get_user) | **GET** /user/{userId} | +[**get_user_owned_games**](DefaultApi.md#get_user_owned_games) | **GET** /user/{userId}/owned_games | Get owned games of user +[**get_users**](DefaultApi.md#get_users) | **GET** /users | Get all users +[**post_game_owners**](DefaultApi.md#post_game_owners) | **POST** /game/{gameId}/owners | Own this game +[**post_gamenight_participants**](DefaultApi.md#post_gamenight_participants) | **POST** /gamenight/{gamenightId}/participants | Add a participant +[**post_gamenights**](DefaultApi.md#post_gamenights) | **POST** /gamenights | Gets the gamenight +[**post_games**](DefaultApi.md#post_games) | **POST** /games | add a game +[**post_location_authorized_users**](DefaultApi.md#post_location_authorized_users) | **POST** /location/{locationId}/authorized_users/ | Authorize a user +[**post_locations**](DefaultApi.md#post_locations) | **POST** /locations | add a location +[**post_refresh_token**](DefaultApi.md#post_refresh_token) | **POST** /refresh_token | Refresh a user token +[**post_token**](DefaultApi.md#post_token) | **POST** /token | Login a user. +[**post_users**](DefaultApi.md#post_users) | **POST** /users | Registers a user into gamenight. +[**put_game**](DefaultApi.md#put_game) | **PUT** /game/{gameId} | Changes this game resource -## authorized_location_user_ids_get - -> Vec authorized_location_user_ids_get(location_id) +## delete_game +> delete_game(game_id) +Delete this game. ### Parameters Name | Type | Description | Required | Notes ------------- | ------------- | ------------- | ------------- | ------------- -**location_id** | Option<[**LocationId**](LocationId.md)> | | | - -### Return type - -[**Vec**](UserId.md) - -### Authorization - -[JWT-Auth](../README.md#JWT-Auth) - -### HTTP request headers - -- **Content-Type**: application/json -- **Accept**: application/json - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - - -## disown_post - -> disown_post(game_id) - - -### Parameters - - -Name | Type | Description | Required | Notes -------------- | ------------- | ------------- | ------------- | ------------- -**game_id** | Option<[**GameId**](GameId.md)> | | | +**game_id** | **String** | Uuid of game to delete. | [required] | ### Return type @@ -81,23 +54,24 @@ Name | Type | Description | Required | Notes ### HTTP request headers -- **Content-Type**: application/json +- **Content-Type**: Not defined - **Accept**: application/json [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) -## game_delete - -> game_delete(game_id) +## delete_game_owner +> delete_game_owner(game_id, user_id) +no longer own this game ### Parameters Name | Type | Description | Required | Notes ------------- | ------------- | ------------- | ------------- | ------------- -**game_id** | Option<[**GameId**](GameId.md)> | | | +**game_id** | **String** | Uuid of game that user no longer owns. | [required] | +**user_id** | **String** | Uuid of user that no longer owns. | [required] | ### Return type @@ -109,23 +83,81 @@ Name | Type | Description | Required | Notes ### HTTP request headers -- **Content-Type**: application/json +- **Content-Type**: Not defined - **Accept**: application/json [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) -## game_get - -> models::Game game_get(game_id) +## delete_gamenight_participant +> delete_gamenight_participant(gamenight_id, user_id) +deletes a gamenight participant ### Parameters Name | Type | Description | Required | Notes ------------- | ------------- | ------------- | ------------- | ------------- -**game_id** | Option<[**GameId**](GameId.md)> | | | +**gamenight_id** | **String** | Uuid of gamenight to delete participant for | [required] | +**user_id** | **String** | Uuid of the of the participant to remove | [required] | + +### Return type + + (empty response body) + +### Authorization + +[JWT-Auth](../README.md#JWT-Auth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## delete_location_authorized_user + +> delete_location_authorized_user(location_id, user_id) +remove an authorized user from a location + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**location_id** | **String** | Uuid of location to deauthorize for. | [required] | +**user_id** | **String** | Uuid of user ot deauthorize. | [required] | + +### Return type + + (empty response body) + +### Authorization + +[JWT-Auth](../README.md#JWT-Auth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## get_game + +> models::Game get_game(game_id) +Get this specific game + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**game_id** | **String** | Uuid of game to get. | [required] | ### Return type @@ -137,59 +169,6 @@ Name | Type | Description | Required | Notes ### HTTP request headers -- **Content-Type**: application/json -- **Accept**: application/json - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - - -## game_post - -> models::GameId game_post(add_game_request_body) - - -### Parameters - - -Name | Type | Description | Required | Notes -------------- | ------------- | ------------- | ------------- | ------------- -**add_game_request_body** | Option<[**AddGameRequestBody**](AddGameRequestBody.md)> | | | - -### Return type - -[**models::GameId**](GameId.md) - -### Authorization - -[JWT-Auth](../README.md#JWT-Auth) - -### HTTP request headers - -- **Content-Type**: application/json -- **Accept**: application/json - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - - -## games_get - -> Vec games_get() - - -### Parameters - -This endpoint does not need any parameter. - -### Return type - -[**Vec**](Game.md) - -### Authorization - -[JWT-Auth](../README.md#JWT-Auth) - -### HTTP request headers - - **Content-Type**: Not defined - **Accept**: application/json @@ -198,15 +177,15 @@ This endpoint does not need any parameter. ## get_gamenight -> models::Gamenight get_gamenight(get_gamenight_request_body) - +> models::Gamenight get_gamenight(gamenight_id) +get the specified gamenight ### Parameters Name | Type | Description | Required | Notes ------------- | ------------- | ------------- | ------------- | ------------- -**get_gamenight_request_body** | Option<[**GetGamenightRequestBody**](GetGamenightRequestBody.md)> | | | +**gamenight_id** | **String** | Uuid of gamenight to get. | [required] | ### Return type @@ -218,7 +197,37 @@ Name | Type | Description | Required | Notes ### HTTP request headers -- **Content-Type**: application/json +- **Content-Type**: Not defined +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## get_gamenight_participants + +> models::Participants get_gamenight_participants(gamenight_id) +Get all participants for a gamenight + +Retrieve the participants of a single gamenight by id. + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**gamenight_id** | **String** | Uuid of gamenight to get participants for. | [required] | + +### Return type + +[**models::Participants**](Participants.md) + +### Authorization + +[JWT-Auth](../README.md#JWT-Auth) + +### HTTP request headers + +- **Content-Type**: Not defined - **Accept**: application/json [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) @@ -251,51 +260,18 @@ This endpoint does not need any parameter. [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) -## get_token +## get_games -> models::Token get_token(login) - - -Submit your credentials to get a JWT-token to use with the rest of the api. +> Vec get_games() +get all games ### Parameters - -Name | Type | Description | Required | Notes -------------- | ------------- | ------------- | ------------- | ------------- -**login** | Option<[**Login**](Login.md)> | | | +This endpoint does not need any parameter. ### Return type -[**models::Token**](Token.md) - -### Authorization - -No authorization required - -### HTTP request headers - -- **Content-Type**: application/json -- **Accept**: application/json - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - - -## join_post - -> join_post(gamenight_id) - - -### Parameters - - -Name | Type | Description | Required | Notes -------------- | ------------- | ------------- | ------------- | ------------- -**gamenight_id** | Option<[**GamenightId**](GamenightId.md)> | | | - -### Return type - - (empty response body) +[**Vec**](Game.md) ### Authorization @@ -303,79 +279,23 @@ Name | Type | Description | Required | Notes ### HTTP request headers -- **Content-Type**: application/json +- **Content-Type**: Not defined - **Accept**: application/json [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) -## leave_post - -> leave_post(gamenight_id) +## get_location +> models::Location get_location(location_id) +gets this location ### Parameters Name | Type | Description | Required | Notes ------------- | ------------- | ------------- | ------------- | ------------- -**gamenight_id** | Option<[**GamenightId**](GamenightId.md)> | | | - -### Return type - - (empty response body) - -### Authorization - -[JWT-Auth](../README.md#JWT-Auth) - -### HTTP request headers - -- **Content-Type**: application/json -- **Accept**: application/json - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - - -## location_authorize_post - -> location_authorize_post(authorize_location_request_body) - - -### Parameters - - -Name | Type | Description | Required | Notes -------------- | ------------- | ------------- | ------------- | ------------- -**authorize_location_request_body** | Option<[**AuthorizeLocationRequestBody**](AuthorizeLocationRequestBody.md)> | | | - -### Return type - - (empty response body) - -### Authorization - -[JWT-Auth](../README.md#JWT-Auth) - -### HTTP request headers - -- **Content-Type**: application/json -- **Accept**: application/json - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - - -## location_get - -> models::Location location_get(location_id) - - -### Parameters - - -Name | Type | Description | Required | Notes -------------- | ------------- | ------------- | ------------- | ------------- -**location_id** | Option<[**LocationId**](LocationId.md)> | | | +**location_id** | **String** | Uuid of location to get. | [required] | ### Return type @@ -387,27 +307,27 @@ Name | Type | Description | Required | Notes ### HTTP request headers -- **Content-Type**: application/json +- **Content-Type**: Not defined - **Accept**: application/json [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) -## location_post - -> models::LocationId location_post(add_location_request_body) +## get_location_authorized_users +> Vec get_location_authorized_users(location_id) +gets this locations authorized users ### Parameters Name | Type | Description | Required | Notes ------------- | ------------- | ------------- | ------------- | ------------- -**add_location_request_body** | Option<[**AddLocationRequestBody**](AddLocationRequestBody.md)> | | | +**location_id** | **String** | Uuid of location to get authorized users for. | [required] | ### Return type -[**models::LocationId**](LocationId.md) +[**Vec**](UserId.md) ### Authorization @@ -415,16 +335,16 @@ Name | Type | Description | Required | Notes ### HTTP request headers -- **Content-Type**: application/json +- **Content-Type**: Not defined - **Accept**: application/json [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) -## locations_get - -> Vec locations_get() +## get_locations +> Vec get_locations() +get all locations ### Parameters @@ -446,17 +366,101 @@ This endpoint does not need any parameter. [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) -## own_post +## get_user -> own_post(own_game_request_body) +> models::User get_user(user_id) +Get a user from primary id + ### Parameters Name | Type | Description | Required | Notes ------------- | ------------- | ------------- | ------------- | ------------- -**own_game_request_body** | Option<[**OwnGameRequestBody**](OwnGameRequestBody.md)> | | | +**user_id** | **String** | Uuid of user to get | [required] | + +### Return type + +[**models::User**](User.md) + +### Authorization + +[JWT-Auth](../README.md#JWT-Auth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## get_user_owned_games + +> Vec get_user_owned_games(user_id) +Get owned games of user + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**user_id** | **String** | Uuid of user to get owned games for. | [required] | + +### Return type + +[**Vec**](OwnedGame.md) + +### Authorization + +[JWT-Auth](../README.md#JWT-Auth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## get_users + +> Vec get_users() +Get all users + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +[**Vec**](User.md) + +### Authorization + +[JWT-Auth](../README.md#JWT-Auth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## post_game_owners + +> post_game_owners(game_id, own_game) +Own this game + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**game_id** | **String** | Uuid of game to own. | [required] | +**own_game** | Option<[**OwnGame**](OwnGame.md)> | | | ### Return type @@ -474,21 +478,22 @@ Name | Type | Description | Required | Notes [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) -## owned_games_get - -> Vec owned_games_get(user_id) +## post_gamenight_participants +> post_gamenight_participants(gamenight_id, user_id) +Add a participant ### Parameters Name | Type | Description | Required | Notes ------------- | ------------- | ------------- | ------------- | ------------- +**gamenight_id** | **String** | Uuid of gamenight to add participants for. | [required] | **user_id** | Option<[**UserId**](UserId.md)> | | | ### Return type -[**Vec**](OwnedGame.md) + (empty response body) ### Authorization @@ -502,40 +507,10 @@ Name | Type | Description | Required | Notes [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) -## participants_get - -> models::Participants participants_get(gamenight_id) -Get all participants for a gamenight - -Retrieve the participants of a single gamenight by id. - -### Parameters - - -Name | Type | Description | Required | Notes -------------- | ------------- | ------------- | ------------- | ------------- -**gamenight_id** | Option<[**GamenightId**](GamenightId.md)> | | | - -### Return type - -[**models::Participants**](Participants.md) - -### Authorization - -[JWT-Auth](../README.md#JWT-Auth) - -### HTTP request headers - -- **Content-Type**: application/json -- **Accept**: application/json - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - - -## post_gamenight - -> post_gamenight(add_gamenight_request_body) +## post_gamenights +> post_gamenights(add_gamenight_request_body) +Gets the gamenight Add a gamenight by providing a name and a date, only available when providing an JWT token. @@ -562,10 +537,152 @@ Name | Type | Description | Required | Notes [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) -## post_register +## post_games -> post_register(registration) +> models::GameId post_games(add_game_request_body) +add a game +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**add_game_request_body** | Option<[**AddGameRequestBody**](AddGameRequestBody.md)> | | | + +### Return type + +[**models::GameId**](GameId.md) + +### Authorization + +[JWT-Auth](../README.md#JWT-Auth) + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## post_location_authorized_users + +> post_location_authorized_users(location_id, user_id) +Authorize a user + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**location_id** | **String** | Uuid location to authorize for. | [required] | +**user_id** | Option<[**UserId**](UserId.md)> | | | + +### Return type + + (empty response body) + +### Authorization + +[JWT-Auth](../README.md#JWT-Auth) + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## post_locations + +> models::LocationId post_locations(add_location_request_body) +add a location + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**add_location_request_body** | Option<[**AddLocationRequestBody**](AddLocationRequestBody.md)> | | | + +### Return type + +[**models::LocationId**](LocationId.md) + +### Authorization + +[JWT-Auth](../README.md#JWT-Auth) + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## post_refresh_token + +> models::Token post_refresh_token() +Refresh a user token + +Refresh your JWT-token without logging in again. + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +[**models::Token**](Token.md) + +### Authorization + +[JWT-Auth](../README.md#JWT-Auth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## post_token + +> models::Token post_token(login) +Login a user. + +Submit your credentials to get a JWT-token to use with the rest of the api. + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**login** | Option<[**Login**](Login.md)> | | | + +### Return type + +[**models::Token**](Token.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## post_users + +> post_users(registration) +Registers a user into gamenight. Create a new user given a registration token and user information, username and email must be unique, and password and password_repeat must match. @@ -592,44 +709,18 @@ Name | Type | Description | Required | Notes [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) -## post_token - -> models::Token post_token() - - -Refresh your JWT-token without logging in again. - -### Parameters - -This endpoint does not need any parameter. - -### Return type - -[**models::Token**](Token.md) - -### Authorization - -[JWT-Auth](../README.md#JWT-Auth) - -### HTTP request headers - -- **Content-Type**: Not defined -- **Accept**: application/json - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - - -## rename_game_post - -> rename_game_post(rename_game_request_body) +## put_game +> put_game(game_id, edit_game_request_body) +Changes this game resource ### Parameters Name | Type | Description | Required | Notes ------------- | ------------- | ------------- | ------------- | ------------- -**rename_game_request_body** | Option<[**RenameGameRequestBody**](RenameGameRequestBody.md)> | | | +**game_id** | **String** | Uuid of game to change. | [required] | +**edit_game_request_body** | Option<[**EditGameRequestBody**](EditGameRequestBody.md)> | | | ### Return type @@ -646,58 +737,3 @@ Name | Type | Description | Required | Notes [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - -## user_get - -> models::User user_get(user_id) - - -Get a user from primary id - -### Parameters - - -Name | Type | Description | Required | Notes -------------- | ------------- | ------------- | ------------- | ------------- -**user_id** | Option<[**UserId**](UserId.md)> | | | - -### Return type - -[**models::User**](User.md) - -### Authorization - -[JWT-Auth](../README.md#JWT-Auth) - -### HTTP request headers - -- **Content-Type**: application/json -- **Accept**: application/json - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - - -## users_get - -> Vec users_get() - - -### Parameters - -This endpoint does not need any parameter. - -### Return type - -[**Vec**](User.md) - -### Authorization - -[JWT-Auth](../README.md#JWT-Auth) - -### HTTP request headers - -- **Content-Type**: Not defined -- **Accept**: application/json - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - diff --git a/gamenight-api-client-rs/docs/EditGameRequestBody.md b/gamenight-api-client-rs/docs/EditGameRequestBody.md new file mode 100644 index 0000000..4d1e645 --- /dev/null +++ b/gamenight-api-client-rs/docs/EditGameRequestBody.md @@ -0,0 +1,12 @@ +# EditGameRequestBody + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | **String** | | +**name** | **String** | | + +[[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/docs/OwnGame.md b/gamenight-api-client-rs/docs/OwnGame.md new file mode 100644 index 0000000..a6acd0a --- /dev/null +++ b/gamenight-api-client-rs/docs/OwnGame.md @@ -0,0 +1,12 @@ +# OwnGame + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**user_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/docs/OwnedGame.md b/gamenight-api-client-rs/docs/OwnedGame.md index ee2055e..16367ca 100644 --- a/gamenight-api-client-rs/docs/OwnedGame.md +++ b/gamenight-api-client-rs/docs/OwnedGame.md @@ -4,6 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**user_id** | **String** | | **game_id** | **String** | | **location_id** | Option<**String**> | | [optional] diff --git a/gamenight-api-client-rs/src/apis/default_api.rs b/gamenight-api-client-rs/src/apis/default_api.rs index 40d4169..4f5a1e8 100644 --- a/gamenight-api-client-rs/src/apis/default_api.rs +++ b/gamenight-api-client-rs/src/apis/default_api.rs @@ -20,125 +20,130 @@ use crate::apis::ContentType; #[async_trait] pub trait DefaultApi: Send + Sync { - /// GET /authorized_location_user_ids + /// DELETE /game/{gameId} /// /// - async fn authorized_location_user_ids_get<'location_id>(&self, location_id: Option) -> Result, Error>; + async fn delete_game<'game_id>(&self, game_id: &'game_id str) -> Result<(), Error>; - /// POST /disown + /// DELETE /game/{gameId}/owner/{userId} /// /// - async fn disown_post<'game_id>(&self, game_id: Option) -> Result<(), Error>; + async fn delete_game_owner<'game_id, 'user_id>(&self, game_id: &'game_id str, user_id: &'user_id str) -> Result<(), Error>; - /// DELETE /game + /// DELETE /gamenight/{gamenightId}/participant/{userId} /// /// - async fn game_delete<'game_id>(&self, game_id: Option) -> Result<(), Error>; + async fn delete_gamenight_participant<'gamenight_id, 'user_id>(&self, gamenight_id: &'gamenight_id str, user_id: &'user_id str) -> Result<(), Error>; - /// GET /game + /// DELETE /location/{locationId}/authorized_user/{userId} /// /// - async fn game_get<'game_id>(&self, game_id: Option) -> Result>; + async fn delete_location_authorized_user<'location_id, 'user_id>(&self, location_id: &'location_id str, user_id: &'user_id str) -> Result<(), Error>; - /// POST /game + /// GET /game/{gameId} /// /// - async fn game_post<'add_game_request_body>(&self, add_game_request_body: Option) -> Result>; + async fn get_game<'game_id>(&self, game_id: &'game_id str) -> Result>; - /// GET /games + /// GET /gamenight/{gamenightId} /// /// - async fn games_get<>(&self, ) -> Result, Error>; + async fn get_gamenight<'gamenight_id>(&self, gamenight_id: &'gamenight_id str) -> Result>; - /// GET /gamenight + /// GET /gamenight/{gamenightId}/participants /// - /// - async fn get_gamenight<'get_gamenight_request_body>(&self, get_gamenight_request_body: Option) -> Result>; + /// Retrieve the participants of a single gamenight by id. + async fn get_gamenight_participants<'gamenight_id>(&self, gamenight_id: &'gamenight_id str) -> 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 + /// GET /games /// /// - async fn join_post<'gamenight_id>(&self, gamenight_id: Option) -> Result<(), Error>; + async fn get_games<>(&self, ) -> Result, Error>; - /// POST /leave + /// GET /location/{locationId} /// /// - async fn leave_post<'gamenight_id>(&self, gamenight_id: Option) -> Result<(), Error>; + async fn get_location<'location_id>(&self, location_id: &'location_id str) -> Result>; - /// POST /location_authorize + /// GET /location/{locationId}/authorized_users/ /// /// - 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>; + async fn get_location_authorized_users<'location_id>(&self, location_id: &'location_id str) -> Result, Error>; /// GET /locations /// /// - async fn locations_get<>(&self, ) -> Result, Error>; + async fn get_locations<>(&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 /user/{userId} /// /// Get a user from primary id - async fn user_get<'user_id>(&self, user_id: Option) -> Result>; + async fn get_user<'user_id>(&self, user_id: &'user_id str) -> Result>; + + /// GET /user/{userId}/owned_games + /// + /// + async fn get_user_owned_games<'user_id>(&self, user_id: &'user_id str) -> Result, Error>; /// GET /users /// /// - async fn users_get<>(&self, ) -> Result, Error>; + async fn get_users<>(&self, ) -> Result, Error>; + + /// POST /game/{gameId}/owners + /// + /// + async fn post_game_owners<'game_id, 'own_game>(&self, game_id: &'game_id str, own_game: Option) -> Result<(), Error>; + + /// POST /gamenight/{gamenightId}/participants + /// + /// + async fn post_gamenight_participants<'gamenight_id, 'user_id>(&self, gamenight_id: &'gamenight_id str, user_id: Option) -> Result<(), Error>; + + /// POST /gamenights + /// + /// Add a gamenight by providing a name and a date, only available when providing an JWT token. + async fn post_gamenights<'add_gamenight_request_body>(&self, add_gamenight_request_body: Option) -> Result<(), Error>; + + /// POST /games + /// + /// + async fn post_games<'add_game_request_body>(&self, add_game_request_body: Option) -> Result>; + + /// POST /location/{locationId}/authorized_users/ + /// + /// + async fn post_location_authorized_users<'location_id, 'user_id>(&self, location_id: &'location_id str, user_id: Option) -> Result<(), Error>; + + /// POST /locations + /// + /// + async fn post_locations<'add_location_request_body>(&self, add_location_request_body: Option) -> Result>; + + /// POST /refresh_token + /// + /// Refresh your JWT-token without logging in again. + async fn post_refresh_token<>(&self, ) -> Result>; + + /// POST /token + /// + /// Submit your credentials to get a JWT-token to use with the rest of the api. + async fn post_token<'login>(&self, login: Option) -> Result>; + + /// POST /users + /// + /// 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_users<'registration>(&self, registration: Option) -> Result<(), Error>; + + /// PUT /game/{gameId} + /// + /// + async fn put_game<'game_id, 'edit_game_request_body>(&self, game_id: &'game_id str, edit_game_request_body: Option) -> Result<(), Error>; } pub struct DefaultApiClient { @@ -155,84 +160,12 @@ impl DefaultApiClient { #[async_trait] impl DefaultApi for DefaultApiClient { - async fn authorized_location_user_ids_get<'location_id>(&self, location_id: Option) -> Result, Error> { + async fn delete_game<'game_id>(&self, game_id: &'game_id str) -> 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 local_var_uri_str = format!("{}/game/{gameId}", local_var_configuration.base_path, gameId=crate::apis::urlencode(game_id)); 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 { @@ -241,7 +174,6 @@ impl DefaultApi for DefaultApiClient { 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?; @@ -252,18 +184,108 @@ impl DefaultApi for DefaultApiClient { 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_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> { + async fn delete_game_owner<'game_id, 'user_id>(&self, game_id: &'game_id str, user_id: &'user_id str) -> 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 local_var_uri_str = format!("{}/game/{gameId}/owner/{userId}", local_var_configuration.base_path, gameId=crate::apis::urlencode(game_id), userId=crate::apis::urlencode(user_id)); + 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()); + }; + + 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 delete_gamenight_participant<'gamenight_id, 'user_id>(&self, gamenight_id: &'gamenight_id str, user_id: &'user_id str) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/gamenight/{gamenightId}/participant/{userId}", local_var_configuration.base_path, gamenightId=crate::apis::urlencode(gamenight_id), userId=crate::apis::urlencode(user_id)); + 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()); + }; + + 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 delete_location_authorized_user<'location_id, 'user_id>(&self, location_id: &'location_id str, user_id: &'user_id str) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/location/{locationId}/authorized_user/{userId}", local_var_configuration.base_path, locationId=crate::apis::urlencode(location_id), userId=crate::apis::urlencode(user_id)); + 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()); + }; + + 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 get_game<'game_id>(&self, game_id: &'game_id str) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/game/{gameId}", local_var_configuration.base_path, gameId=crate::apis::urlencode(game_id)); 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 { @@ -272,7 +294,6 @@ impl DefaultApi for DefaultApiClient { 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?; @@ -293,59 +314,18 @@ impl DefaultApi for DefaultApiClient { 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_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> { + async fn get_gamenight<'gamenight_id>(&self, gamenight_id: &'gamenight_id str) -> 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 local_var_uri_str = format!("{}/gamenight/{gamenightId}", local_var_configuration.base_path, gamenightId=crate::apis::urlencode(gamenight_id)); 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 { @@ -367,47 +347,6 @@ impl DefaultApi for DefaultApiClient { 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), @@ -421,6 +360,47 @@ impl DefaultApi for DefaultApiClient { } } + /// Retrieve the participants of a single gamenight by id. + async fn get_gamenight_participants<'gamenight_id>(&self, gamenight_id: &'gamenight_id str) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/gamenight/{gamenightId}/participants", local_var_configuration.base_path, gamenightId=crate::apis::urlencode(gamenight_id)); + 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 `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)) + } + } + /// Retrieve the list of gamenights on this gamenight server. Requires authorization. async fn get_gamenights<>(&self, ) -> Result, Error> { let local_var_configuration = &self.configuration; @@ -462,19 +442,20 @@ impl DefaultApi for DefaultApiClient { } } - /// 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> { + async fn get_games<>(&self, ) -> Result, Error> { 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 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()); } - local_var_req_builder = local_var_req_builder.json(&login); + 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?; @@ -491,115 +472,22 @@ impl DefaultApi for DefaultApiClient { 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`")))), + 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_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> { + async fn get_location<'location_id>(&self, location_id: &'location_id str) -> Result> { 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 local_var_uri_str = format!("{}/location/{locationId}", local_var_configuration.base_path, locationId=crate::apis::urlencode(location_id)); 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 { @@ -608,7 +496,6 @@ impl DefaultApi for DefaultApiClient { 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?; @@ -629,19 +516,19 @@ impl DefaultApi for DefaultApiClient { 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_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> { + async fn get_location_authorized_users<'location_id>(&self, location_id: &'location_id str) -> Result, Error> { 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()); + let local_var_uri_str = format!("{}/location/{locationId}/authorized_users/", local_var_configuration.base_path, locationId=crate::apis::urlencode(location_id)); + 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()); @@ -649,7 +536,6 @@ impl DefaultApi for DefaultApiClient { 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?; @@ -666,17 +552,17 @@ impl DefaultApi for DefaultApiClient { 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`")))), + 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_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> { + async fn get_locations<>(&self, ) -> Result, Error> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -710,269 +596,19 @@ impl DefaultApi for DefaultApiClient { 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_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> { + async fn get_user<'user_id>(&self, user_id: &'user_id str) -> 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 local_var_uri_str = format!("{}/user/{userId}", local_var_configuration.base_path, userId=crate::apis::urlencode(user_id)); 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 { @@ -981,7 +617,6 @@ impl DefaultApi for DefaultApiClient { 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?; @@ -1002,13 +637,53 @@ impl DefaultApi for DefaultApiClient { 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_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> { + async fn get_user_owned_games<'user_id>(&self, user_id: &'user_id str) -> Result, Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/user/{userId}/owned_games", local_var_configuration.base_path, userId=crate::apis::urlencode(user_id)); + 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::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)) + } + } + + async fn get_users<>(&self, ) -> Result, Error> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -1042,7 +717,357 @@ impl DefaultApi for DefaultApiClient { 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_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 post_game_owners<'game_id, 'own_game>(&self, game_id: &'game_id str, own_game: Option) -> Result<(), Error> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/game/{gameId}/owners", local_var_configuration.base_path, gameId=crate::apis::urlencode(game_id)); + 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); + + 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 post_gamenight_participants<'gamenight_id, 'user_id>(&self, gamenight_id: &'gamenight_id str, 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!("{}/gamenight/{gamenightId}/participants", local_var_configuration.base_path, gamenightId=crate::apis::urlencode(gamenight_id)); + 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(&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 = 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)) + } + } + + /// Add a gamenight by providing a name and a date, only available when providing an JWT token. + async fn post_gamenights<'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!("{}/gamenights", 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)) + } + } + + async fn post_games<'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!("{}/games", 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 post_location_authorized_users<'location_id, 'user_id>(&self, location_id: &'location_id str, 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!("{}/location/{locationId}/authorized_users/", local_var_configuration.base_path, locationId=crate::apis::urlencode(location_id)); + 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(&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 = 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 post_locations<'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!("{}/locations", 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)) + } + } + + /// Refresh your JWT-token without logging in again. + async fn post_refresh_token<>(&self, ) -> Result> { + let local_var_configuration = &self.configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/refresh_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)) + } + } + + /// Submit your credentials to get a JWT-token to use with the rest of the api. + async fn post_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::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()); + } + 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)) + } + } + + /// 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_users<'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!("{}/users", 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)) + } + } + + async fn put_game<'game_id, 'edit_game_request_body>(&self, game_id: &'game_id str, edit_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!("{}/game/{gameId}", local_var_configuration.base_path, gameId=crate::apis::urlencode(game_id)); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, 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(&edit_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)) } @@ -1050,55 +1075,46 @@ impl DefaultApi for DefaultApiClient { } -/// struct for typed errors of method [`DefaultApi::authorized_location_user_ids_get`] +/// struct for typed errors of method [`DefaultApi::delete_game`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] -pub enum AuthorizedLocationUserIdsGetError { +pub enum DeleteGameError { Status401(models::Failure), Status422(models::Failure), UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`DefaultApi::disown_post`] +/// struct for typed errors of method [`DefaultApi::delete_game_owner`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] -pub enum DisownPostError { +pub enum DeleteGameOwnerError { Status401(models::Failure), Status422(models::Failure), UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`DefaultApi::game_delete`] +/// struct for typed errors of method [`DefaultApi::delete_gamenight_participant`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] -pub enum GameDeleteError { +pub enum DeleteGamenightParticipantError { Status401(models::Failure), Status422(models::Failure), UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`DefaultApi::game_get`] +/// struct for typed errors of method [`DefaultApi::delete_location_authorized_user`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] -pub enum GameGetError { +pub enum DeleteLocationAuthorizedUserError { Status401(models::Failure), Status422(models::Failure), UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`DefaultApi::game_post`] +/// struct for typed errors of method [`DefaultApi::get_game`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] -pub enum GamePostError { - Status401(models::Failure), - Status422(models::Failure), - UnknownValue(serde_json::Value), -} - -/// struct for typed errors of method [`DefaultApi::games_get`] -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(untagged)] -pub enum GamesGetError { +pub enum GetGameError { Status401(models::Failure), Status422(models::Failure), UnknownValue(serde_json::Value), @@ -1113,6 +1129,15 @@ pub enum GetGamenightError { UnknownValue(serde_json::Value), } +/// struct for typed errors of method [`DefaultApi::get_gamenight_participants`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetGamenightParticipantsError { + Status400(models::Failure), + Status401(models::Failure), + UnknownValue(serde_json::Value), +} + /// struct for typed errors of method [`DefaultApi::get_gamenights`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -1122,112 +1147,132 @@ pub enum GetGamenightsError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`DefaultApi::get_token`] +/// struct for typed errors of method [`DefaultApi::get_games`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] -pub enum GetTokenError { - Status401(models::Failure), - UnknownValue(serde_json::Value), -} - -/// struct for typed errors of method [`DefaultApi::join_post`] -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(untagged)] -pub enum JoinPostError { +pub enum GetGamesError { Status401(models::Failure), Status422(models::Failure), UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`DefaultApi::leave_post`] +/// struct for typed errors of method [`DefaultApi::get_location`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] -pub enum LeavePostError { +pub enum GetLocationError { Status401(models::Failure), Status422(models::Failure), UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`DefaultApi::location_authorize_post`] +/// struct for typed errors of method [`DefaultApi::get_location_authorized_users`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] -pub enum LocationAuthorizePostError { +pub enum GetLocationAuthorizedUsersError { Status401(models::Failure), Status422(models::Failure), UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`DefaultApi::location_get`] +/// struct for typed errors of method [`DefaultApi::get_locations`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] -pub enum LocationGetError { +pub enum GetLocationsError { Status401(models::Failure), Status422(models::Failure), UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`DefaultApi::location_post`] +/// struct for typed errors of method [`DefaultApi::get_user`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] -pub enum LocationPostError { +pub enum GetUserError { + Status401(models::Failure), + Status404(models::Failure), + Status422(models::Failure), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`DefaultApi::get_user_owned_games`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetUserOwnedGamesError { Status401(models::Failure), Status422(models::Failure), UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`DefaultApi::locations_get`] +/// struct for typed errors of method [`DefaultApi::get_users`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] -pub enum LocationsGetError { - Status401(models::Failure), - Status422(models::Failure), - UnknownValue(serde_json::Value), -} - -/// struct for typed errors of method [`DefaultApi::own_post`] -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(untagged)] -pub enum OwnPostError { - Status401(models::Failure), - Status422(models::Failure), - UnknownValue(serde_json::Value), -} - -/// struct for typed errors of method [`DefaultApi::owned_games_get`] -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(untagged)] -pub enum OwnedGamesGetError { - Status401(models::Failure), - Status422(models::Failure), - UnknownValue(serde_json::Value), -} - -/// struct for typed errors of method [`DefaultApi::participants_get`] -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(untagged)] -pub enum ParticipantsGetError { +pub enum GetUsersError { Status400(models::Failure), Status401(models::Failure), UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`DefaultApi::post_gamenight`] +/// struct for typed errors of method [`DefaultApi::post_game_owners`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] -pub enum PostGamenightError { +pub enum PostGameOwnersError { Status401(models::Failure), Status422(models::Failure), UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`DefaultApi::post_register`] +/// struct for typed errors of method [`DefaultApi::post_gamenight_participants`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] -pub enum PostRegisterError { +pub enum PostGamenightParticipantsError { + Status401(models::Failure), Status422(models::Failure), UnknownValue(serde_json::Value), } +/// struct for typed errors of method [`DefaultApi::post_gamenights`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum PostGamenightsError { + Status401(models::Failure), + Status422(models::Failure), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`DefaultApi::post_games`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum PostGamesError { + Status401(models::Failure), + Status422(models::Failure), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`DefaultApi::post_location_authorized_users`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum PostLocationAuthorizedUsersError { + Status401(models::Failure), + Status422(models::Failure), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`DefaultApi::post_locations`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum PostLocationsError { + Status401(models::Failure), + Status422(models::Failure), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`DefaultApi::post_refresh_token`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum PostRefreshTokenError { + Status401(models::Failure), + UnknownValue(serde_json::Value), +} + /// struct for typed errors of method [`DefaultApi::post_token`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -1236,31 +1281,20 @@ pub enum PostTokenError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`DefaultApi::rename_game_post`] +/// struct for typed errors of method [`DefaultApi::post_users`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] -pub enum RenameGamePostError { +pub enum PostUsersError { + Status422(models::Failure), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`DefaultApi::put_game`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum PutGameError { Status401(models::Failure), Status422(models::Failure), UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`DefaultApi::user_get`] -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(untagged)] -pub enum UserGetError { - Status401(models::Failure), - Status404(models::Failure), - Status422(models::Failure), - UnknownValue(serde_json::Value), -} - -/// struct for typed errors of method [`DefaultApi::users_get`] -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(untagged)] -pub enum UsersGetError { - Status400(models::Failure), - Status401(models::Failure), - UnknownValue(serde_json::Value), -} - diff --git a/gamenight-api-client-rs/src/models/edit_game_request_body.rs b/gamenight-api-client-rs/src/models/edit_game_request_body.rs new file mode 100644 index 0000000..46099f2 --- /dev/null +++ b/gamenight-api-client-rs/src/models/edit_game_request_body.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 EditGameRequestBody { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "name")] + pub name: String, +} + +impl EditGameRequestBody { + pub fn new(id: String, name: String) -> EditGameRequestBody { + EditGameRequestBody { + id, + name, + } + } +} + diff --git a/gamenight-api-client-rs/src/models/mod.rs b/gamenight-api-client-rs/src/models/mod.rs index 8189728..8c8ce65 100644 --- a/gamenight-api-client-rs/src/models/mod.rs +++ b/gamenight-api-client-rs/src/models/mod.rs @@ -4,8 +4,8 @@ pub mod add_gamenight_request_body; pub use self::add_gamenight_request_body::AddGamenightRequestBody; pub mod add_location_request_body; pub use self::add_location_request_body::AddLocationRequestBody; -pub mod authorize_location_request_body; -pub use self::authorize_location_request_body::AuthorizeLocationRequestBody; +pub mod edit_game_request_body; +pub use self::edit_game_request_body::EditGameRequestBody; pub mod failure; pub use self::failure::Failure; pub mod game; @@ -16,24 +16,20 @@ pub mod gamenight; pub use self::gamenight::Gamenight; pub mod gamenight_id; pub use self::gamenight_id::GamenightId; -pub mod get_gamenight_request_body; -pub use self::get_gamenight_request_body::GetGamenightRequestBody; pub mod location; pub use self::location::Location; pub mod location_id; pub use self::location_id::LocationId; pub mod login; pub use self::login::Login; -pub mod own_game_request_body; -pub use self::own_game_request_body::OwnGameRequestBody; +pub mod own_game; +pub use self::own_game::OwnGame; pub mod owned_game; pub use self::owned_game::OwnedGame; pub mod participants; pub use self::participants::Participants; pub mod registration; pub use self::registration::Registration; -pub mod rename_game_request_body; -pub use self::rename_game_request_body::RenameGameRequestBody; pub mod token; pub use self::token::Token; pub mod user; diff --git a/gamenight-api-client-rs/src/models/own_game.rs b/gamenight-api-client-rs/src/models/own_game.rs new file mode 100644 index 0000000..8acf920 --- /dev/null +++ b/gamenight-api-client-rs/src/models/own_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 OwnGame { + #[serde(rename = "user_id")] + pub user_id: String, + #[serde(rename = "location_id", skip_serializing_if = "Option::is_none")] + pub location_id: Option, +} + +impl OwnGame { + pub fn new(user_id: String) -> OwnGame { + OwnGame { + user_id, + location_id: None, + } + } +} + diff --git a/gamenight-api-client-rs/src/models/owned_game.rs b/gamenight-api-client-rs/src/models/owned_game.rs index e329344..1828b1d 100644 --- a/gamenight-api-client-rs/src/models/owned_game.rs +++ b/gamenight-api-client-rs/src/models/owned_game.rs @@ -13,6 +13,8 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] pub struct OwnedGame { + #[serde(rename = "user_id")] + pub user_id: String, #[serde(rename = "game_id")] pub game_id: String, #[serde(rename = "location_id", skip_serializing_if = "Option::is_none")] @@ -20,8 +22,9 @@ pub struct OwnedGame { } impl OwnedGame { - pub fn new(game_id: String) -> OwnedGame { + pub fn new(user_id: String, game_id: String) -> OwnedGame { OwnedGame { + user_id, game_id, location_id: None, } diff --git a/gamenight-cli/src/flows/add_game.rs b/gamenight-cli/src/flows/add_game.rs index 7b2327a..a5c33b0 100644 --- a/gamenight-cli/src/flows/add_game.rs +++ b/gamenight-cli/src/flows/add_game.rs @@ -24,7 +24,7 @@ impl<'a> Flow<'a> for AddGame { let add_game_request = AddGameRequestBody { name }; - let game_id_response = state.api.game_post(Some(add_game_request)).await?; + let game_id_response = state.api.post_games(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 3564705..46abf4c 100644 --- a/gamenight-cli/src/flows/add_gamenight.rs +++ b/gamenight-cli/src/flows/add_gamenight.rs @@ -31,7 +31,7 @@ impl<'a> Flow<'a> for AddGamenight { .to_utc() .to_rfc3339(); let add_gamenight = models::AddGamenightRequestBody::new(name, datetime); - state.api.post_gamenight(Some(add_gamenight)).await?; + state.api.post_gamenights(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 27b9a38..1d24be5 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::models::{authorize_location_request_body::Op::Grant, AddLocationRequestBody, AuthorizeLocationRequestBody}; +use gamenight_api_client_rs::models::{AddLocationRequestBody, UserId}; use inquire::{Editor, Text}; @@ -44,15 +44,13 @@ impl<'a> Flow<'a> for AddLocation { note }; - let location_id = state.api.location_post(Some(add_location_request)).await?; + let result = state.api.post_locations(Some(add_location_request)).await?; - let add_authorize_request = AuthorizeLocationRequestBody { - location_id: location_id.location_id.to_string(), - user_id: state.get_user_id()?.to_string(), - op: Grant + let user_id = UserId { + user_id: state.get_user_id()?.to_string() }; - state.api.location_authorize_post(Some(add_authorize_request)).await?; + state.api.post_location_authorized_users(&result.location_id, Some(user_id)).await?; } Ok((FlowOutcome::Cancelled, state)) } diff --git a/gamenight-cli/src/flows/connect.rs b/gamenight-cli/src/flows/connect.rs index 950d364..c7c5d45 100644 --- a/gamenight-cli/src/flows/connect.rs +++ b/gamenight-cli/src/flows/connect.rs @@ -50,7 +50,7 @@ impl Connect { 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 { let state = state.set_bearer_access_token(Some(token.clone())); - let result = state.api.post_token().await; + let result = state.api.post_refresh_token().await; if let Ok(token) = result { let instance = state.gamenight_configuration.instances.iter_mut().find(|x| x.name == *instance_name).unwrap(); instance.token = token.jwt_token.clone(); diff --git a/gamenight-cli/src/flows/disown.rs b/gamenight-cli/src/flows/disown.rs index 05b566f..3dd81f8 100644 --- a/gamenight-cli/src/flows/disown.rs +++ b/gamenight-cli/src/flows/disown.rs @@ -1,7 +1,6 @@ use std::fmt::Display; use async_trait::async_trait; -use gamenight_api_client_rs::models::GameId; use uuid::Uuid; use super::{Flow, FlowOutcome, FlowResult, GamenightState}; @@ -22,7 +21,7 @@ impl Disown { #[async_trait] impl<'a> Flow<'a> for Disown { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { - let _ = state.api.disown_post(Some(GameId{game_id: self.game_id.to_string()})).await?; + let _ = state.api.delete_game_owner(&self.game_id.to_string(), &state.get_user_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 68c1d6f..dac0729 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::models::GamenightId; +use gamenight_api_client_rs::models::UserId; 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 _ = state.api.join_post(Some(GamenightId{gamenight_id: self.gamenight_id.to_string()})).await?; + let _ = state.api.post_gamenight_participants(&self.gamenight_id.to_string(), Some(UserId{user_id: state.get_user_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 b475d89..1c0e9e7 100644 --- a/gamenight-cli/src/flows/leave.rs +++ b/gamenight-cli/src/flows/leave.rs @@ -1,7 +1,6 @@ use std::fmt::Display; use async_trait::async_trait; -use gamenight_api_client_rs::models::GamenightId; use uuid::Uuid; use super::{Flow, FlowOutcome, FlowResult, GamenightState}; @@ -22,7 +21,7 @@ impl Leave { #[async_trait] impl<'a> Flow<'a> for Leave { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { - let _ = state.api.leave_post(Some(GamenightId{gamenight_id: self.gamenight_id.to_string()})).await?; + let _ = state.api.delete_gamenight_participant(&self.gamenight_id.to_string(), &state.get_user_id()?.to_string()).await?; clear_screen::clear(); Ok((FlowOutcome::Successful, state)) diff --git a/gamenight-cli/src/flows/list_games.rs b/gamenight-cli/src/flows/list_games.rs index 22d2595..8e3979a 100644 --- a/gamenight-cli/src/flows/list_games.rs +++ b/gamenight-cli/src/flows/list_games.rs @@ -21,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 = state.api.games_get().await?; + let games = state.api.get_games().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 f341707..15795d6 100644 --- a/gamenight-cli/src/flows/list_locations.rs +++ b/gamenight-cli/src/flows/list_locations.rs @@ -21,7 +21,7 @@ impl ListLocations { #[async_trait] impl<'a> Flow<'a> for ListLocations { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { - let locations = state.api.locations_get().await?; + let locations = state.api.get_locations().await?; let mut flows = locations.into_iter().map(|location| -> Box { Box::new(ViewLocation::new(location.try_into().unwrap())) diff --git a/gamenight-cli/src/flows/location_authorize.rs b/gamenight-cli/src/flows/location_authorize.rs index 9208436..7754a8a 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::models::{AuthorizeLocationRequestBody, LocationId, User}; +use gamenight_api_client_rs::models::{User, UserId}; use inquire::MultiSelect; use uuid::Uuid; @@ -47,11 +47,9 @@ 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 = state.api.users_get().await?; - let location_id = LocationId { - location_id: self.location_id.to_string() - }; - let authorized_user_ids = state.api.authorized_location_user_ids_get(Some(location_id)).await?; + let users = state.api.get_users().await?; + + let authorized_user_ids = state.api.get_location_authorized_users(&self.location_id.to_string()).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>>()?; @@ -66,25 +64,14 @@ impl<'a> Flow<'a> for LocationAuthorize { if let Some(selections) = &selections { for selection in selections { + let user_id = UserId { user_id: selection.id.to_string() }; if authorized_users.iter().find(|x| {x.id == selection.id.to_string()}).is_none() { - state.api.location_authorize_post(Some( - AuthorizeLocationRequestBody { - location_id: self.location_id.to_string(), - user_id: selection.id.to_string(), - op: gamenight_api_client_rs::models::authorize_location_request_body::Op::Grant - } - )).await? + state.api.post_location_authorized_users(&self.location_id.to_string(), Some(user_id)).await? } } for authorized_user in authorized_users { if selections.iter().find(|x| {x.id.to_string() == authorized_user.id}).is_none() { - state.api.location_authorize_post(Some( - AuthorizeLocationRequestBody { - location_id: self.location_id.to_string(), - user_id: authorized_user.id.to_string(), - op: gamenight_api_client_rs::models::authorize_location_request_body::Op::Revoke - } - )).await? + state.api.delete_location_authorized_user(&self.location_id.to_string(), &authorized_user.id.to_string()).await? } } } diff --git a/gamenight-cli/src/flows/login.rs b/gamenight-cli/src/flows/login.rs index a5f8579..e04c9e6 100644 --- a/gamenight-cli/src/flows/login.rs +++ b/gamenight-cli/src/flows/login.rs @@ -26,7 +26,7 @@ impl<'a> Flow<'a> for Login { let login = models::Login::new(username, password); - let result = state.api.get_token(Some(login)).await?; + let result = state.api.post_token(Some(login)).await?; clear_screen::clear(); if let Some(token) = result.jwt_token { diff --git a/gamenight-cli/src/flows/own.rs b/gamenight-cli/src/flows/own.rs index b80aa0b..bd20119 100644 --- a/gamenight-cli/src/flows/own.rs +++ b/gamenight-cli/src/flows/own.rs @@ -3,7 +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::models::OwnGameRequestBody; +use gamenight_api_client_rs::models::OwnGame; use inquire::{Confirm, Select}; use uuid::Uuid; @@ -24,8 +24,8 @@ impl Own { impl<'a> Flow<'a> for Own { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { - let mut own_game_request = OwnGameRequestBody { - game_id: self.game_id.to_string(), + let mut own_game_request = OwnGame { + user_id: state.get_user_id()?.to_string(), location_id: None }; @@ -33,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 = state.api.locations_get().await?.iter().map(|x| { x.try_into() }).collect::, FlowError>>()?; + let locations = state.api.get_locations().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 _ = state.api.own_post(Some(own_game_request)).await?; + let _ = state.api.post_game_owners(&self.game_id.to_string(), Some(own_game_request)).await?; } } diff --git a/gamenight-cli/src/flows/remove_game.rs b/gamenight-cli/src/flows/remove_game.rs index 72205cd..075e126 100644 --- a/gamenight-cli/src/flows/remove_game.rs +++ b/gamenight-cli/src/flows/remove_game.rs @@ -1,7 +1,6 @@ use std::fmt::Display; use async_trait::async_trait; -use gamenight_api_client_rs::models::GameId; use super::{Flow, FlowOutcome, FlowResult, GamenightState}; use crate::domain::game::Game; @@ -22,10 +21,7 @@ impl RemoveGame { #[async_trait] impl<'a> Flow<'a> for RemoveGame { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { - let req = GameId { - game_id: self.game.id.to_string() - }; - state.api.game_delete(Some(req)).await?; + state.api.delete_game(&self.game.id.to_string()).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 3da8b04..000c067 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::models::RenameGameRequestBody; +use gamenight_api_client_rs::models::EditGameRequestBody; use inquire::Text; use crate::domain::game::Game; @@ -28,11 +28,11 @@ impl<'a> Flow<'a> for RenameGame { .with_initial_value(&self.game.name) .prompt_skippable()? { - let req = RenameGameRequestBody { + let req = EditGameRequestBody { id: self.game.id.to_string(), name }; - state.api.rename_game_post(Some(req)).await?; + state.api.put_game(&req.id.clone(), 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 9451007..8299233 100644 --- a/gamenight-cli/src/flows/view_game.rs +++ b/gamenight-cli/src/flows/view_game.rs @@ -1,11 +1,9 @@ - -use gamenight_api_client_rs::models::{GameId, UserId}; use inquire::Select; use uuid::Uuid; -use crate::{domain::game::Game, flows::{disown::Disown, exit::Exit, own::Own, rename_game::RenameGame}}; -use crate::flows::remove_game::RemoveGame; use super::*; +use crate::flows::remove_game::RemoveGame; +use crate::{domain::game::Game, flows::{disown::Disown, exit::Exit, own::Own, rename_game::RenameGame}}; #[derive(Clone)] pub struct ViewGame { @@ -23,14 +21,10 @@ impl ViewGame { #[async_trait] 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 = state.api.game_get(Some(game_id)).await?.into(); + let game: Game = state.api.get_game(&self.game.id.to_string()).await?.into(); println!("{}", game); - - let my_uid = state.get_user_id()?; - let request = UserId{ user_id: my_uid.to_string() }; - let owned_games: Vec = state.api.owned_games_get(Some(request)).await? + let owned_games: Vec = state.api.get_user_owned_games(&state.get_user_id()?.to_string()).await? .iter().map(|x| -> Result { Ok(Uuid::parse_str(&x.game_id)?) }).collect::, FlowError>>()?; diff --git a/gamenight-cli/src/flows/view_gamenight.rs b/gamenight-cli/src/flows/view_gamenight.rs index 90ae61e..98c7e97 100644 --- a/gamenight-cli/src/flows/view_gamenight.rs +++ b/gamenight-cli/src/flows/view_gamenight.rs @@ -1,7 +1,7 @@ use crate::domain::gamenight::Gamenight; use std::collections::HashMap; -use gamenight_api_client_rs::models::{GameId, GamenightId, LocationId, OwnedGame, UserId}; +use gamenight_api_client_rs::models::OwnedGame; use inquire::Select; use super::*; @@ -29,30 +29,29 @@ impl<'a> Flow<'a> for ViewGamenight { start_time: self.gamenight_select_data.start_time, name: self.gamenight_select_data.name.clone(), location: None, - organizer: state.api.user_get(Some(UserId{user_id: self.gamenight_select_data.owner_id.to_string()})).await?.try_into()?, + organizer: state.api.get_user(&self.gamenight_select_data.owner_id.to_string()).await?.try_into()?, participants: Participants(vec![]), owned_games: OwnedGames(HashMap::new()) }; 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()?) + Some(l) => Some(state.api.get_location(&l.to_string()).await?.try_into()?) }; - let participants = state.api.participants_get(Some(GamenightId{gamenight_id: gamenight.id.to_string()})).await?; + let participants = state.api.get_gamenight_participants(&gamenight.id.to_string()).await?; for participant in participants.participants.iter() { - gamenight.participants.0.push(state.api.user_get(Some(UserId{user_id: participant.clone()})).await?.try_into()?); + gamenight.participants.0.push(state.api.get_user(&participant).await?.try_into()?); } for user in &gamenight.participants.0 { - let request = UserId{ user_id: user.id.to_string() }; - let owned_games_refs: Vec = state.api.owned_games_get(Some(request)).await?; + let owned_games_refs: Vec = state.api.get_user_owned_games(&user.id.to_string()).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 game = state.api.get_game(&owned_games_ref.game_id).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()?) + Some(x) => Some(state.api.get_location(&x).await?.try_into()?) }; owned_games.push((game, location)); } diff --git a/gamenight-database/src/owned_game.rs b/gamenight-database/src/owned_game.rs index a76925d..0d51d7f 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, owned_game::location_id)) + .select((owned_game::user_id, owned_game::game_id, owned_game::location_id)) .filter(owned_game::user_id.eq(uuid)) .get_results(conn)?) }