Adds renaming games functionality

This commit is contained in:
Dennis Brentjes 2025-07-12 17:07:33 +02:00
parent 28f7306d57
commit 3f99b68d62
30 changed files with 502 additions and 178 deletions

163
backend-actix/Cargo.lock generated
View File

@ -318,9 +318,9 @@ dependencies = [
[[package]]
name = "autocfg"
version = "1.4.0"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]]
name = "backend-actix"
@ -414,9 +414,9 @@ dependencies = [
[[package]]
name = "bumpalo"
version = "3.18.1"
version = "3.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "793db76d6187cd04dff33004d8e6c9cc4e05cd330500379d2394209271b4aeee"
checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
[[package]]
name = "byteorder"
@ -441,9 +441,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.2.26"
version = "1.2.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "956a5e21988b87f372569b66183b78babf23ebc2e744b733e4350a752c4dafac"
checksum = "5c1599538de2394445747c8cf7935946e3cc27e9625f889d979bfb2aaf569362"
dependencies = [
"jobserver",
"libc",
@ -589,9 +589,9 @@ dependencies = [
[[package]]
name = "diesel"
version = "2.2.10"
version = "2.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff3e1edb1f37b4953dd5176916347289ed43d7119cc2e6c7c3f7849ff44ea506"
checksum = "229850a212cd9b84d4f0290ad9d294afc0ae70fccaa8949dbe8b43ffafa1e20c"
dependencies = [
"bitflags",
"byteorder",
@ -617,9 +617,9 @@ dependencies = [
[[package]]
name = "diesel_derives"
version = "2.2.5"
version = "2.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68d4216021b3ea446fd2047f5c8f8fe6e98af34508a254a01e4d6bc1e844f84d"
checksum = "1b96984c469425cb577bf6f17121ecb3e4fe1e81de5d8f780dd372802858d756"
dependencies = [
"diesel_table_macro_syntax",
"dsl_auto_type",
@ -847,9 +847,9 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
[[package]]
name = "h2"
version = "0.3.26"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8"
checksum = "0beca50380b1fc32983fc1cb4587bfa4bb9e78fc259aad4a0032d2080309222d"
dependencies = [
"bytes",
"fnv",
@ -1050,14 +1050,25 @@ checksum = "e8a5a9a0ff0086c7a148acb942baaabeadf9504d10400b5a05645853729b9cd2"
[[package]]
name = "indexmap"
version = "2.9.0"
version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e"
checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "io-uring"
version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013"
dependencies = [
"bitflags",
"cfg-if",
"libc",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
@ -1072,9 +1083,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "jiff"
version = "0.2.14"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a194df1107f33c79f4f93d02c80798520551949d59dfad22b6157048a88cca93"
checksum = "be1f93b8b1eb69c77f24bbb0afdf66f54b632ee39af40ca21c4365a1d7347e49"
dependencies = [
"jiff-static",
"log",
@ -1085,9 +1096,9 @@ dependencies = [
[[package]]
name = "jiff-static"
version = "0.2.14"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c6e1db7ed32c6c71b759497fae34bf7933636f75a251b9e736555da426f6442"
checksum = "03343451ff899767262ec32146f6d559dd759fdadf42ff0e227c7c48f72594b4"
dependencies = [
"proc-macro2",
"quote",
@ -1137,9 +1148,9 @@ checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388"
[[package]]
name = "libc"
version = "0.2.172"
version = "0.2.174"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776"
[[package]]
name = "litemap"
@ -1188,9 +1199,9 @@ checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
[[package]]
name = "migrations_internals"
version = "2.2.0"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd01039851e82f8799046eabbb354056283fb265c8ec0996af940f4e85a380ff"
checksum = "3bda1634d70d5bd53553cf15dca9842a396e8c799982a3ad22998dc44d961f24"
dependencies = [
"serde",
"toml",
@ -1424,9 +1435,9 @@ dependencies = [
[[package]]
name = "pq-sys"
version = "0.7.1"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41c852911b98f5981956037b2ca976660612e548986c30af075e753107bc3400"
checksum = "dfd6cf44cca8f9624bc19df234fc4112873432f5fda1caff174527846d026fa9"
dependencies = [
"libc",
"vcpkg",
@ -1474,9 +1485,9 @@ dependencies = [
[[package]]
name = "r-efi"
version = "5.2.0"
version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
[[package]]
name = "r2d2"
@ -1529,9 +1540,9 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.5.12"
version = "0.5.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af"
checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6"
dependencies = [
"bitflags",
]
@ -1652,9 +1663,9 @@ dependencies = [
[[package]]
name = "serde_spanned"
version = "0.6.9"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3"
checksum = "40734c41988f7306bb04f0ecf60ec0f3f1caa34290e4e8ea471dcd3346483b83"
dependencies = [
"serde",
]
@ -1711,12 +1722,9 @@ dependencies = [
[[package]]
name = "slab"
version = "0.4.9"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67"
dependencies = [
"autocfg",
]
checksum = "04dc19736151f35336d325007ac991178d504a119863a2fcb3758cdb5e52c50d"
[[package]]
name = "smallvec"
@ -1754,9 +1762,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "syn"
version = "2.0.102"
version = "2.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6397daf94fa90f058bd0fd88429dd9e5738999cca8d701813c80723add80462"
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
dependencies = [
"proc-macro2",
"quote",
@ -1837,17 +1845,19 @@ dependencies = [
[[package]]
name = "tokio"
version = "1.45.1"
version = "1.46.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75ef51a33ef1da925cea3e4eb122833cb377c61439ca401b770f54902b806779"
checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17"
dependencies = [
"backtrace",
"bytes",
"io-uring",
"libc",
"mio",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"slab",
"socket2",
"windows-sys 0.52.0",
]
@ -1867,44 +1877,42 @@ dependencies = [
[[package]]
name = "toml"
version = "0.8.23"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.22.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a"
checksum = "ed0aee96c12fa71097902e0bb061a5e1ebd766a6636bb605ba401c45c1650eac"
dependencies = [
"indexmap",
"serde",
"serde_spanned",
"toml_datetime",
"toml_write",
"toml_parser",
"toml_writer",
"winnow",
]
[[package]]
name = "toml_write"
version = "0.1.2"
name = "toml_datetime"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801"
checksum = "bade1c3e902f58d73d3f294cd7f20391c1cb2fbcb643b73566bc773971df91e3"
dependencies = [
"serde",
]
[[package]]
name = "toml_parser"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97200572db069e74c512a14117b296ba0a80a30123fbbb5aa1f4a348f639ca30"
dependencies = [
"winnow",
]
[[package]]
name = "toml_writer"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcc842091f2def52017664b53082ecbbeb5c7731092bad69d2c63050401dfd64"
[[package]]
name = "tracing"
@ -1933,9 +1941,9 @@ dependencies = [
[[package]]
name = "tracing-attributes"
version = "0.1.29"
version = "0.1.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1ffbcf9c6f6b99d386e7444eb608ba646ae452a36b39737deb9663b610f662"
checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903"
dependencies = [
"proc-macro2",
"quote",
@ -2162,9 +2170,9 @@ dependencies = [
[[package]]
name = "windows-link"
version = "0.1.1"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38"
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
[[package]]
name = "windows-result"
@ -2268,12 +2276,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "winnow"
version = "0.7.11"
version = "0.7.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74c7b26e3480b707944fc872477815d29a8e429d2f93a1ce000f5fa84a15cbcd"
dependencies = [
"memchr",
]
checksum = "f3edebf492c8125044983378ecb5766203ad3b4c2f7a922bd7dd207f6d443e95"
[[package]]
name = "wit-bindgen-rt"
@ -2316,18 +2321,18 @@ dependencies = [
[[package]]
name = "zerocopy"
version = "0.8.25"
version = "0.8.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb"
checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.25"
version = "0.8.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef"
checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181"
dependencies = [
"proc-macro2",
"quote",

View File

@ -190,6 +190,20 @@ paths:
$ref: '#/components/requestBodies/AddGameRequest'
security:
- JWT-Auth: []
/rename_game:
post:
responses:
'200':
description: "OK"
'401':
$ref: '#/components/responses/FailureResponse'
'422':
$ref: '#/components/responses/FailureResponse'
requestBody:
$ref: '#/components/requestBodies/RenameGameRequest'
security:
- JWT-Auth: []
components:
schemas:
@ -333,7 +347,16 @@ components:
type: string
required:
- name
RenameGameRequestBody:
type: object
properties:
id:
type: string
name:
type: string
required:
- id
- name
requestBodies:
LoginRequest:
content:
@ -385,6 +408,11 @@ components:
application/json:
schema:
$ref: '#/components/schemas/AddGameRequestBody'
RenameGameRequest:
content:
application/json:
schema:
$ref: '#/components/schemas/RenameGameRequestBody'
responses:
TokenResponse:
description: Example response

View File

@ -49,7 +49,9 @@ async fn main() -> std::io::Result<()> {
.service(post_leave_gamenight)
.service(get_get_participants)
.service(get_games)
.service(get_game)
.service(post_game)
.service(post_rename_game)
})
.bind(("::1", 8080))?
.run()

View File

@ -1,8 +1,8 @@
use actix_web::{get, http::header::ContentType, post, web, HttpResponse, Responder};
use gamenight_database::{game::insert_game, DbPool, GetConnection};
use gamenight_database::{game::{insert_game, load_game, rename_game}, DbPool, GetConnection};
use uuid::Uuid;
use crate::{models::{add_game_request_body::AddGameRequestBody, game::Game}, request::{authorization::AuthUser, error::ApiError}};
use crate::{models::{add_game_request_body::AddGameRequestBody, game::Game, game_id::GameId, rename_game_request_body::RenameGameRequestBody}, request::{authorization::AuthUser, error::ApiError}};
#[get("/games")]
pub async fn get_games(pool: web::Data<DbPool>, _user: AuthUser) -> Result<impl Responder, ApiError> {
@ -30,10 +30,34 @@ impl From<AddGameRequestBody> for gamenight_database::game::Game {
}
}
#[get("/game")]
pub async fn get_game(pool: web::Data<DbPool>, _user: AuthUser, game_id: web::Json<GameId>) -> Result<impl Responder, ApiError> {
let mut conn = pool.get_conn();
let db_game = load_game(&mut conn, Uuid::parse_str(&game_id.0.game_id)?)?;
let model = Game {
id: db_game.id.to_string(),
name: db_game.name
};
Ok(HttpResponse::Ok()
.content_type(ContentType::json())
.body(serde_json::to_string(&model)?)
)
}
#[post("/game")]
pub async fn post_game(pool: web::Data<DbPool>, _user: AuthUser, game_data: web::Json<AddGameRequestBody>) -> Result<impl Responder, ApiError> {
let mut conn = pool.get_conn();
insert_game(&mut conn, game_data.0.into())?;
Ok(HttpResponse::Ok())
}
#[post("/rename_game")]
pub async fn post_rename_game(pool: web::Data<DbPool>, _user: AuthUser, game_data: web::Json<RenameGameRequestBody>) -> Result <impl Responder, ApiError> {
let mut conn = pool.get_conn();
rename_game(&mut conn, Uuid::parse_str(&game_data.0.id)?, game_data.0.name)?;
Ok(HttpResponse::Ok())
}

View File

@ -19,4 +19,6 @@ pub use join_gamenight::post_join_gamenight;
pub use join_gamenight::post_leave_gamenight;
pub use participant_handlers::get_get_participants;
pub use game::get_games;
pub use game::get_game;
pub use game::post_game;
pub use game::post_rename_game;

View File

@ -14,6 +14,7 @@ docs/GetGamenightRequestBody.md
docs/Login.md
docs/Participants.md
docs/Registration.md
docs/RenameGameRequestBody.md
docs/Token.md
docs/User.md
docs/UserId.md
@ -34,6 +35,7 @@ src/models/login.rs
src/models/mod.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

View File

@ -1 +1 @@
7.13.0
7.14.0

View File

@ -10,7 +10,7 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
- API version: 1.0
- Package version: 0.1.0
- Generator version: 7.13.0
- Generator version: 7.14.0
- Build package: `org.openapitools.codegen.languages.RustClientCodegen`
## Installation
@ -39,6 +39,7 @@ Class | Method | HTTP request | Description
*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 |
@ -55,6 +56,7 @@ Class | Method | HTTP request | Description
- [Login](docs/Login.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)

View File

@ -16,6 +16,7 @@ Method | HTTP request | Description
[**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 |
@ -359,6 +360,34 @@ 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)
## rename_game_post
> rename_game_post(rename_game_request_body)
### Parameters
Name | Type | Description | Required | Notes
------------- | ------------- | ------------- | ------------- | -------------
**rename_game_request_body** | Option<[**RenameGameRequestBody**](RenameGameRequestBody.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)
## user_get
> models::User user_get(user_id)

View File

@ -0,0 +1,12 @@
# RenameGameRequestBody
## 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)

View File

@ -120,6 +120,15 @@ pub enum PostTokenError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`rename_game_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RenameGamePostError {
Status401(models::Failure),
Status422(models::Failure),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`user_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
@ -550,6 +559,35 @@ pub async fn post_token(configuration: &configuration::Configuration, ) -> Resul
}
}
pub async fn rename_game_post(configuration: &configuration::Configuration, rename_game_request_body: Option<models::RenameGameRequestBody>) -> Result<(), Error<RenameGamePostError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_rename_game_request_body = rename_game_request_body;
let uri_str = format!("{}/rename_game", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_rename_game_request_body);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<RenameGamePostError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Get a user from primary id
pub async fn user_get(configuration: &configuration::Configuration, user_id: Option<models::UserId>) -> Result<models::User, Error<UserGetError>> {
// add a prefix to parameters to efficiently prevent name collisions

View File

@ -20,6 +20,8 @@ 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;

View File

@ -0,0 +1,30 @@
/*
* Gamenight
*
* Api specifaction 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 RenameGameRequestBody {
#[serde(rename = "id")]
pub id: String,
#[serde(rename = "name")]
pub name: String,
}
impl RenameGameRequestBody {
pub fn new(id: String, name: String) -> RenameGameRequestBody {
RenameGameRequestBody {
id,
name,
}
}
}

View File

@ -45,9 +45,9 @@ dependencies = [
[[package]]
name = "autocfg"
version = "1.4.0"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]]
name = "backtrace"
@ -84,9 +84,9 @@ checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
[[package]]
name = "bumpalo"
version = "3.18.1"
version = "3.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "793db76d6187cd04dff33004d8e6c9cc4e05cd330500379d2394209271b4aeee"
checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
[[package]]
name = "byteorder"
@ -102,9 +102,9 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
[[package]]
name = "cc"
version = "1.2.26"
version = "1.2.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "956a5e21988b87f372569b66183b78babf23ebc2e744b733e4350a752c4dafac"
checksum = "5c1599538de2394445747c8cf7935946e3cc27e9625f889d979bfb2aaf569362"
dependencies = [
"shlex",
]
@ -381,9 +381,9 @@ dependencies = [
[[package]]
name = "hyper-util"
version = "0.1.14"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc2fdfdbff08affe55bb779f33b053aa1fe5dd5b54c257343c17edfa55711bdb"
checksum = "7f66d5bd4c6f02bf0542fad85d626775bab9258cf795a4256dcaf3161114d1df"
dependencies = [
"base64",
"bytes",
@ -552,6 +552,17 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "io-uring"
version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013"
dependencies = [
"bitflags 2.9.1",
"cfg-if",
"libc",
]
[[package]]
name = "ipnet"
version = "2.11.0"
@ -601,9 +612,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.172"
version = "0.2.174"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776"
[[package]]
name = "litemap"
@ -825,24 +836,24 @@ dependencies = [
[[package]]
name = "r-efi"
version = "5.2.0"
version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
[[package]]
name = "redox_syscall"
version = "0.5.12"
version = "0.5.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af"
checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6"
dependencies = [
"bitflags 2.9.1",
]
[[package]]
name = "reqwest"
version = "0.12.20"
version = "0.12.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eabf4c97d9130e2bf606614eb937e86edac8292eaa6f422f995d7e8de1eb1813"
checksum = "cbc931937e6ca3a06e3b6c0aa7841849b160a90351d6ab467a8b9b9959767531"
dependencies = [
"base64",
"bytes",
@ -1013,6 +1024,12 @@ dependencies = [
"time",
]
[[package]]
name = "slab"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04dc19736151f35336d325007ac991178d504a119863a2fcb3758cdb5e52c50d"
[[package]]
name = "smallvec"
version = "1.15.1"
@ -1037,9 +1054,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "syn"
version = "2.0.102"
version = "2.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6397daf94fa90f058bd0fd88429dd9e5738999cca8d701813c80723add80462"
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
dependencies = [
"proc-macro2",
"quote",
@ -1088,12 +1105,11 @@ dependencies = [
[[package]]
name = "thread_local"
version = "1.1.8"
version = "1.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c"
checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185"
dependencies = [
"cfg-if",
"once_cell",
]
[[package]]
@ -1139,17 +1155,19 @@ dependencies = [
[[package]]
name = "tokio"
version = "1.45.1"
version = "1.46.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75ef51a33ef1da925cea3e4eb122833cb377c61439ca401b770f54902b806779"
checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17"
dependencies = [
"backtrace",
"bytes",
"io-uring",
"libc",
"mio 1.0.4",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"slab",
"socket2",
"tokio-macros",
"windows-sys 0.52.0",
@ -1459,9 +1477,9 @@ dependencies = [
[[package]]
name = "windows-link"
version = "0.1.1"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38"
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
[[package]]
name = "windows-result"

View File

@ -0,0 +1,26 @@
use std::fmt::Display;
use gamenight_api_client_rs::models;
use uuid::Uuid;
#[derive(Clone)]
pub struct Game {
pub id: Uuid,
pub name: String
}
impl From<models::Game> for Game {
fn from(game: models::Game) -> Self {
Self {
id: Uuid::parse_str(&game.id).unwrap(),
name: game.name
}
}
}
impl Display for Game {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Name: {}", self.name)
}
}

View File

@ -1,4 +1,5 @@
pub mod gamenight;
pub mod user;
pub mod config;
pub mod participants;
pub mod participants;
pub mod game;

View File

@ -1,7 +1,7 @@
use std::fmt::Display;
use async_trait::async_trait;
use gamenight_api_client_rs::{apis::default_api::game_post, models::{AddGameRequestBody, Game}};
use gamenight_api_client_rs::{apis::default_api::game_post, models::AddGameRequestBody};
use inquire::{Confirm, Text};

View File

@ -1,31 +0,0 @@
use gamenight_api_client_rs::models::Game;
use super::*;
#[derive(Clone)]
pub struct EditGame {
game: Game
}
impl EditGame {
pub fn new(game: Game) -> Self {
Self {
game
}
}
}
#[async_trait]
impl<'a> Flow<'a> for EditGame {
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> {
todo!()
}
}
impl Display for EditGame {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "")
}
}

View File

@ -38,8 +38,7 @@ impl<'a> Flow<'a> for GamenightMenu {
})
.prompt_skippable()?;
clear_screen::clear();
handle_choice_option(&choice, self, state).await
self.continue_choice(state, &choice).await
}
}

View File

@ -34,9 +34,8 @@ impl<'a> Flow<'a> for Games {
..Default::default()
})
.prompt_skippable()?;
clear_screen::clear();
handle_choice_option(&choice, self, state).await
self.continue_choice(state, &choice).await
}
}

View File

@ -40,8 +40,7 @@ impl<'a> Flow<'a> for ListGamenights {
let choice = Select::new("What gamenight would you like to view?", view_flows).prompt_skippable()?;
clear_screen::clear();
handle_choice_option(&choice, self, state).await
self.continue_choice(state, &choice).await
}
}

View File

@ -4,7 +4,7 @@ use async_trait::async_trait;
use gamenight_api_client_rs::apis::default_api::games_get;
use inquire::{ui::RenderConfig, Select};
use crate::flows::{edit_game::EditGame, exit::Exit};
use crate::flows::{view_game::ViewGame, exit::Exit};
use super::*;
@ -25,7 +25,7 @@ impl<'a> Flow<'a> for ListGames {
let games = games_get(&state.api_configuration).await?;
let mut flows = games.into_iter().map(|game| -> Box<dyn Flow + Send> {
Box::new(EditGame::new(game))
Box::new(ViewGame::new(game.into()))
}).collect::<Vec::<Box::<dyn Flow + Send>>>();
flows.push(Box::new(Exit::new()));
@ -38,9 +38,7 @@ impl<'a> Flow<'a> for ListGames {
})
.prompt_skippable()?;
clear_screen::clear();
handle_choice_option(&choice, self, state).await
self.continue_choice(state, &choice).await
}
}

View File

@ -50,8 +50,7 @@ impl<'a> Flow<'a> for Main {
})
.prompt_skippable()?;
clear_screen::clear();
handle_choice_option(&choice, self, state).await
self.continue_choice(state, &choice).await
}
}

View File

@ -23,7 +23,8 @@ mod settings;
mod games;
mod list_games;
mod add_game;
mod edit_game;
mod view_game;
mod rename_game;
pub struct GamenightState {
api_configuration: Configuration,
@ -111,25 +112,27 @@ dyn_clone::clone_trait_object!(for<'a> Flow<'a>);
#[async_trait]
pub trait Flow<'a>: Sync + DynClone + Send + Display {
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a>;
}
async fn handle_choice<'a>(choice: &Box<dyn Flow<'a> + Send>, flow: &dyn Flow<'a>, state: &'a mut GamenightState) -> FlowResult<'a> {
let (outcome, new_state) = choice.run(state).await?;
async fn continue_choice(&self, state: &'a mut GamenightState, choice: &Option<Box<dyn Flow<'a> + Send>>) -> FlowResult<'a> {
clear_screen::clear();
if let Some(choice) = choice {
let (outcome, new_state) = choice.run(state).await?;
if outcome == FlowOutcome::Abort {
Ok((FlowOutcome::Successful, new_state))
if outcome == FlowOutcome::Abort {
Ok((FlowOutcome::Successful, new_state))
}
else {
self.run(new_state).await
}
}
else {
Ok((FlowOutcome::Cancelled, state))
}
}
else {
flow.run(new_state).await
}
}
async fn handle_choice_option<'a>(choice: &Option<Box<dyn Flow<'a> + Send>>, flow: &dyn Flow<'a>, state: &'a mut GamenightState) -> FlowResult<'a> {
if let Some(choice) = choice {
handle_choice(choice, flow, state).await
}
else {
Ok((FlowOutcome::Cancelled, state))
async fn continue_with(&self, state: &'a mut GamenightState, other: &dyn Flow<'a>) -> FlowResult<'a> {
clear_screen::clear();
other.run(state).await
}
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a>;
}

View File

@ -0,0 +1,47 @@
use std::fmt::Display;
use async_trait::async_trait;
use gamenight_api_client_rs::{apis::default_api::rename_game_post, models::RenameGameRequestBody};
use inquire::Text;
use crate::domain::game::Game;
use super::{Flow, FlowOutcome, FlowResult, GamenightState};
#[derive(Clone)]
pub struct RenameGame {
pub game: Game
}
impl RenameGame {
pub fn new(game: Game) -> Self {
Self{
game
}
}
}
#[async_trait]
impl<'a> Flow<'a> for RenameGame {
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> {
if let Some(name) = Text::new(&format!("Rename {} to:", self.game.name))
.with_initial_value(&format!("{}", self.game.name))
.prompt_skippable()?
{
let req = RenameGameRequestBody {
id: self.game.id.to_string(),
name
};
rename_game_post(&state.api_configuration, Some(req)).await?;
return Ok((FlowOutcome::Successful, state))
}
Ok((FlowOutcome::Cancelled, state))
}
}
impl Display for RenameGame {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Rename")
}
}

View File

@ -0,0 +1,46 @@
use gamenight_api_client_rs::{apis::default_api::game_get, models::GameId};
use inquire::Select;
use crate::{domain::game::Game, flows::{exit::Exit, rename_game::RenameGame}};
use super::*;
#[derive(Clone)]
pub struct ViewGame {
game: Game
}
impl ViewGame {
pub fn new(game: Game) -> Self {
Self {
game
}
}
}
#[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 = game_get(&state.api_configuration, Some(game_id)).await?.into();
println!("{}", game);
let options: Vec<Box<dyn Flow<'a> + Send>> = vec![
Box::new(RenameGame::new(game.clone())),
Box::new(Exit::new())
];
let choice = Select::new("What do you want to do:", options)
.prompt_skippable()?;
self.continue_choice(state, &choice).await
}
}
impl Display for ViewGame {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", &self.game.name)
}
}

View File

@ -77,8 +77,7 @@ impl<'a> Flow<'a> for ViewGamenight {
let choice = Select::new("What do you want to do:", options)
.prompt_skippable()?;
clear_screen::clear();
handle_choice_option(&choice, self, state).await
self.continue_choice(state, &choice).await
}
}

View File

@ -1,4 +1,4 @@
use diesel::{dsl::insert_into, Insertable, PgConnection, Queryable, RunQueryDsl};
use diesel::{dsl::insert_into, ExpressionMethods, Insertable, PgConnection, QueryDsl, Queryable, RunQueryDsl};
use serde::{Serialize, Deserialize};
use uuid::Uuid;
use crate::schema::game;
@ -16,6 +16,16 @@ pub fn games(conn: &mut PgConnection) -> Result<Vec::<Game>, DatabaseError> {
Ok(game::table.load::<Game>(conn)?)
}
pub fn load_game(conn: &mut PgConnection, id: Uuid) -> Result<Game, DatabaseError> {
Ok(game::table.find(id).get_result(conn)?)
}
pub fn insert_game(conn: &mut PgConnection, game: Game) -> Result<usize, DatabaseError> {
Ok(insert_into(game::table).values(&game).execute(conn)?)
}
pub fn rename_game(conn: &mut PgConnection, id: Uuid, name: String) -> Result<usize, DatabaseError> {
Ok(diesel::update(game::table.filter(game::id.eq(id)))
.set(game::name.eq(&name))
.execute(conn)?)
}

17
gamenight.code-workspace Normal file
View File

@ -0,0 +1,17 @@
{
"folders": [
{
"path": "backend-actix"
},
{
"path": "gamenight-database"
},
{
"path": "gamenight-cli"
},
{
"path": "gamenight-api-client-rs"
}
],
"settings": {}
}

18
update-rust.sh Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env sh
set -x -e
pushd backend-actix
cargo update
cargo build
popd
pushd gamenight-database
cargo update
cargo build
popd
pushd gamenight-cli
cargo update
cargo build
popd