Added owning games and not willing to travel with them.

This commit is contained in:
2025-12-30 21:18:16 +01:00
parent ff88029a4b
commit 0c256846f6
45 changed files with 595 additions and 92 deletions

413
backend-actix/Cargo.lock generated
View File

@@ -64,7 +64,7 @@ dependencies = [
"mime", "mime",
"percent-encoding", "percent-encoding",
"pin-project-lite", "pin-project-lite",
"rand", "rand 0.9.2",
"sha1", "sha1",
"smallvec", "smallvec",
"tokio", "tokio",
@@ -317,7 +317,6 @@ dependencies = [
"env_logger", "env_logger",
"gamenight-database", "gamenight-database",
"jsonwebtoken", "jsonwebtoken",
"rand_core 0.9.3",
"serde", "serde",
"serde_json", "serde_json",
"tracing-actix-web", "tracing-actix-web",
@@ -325,6 +324,12 @@ dependencies = [
"validator", "validator",
] ]
[[package]]
name = "base16ct"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf"
[[package]] [[package]]
name = "base64" name = "base64"
version = "0.22.1" version = "0.22.1"
@@ -447,6 +452,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
[[package]]
name = "const-oid"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8"
[[package]] [[package]]
name = "convert_case" name = "convert_case"
version = "0.10.0" version = "0.10.0"
@@ -491,6 +502,18 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "crypto-bigint"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76"
dependencies = [
"generic-array",
"rand_core 0.6.4",
"subtle",
"zeroize",
]
[[package]] [[package]]
name = "crypto-common" name = "crypto-common"
version = "0.1.7" version = "0.1.7"
@@ -501,6 +524,33 @@ dependencies = [
"typenum", "typenum",
] ]
[[package]]
name = "curve25519-dalek"
version = "4.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be"
dependencies = [
"cfg-if",
"cpufeatures",
"curve25519-dalek-derive",
"digest",
"fiat-crypto",
"rustc_version",
"subtle",
"zeroize",
]
[[package]]
name = "curve25519-dalek-derive"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "darling" name = "darling"
version = "0.20.11" version = "0.20.11"
@@ -571,6 +621,17 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "der"
version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb"
dependencies = [
"const-oid",
"pem-rfc7468",
"zeroize",
]
[[package]] [[package]]
name = "deranged" name = "deranged"
version = "0.5.5" version = "0.5.5"
@@ -672,6 +733,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [ dependencies = [
"block-buffer", "block-buffer",
"const-oid",
"crypto-common", "crypto-common",
"subtle", "subtle",
] ]
@@ -707,12 +769,71 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "ecdsa"
version = "0.16.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca"
dependencies = [
"der",
"digest",
"elliptic-curve",
"rfc6979",
"signature",
"spki",
]
[[package]]
name = "ed25519"
version = "2.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53"
dependencies = [
"pkcs8",
"signature",
]
[[package]]
name = "ed25519-dalek"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70e796c081cee67dc755e1a36a0a172b897fab85fc3f6bc48307991f64e4eca9"
dependencies = [
"curve25519-dalek",
"ed25519",
"serde",
"sha2",
"subtle",
"zeroize",
]
[[package]] [[package]]
name = "either" name = "either"
version = "1.15.0" version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
[[package]]
name = "elliptic-curve"
version = "0.13.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47"
dependencies = [
"base16ct",
"crypto-bigint",
"digest",
"ff",
"generic-array",
"group",
"hkdf",
"pem-rfc7468",
"pkcs8",
"rand_core 0.6.4",
"sec1",
"subtle",
"zeroize",
]
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.35" version = "0.8.35"
@@ -751,6 +872,22 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
name = "ff"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393"
dependencies = [
"rand_core 0.6.4",
"subtle",
]
[[package]]
name = "fiat-crypto"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d"
[[package]] [[package]]
name = "find-msvc-tools" name = "find-msvc-tools"
version = "0.1.5" version = "0.1.5"
@@ -841,6 +978,7 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [ dependencies = [
"typenum", "typenum",
"version_check", "version_check",
"zeroize",
] ]
[[package]] [[package]]
@@ -850,10 +988,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys",
"libc", "libc",
"wasi", "wasi",
"wasm-bindgen",
] ]
[[package]] [[package]]
@@ -868,6 +1004,17 @@ dependencies = [
"wasip2", "wasip2",
] ]
[[package]]
name = "group"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63"
dependencies = [
"ff",
"rand_core 0.6.4",
"subtle",
]
[[package]] [[package]]
name = "h2" name = "h2"
version = "0.3.27" version = "0.3.27"
@@ -905,6 +1052,24 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "hkdf"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7"
dependencies = [
"hmac",
]
[[package]]
name = "hmac"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
dependencies = [
"digest",
]
[[package]] [[package]]
name = "http" name = "http"
version = "0.2.12" version = "0.2.12"
@@ -1134,16 +1299,24 @@ dependencies = [
[[package]] [[package]]
name = "jsonwebtoken" name = "jsonwebtoken"
version = "9.3.1" version = "10.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a87cc7a48537badeae96744432de36f4be2b4a34a05a5ef32e9dd8a1c169dde" checksum = "c76e1c7d7df3e34443b3621b459b066a7b79644f059fc8b2db7070c825fd417e"
dependencies = [ dependencies = [
"base64", "base64",
"ed25519-dalek",
"getrandom 0.2.16",
"hmac",
"js-sys", "js-sys",
"p256",
"p384",
"pem", "pem",
"ring", "rand 0.8.5",
"rsa",
"serde", "serde",
"serde_json", "serde_json",
"sha2",
"signature",
"simple_asn1", "simple_asn1",
] ]
@@ -1153,12 +1326,27 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388" checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388"
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
dependencies = [
"spin",
]
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.178" version = "0.2.178"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091" checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091"
[[package]]
name = "libm"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
[[package]] [[package]]
name = "litemap" name = "litemap"
version = "0.8.1" version = "0.8.1"
@@ -1268,6 +1456,22 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "num-bigint-dig"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e661dda6640fad38e827a6d4a310ff4763082116fe217f279885c97f511bb0b7"
dependencies = [
"lazy_static",
"libm",
"num-integer",
"num-iter",
"num-traits",
"rand 0.8.5",
"smallvec",
"zeroize",
]
[[package]] [[package]]
name = "num-conv" name = "num-conv"
version = "0.1.0" version = "0.1.0"
@@ -1283,6 +1487,17 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "num-iter"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]] [[package]]
name = "num-traits" name = "num-traits"
version = "0.2.19" version = "0.2.19"
@@ -1290,6 +1505,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"libm",
] ]
[[package]] [[package]]
@@ -1304,6 +1520,30 @@ version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]]
name = "p256"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b"
dependencies = [
"ecdsa",
"elliptic-curve",
"primeorder",
"sha2",
]
[[package]]
name = "p384"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe42f1670a52a47d448f14b6a5c61dd78fce51856e68edaa38f7ae3a46b8d6b6"
dependencies = [
"ecdsa",
"elliptic-curve",
"primeorder",
"sha2",
]
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.12.5" version = "0.12.5"
@@ -1348,6 +1588,15 @@ dependencies = [
"serde_core", "serde_core",
] ]
[[package]]
name = "pem-rfc7468"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412"
dependencies = [
"base64ct",
]
[[package]] [[package]]
name = "percent-encoding" name = "percent-encoding"
version = "2.3.2" version = "2.3.2"
@@ -1386,6 +1635,27 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pkcs1"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f"
dependencies = [
"der",
"pkcs8",
"spki",
]
[[package]]
name = "pkcs8"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7"
dependencies = [
"der",
"spki",
]
[[package]] [[package]]
name = "pkg-config" name = "pkg-config"
version = "0.3.32" version = "0.3.32"
@@ -1442,6 +1712,15 @@ dependencies = [
"vcpkg", "vcpkg",
] ]
[[package]]
name = "primeorder"
version = "0.13.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6"
dependencies = [
"elliptic-curve",
]
[[package]] [[package]]
name = "proc-macro-error-attr2" name = "proc-macro-error-attr2"
version = "2.0.0" version = "2.0.0"
@@ -1499,16 +1778,37 @@ dependencies = [
"scheduled-thread-pool", "scheduled-thread-pool",
] ]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha 0.3.1",
"rand_core 0.6.4",
]
[[package]] [[package]]
name = "rand" name = "rand"
version = "0.9.2" version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
dependencies = [ dependencies = [
"rand_chacha", "rand_chacha 0.9.0",
"rand_core 0.9.3", "rand_core 0.9.3",
] ]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core 0.6.4",
]
[[package]] [[package]]
name = "rand_chacha" name = "rand_chacha"
version = "0.9.0" version = "0.9.0"
@@ -1582,17 +1882,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
[[package]] [[package]]
name = "ring" name = "rfc6979"
version = "0.17.14" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2"
dependencies = [ dependencies = [
"cc", "hmac",
"cfg-if", "subtle",
"getrandom 0.2.16", ]
"libc",
"untrusted", [[package]]
"windows-sys 0.52.0", name = "rsa"
version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40a0376c50d0358279d9d643e4bf7b7be212f1f4ff1da9070a7b54d22ef75c88"
dependencies = [
"const-oid",
"digest",
"num-bigint-dig",
"num-integer",
"num-traits",
"pkcs1",
"pkcs8",
"rand_core 0.6.4",
"signature",
"spki",
"subtle",
"zeroize",
] ]
[[package]] [[package]]
@@ -1631,6 +1947,20 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "sec1"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc"
dependencies = [
"base16ct",
"der",
"generic-array",
"pkcs8",
"subtle",
"zeroize",
]
[[package]] [[package]]
name = "semver" name = "semver"
version = "1.0.27" version = "1.0.27"
@@ -1712,6 +2042,17 @@ dependencies = [
"digest", "digest",
] ]
[[package]]
name = "sha2"
version = "0.10.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]] [[package]]
name = "shlex" name = "shlex"
version = "1.3.0" version = "1.3.0"
@@ -1727,6 +2068,16 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "signature"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"
dependencies = [
"digest",
"rand_core 0.6.4",
]
[[package]] [[package]]
name = "simd-adler32" name = "simd-adler32"
version = "0.3.8" version = "0.3.8"
@@ -1777,6 +2128,22 @@ dependencies = [
"windows-sys 0.60.2", "windows-sys 0.60.2",
] ]
[[package]]
name = "spin"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
[[package]]
name = "spki"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d"
dependencies = [
"base64ct",
"der",
]
[[package]] [[package]]
name = "stable_deref_trait" name = "stable_deref_trait"
version = "1.2.1" version = "1.2.1"
@@ -2007,12 +2374,6 @@ version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
[[package]]
name = "untrusted"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
[[package]] [[package]]
name = "url" name = "url"
version = "2.5.7" version = "2.5.7"
@@ -2448,6 +2809,12 @@ dependencies = [
"synstructure", "synstructure",
] ]
[[package]]
name = "zeroize"
version = "1.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0"
[[package]] [[package]]
name = "zerotrie" name = "zerotrie"
version = "0.2.3" version = "0.2.3"

View File

@@ -13,8 +13,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
uuid = { version = "1.3.0", features = ["serde", "v4"] } uuid = { version = "1.3.0", features = ["serde", "v4"] }
chrono = { version = "0.4", features = ["serde"] } chrono = { version = "0.4", features = ["serde"] }
jsonwebtoken = "9.3" jsonwebtoken = { version = "10.2.0", features = ["rust_crypto"] }
validator = { version = "0.20", features = ["derive"] } validator = { version = "0.20", features = ["derive"] }
rand_core = { version = "0.9" }
env_logger = "0.11" env_logger = "0.11"
tracing-actix-web = "0.7" tracing-actix-web = "0.7"

View File

@@ -3,6 +3,7 @@ use std::{
io::Write, io::Write,
process::Command, process::Command,
}; };
use std::fs::create_dir;
fn main() { fn main() {
println!("cargo::rerun-if-changed=gamenight-api.yaml"); println!("cargo::rerun-if-changed=gamenight-api.yaml");
@@ -11,6 +12,8 @@ fn main() {
remove_dir_all("src/models").unwrap(); remove_dir_all("src/models").unwrap();
} }
create_dir("src/models/").unwrap();
let _ = Command::new("openapi-generator") let _ = Command::new("openapi-generator")
.args([ .args([
"generate", "generate",
@@ -24,7 +27,7 @@ fn main() {
.output() .output()
.expect("Failed to generate models sources for the gamenight API"); .expect("Failed to generate models sources for the gamenight API");
let mut file = File::create("src/models/mod.rs").unwrap(); let mut file = File::create("./src/models/mod.rs").unwrap();
let paths = read_dir("./src/models").unwrap(); let paths = read_dir("./src/models").unwrap();
for path in paths { for path in paths {
let path = path.unwrap(); let path = path.unwrap();

View File

@@ -6,7 +6,7 @@ info:
name: Dennis Brentjes name: Dennis Brentjes
email: dennis@brentj.es email: dennis@brentj.es
url: 'https://brentj.es' url: 'https://brentj.es'
description: Api specifaction for a Gamenight server description: Api specification for a Gamenight server
license: license:
name: MIT name: MIT
servers: servers:
@@ -192,7 +192,7 @@ paths:
post: post:
responses: responses:
'200': '200':
description: "OK" $ref: '#/components/responses/GameIdResponse'
'401': '401':
$ref: '#/components/responses/FailureResponse' $ref: '#/components/responses/FailureResponse'
'422': '422':
@@ -269,7 +269,6 @@ paths:
post: post:
responses: responses:
'200': '200':
description: 'Ok'
$ref: '#/components/responses/LocationIdResponse' $ref: '#/components/responses/LocationIdResponse'
'401': '401':
$ref: '#/components/responses/FailureResponse' $ref: '#/components/responses/FailureResponse'
@@ -479,6 +478,15 @@ components:
required: required:
- id - id
- name - name
OwnGameRequestBody:
type: object
properties:
game_id:
type: string
location_id:
type: string
required:
- game_id
GameIdsResponse: GameIdsResponse:
type: array type: array
items: items:
@@ -586,7 +594,7 @@ components:
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/GameId' $ref: '#/components/schemas/OwnGameRequestBody'
DisownGameRequest: DisownGameRequest:
content: content:
application/json: application/json:
@@ -679,6 +687,12 @@ components:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/Game' $ref: '#/components/schemas/Game'
GameIdResponse:
description: a game id
content:
application/json:
schema:
$ref: '#/components/schemas/GameId'
GameIdsResponse: GameIdsResponse:
description: A list of game ids. description: A list of game ids.
content: content:

View File

@@ -9,7 +9,7 @@ use uuid::Uuid;
use crate::{ use crate::{
models::{ models::{
add_game_request_body::AddGameRequestBody, game::Game, game_id::GameId, add_game_request_body::AddGameRequestBody, game::Game, game_id::GameId,
rename_game_request_body::RenameGameRequestBody, rename_game_request_body::RenameGameRequestBody, own_game_request_body::OwnGameRequestBody
}, },
request::{authorization::AuthUser, error::ApiError}, request::{authorization::AuthUser, error::ApiError},
}; };
@@ -69,9 +69,12 @@ pub async fn post_game(
game_data: web::Json<AddGameRequestBody>, game_data: web::Json<AddGameRequestBody>,
) -> Result<impl Responder, ApiError> { ) -> Result<impl Responder, ApiError> {
let mut conn = pool.get_conn(); let mut conn = pool.get_conn();
insert_game(&mut conn, game_data.0.into())?; let game = game_data.0.into();
insert_game(&mut conn, &game)?;
Ok(HttpResponse::Ok()) Ok(HttpResponse::Ok()
.content_type(ContentType::json())
.body(serde_json::to_string(&GameId{game_id: game.id.to_string()})?))
} }
#[post("/rename_game")] #[post("/rename_game")]
@@ -94,14 +97,15 @@ pub async fn post_rename_game(
pub async fn post_own_game( pub async fn post_own_game(
pool: web::Data<DbPool>, pool: web::Data<DbPool>,
user: AuthUser, user: AuthUser,
game_id: web::Json<GameId>, own_data: web::Json<OwnGameRequestBody>,
) -> Result<impl Responder, ApiError> { ) -> Result<impl Responder, ApiError> {
let mut conn = pool.get_conn(); let mut conn = pool.get_conn();
own_game( own_game(
&mut conn, &mut conn,
OwnedGame { OwnedGame {
user_id: user.0.id, user_id: user.0.id,
game_id: Uuid::parse_str(&game_id.0.game_id)?, game_id: Uuid::parse_str(&own_data.game_id)?,
location_id: own_data.location_id.clone().map(|x| Uuid::parse_str(&x).unwrap()),
}, },
)?; )?;
@@ -120,6 +124,7 @@ pub async fn post_disown_game(
OwnedGame { OwnedGame {
user_id: user.0.id, user_id: user.0.id,
game_id: Uuid::parse_str(&game_id.0.game_id)?, game_id: Uuid::parse_str(&game_id.0.game_id)?,
location_id: None
}, },
)?; )?;

View File

@@ -16,6 +16,7 @@ docs/GetGamenightRequestBody.md
docs/Location.md docs/Location.md
docs/LocationId.md docs/LocationId.md
docs/Login.md docs/Login.md
docs/OwnGameRequestBody.md
docs/Participants.md docs/Participants.md
docs/Registration.md docs/Registration.md
docs/RenameGameRequestBody.md docs/RenameGameRequestBody.md
@@ -41,6 +42,7 @@ src/models/location.rs
src/models/location_id.rs src/models/location_id.rs
src/models/login.rs src/models/login.rs
src/models/mod.rs src/models/mod.rs
src/models/own_game_request_body.rs
src/models/participants.rs src/models/participants.rs
src/models/registration.rs src/models/registration.rs
src/models/rename_game_request_body.rs src/models/rename_game_request_body.rs

View File

@@ -1 +1 @@
7.17.0 7.18.0

View File

@@ -2,7 +2,7 @@
name = "gamenight-api-client-rs" name = "gamenight-api-client-rs"
version = "0.1.0" version = "0.1.0"
authors = ["dennis@brentj.es"] authors = ["dennis@brentj.es"]
description = "Api specifaction for a Gamenight server" description = "Api specification for a Gamenight server"
license = "MIT" license = "MIT"
edition = "2021" edition = "2021"

View File

@@ -1,6 +1,6 @@
# Rust API client for gamenight-api-client-rs # Rust API client for gamenight-api-client-rs
Api specifaction for a Gamenight server Api specification for a Gamenight server
For more information, please visit [https://brentj.es](https://brentj.es) For more information, please visit [https://brentj.es](https://brentj.es)
@@ -10,7 +10,7 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
- API version: 1.0 - API version: 1.0
- Package version: 0.1.0 - Package version: 0.1.0
- Generator version: 7.17.0 - Generator version: 7.18.0
- Build package: `org.openapitools.codegen.languages.RustClientCodegen` - Build package: `org.openapitools.codegen.languages.RustClientCodegen`
## Installation ## Installation
@@ -67,6 +67,7 @@ Class | Method | HTTP request | Description
- [Location](docs/Location.md) - [Location](docs/Location.md)
- [LocationId](docs/LocationId.md) - [LocationId](docs/LocationId.md)
- [Login](docs/Login.md) - [Login](docs/Login.md)
- [OwnGameRequestBody](docs/OwnGameRequestBody.md)
- [Participants](docs/Participants.md) - [Participants](docs/Participants.md)
- [Registration](docs/Registration.md) - [Registration](docs/Registration.md)
- [RenameGameRequestBody](docs/RenameGameRequestBody.md) - [RenameGameRequestBody](docs/RenameGameRequestBody.md)

View File

@@ -116,7 +116,7 @@ Name | Type | Description | Required | Notes
## game_post ## game_post
> game_post(add_game_request_body) > models::GameId game_post(add_game_request_body)
### Parameters ### Parameters
@@ -128,7 +128,7 @@ Name | Type | Description | Required | Notes
### Return type ### Return type
(empty response body) [**models::GameId**](GameId.md)
### Authorization ### Authorization
@@ -419,7 +419,7 @@ This endpoint does not need any parameter.
## own_post ## own_post
> own_post(game_id) > own_post(own_game_request_body)
### Parameters ### Parameters
@@ -427,7 +427,7 @@ This endpoint does not need any parameter.
Name | Type | Description | Required | Notes Name | Type | Description | Required | Notes
------------- | ------------- | ------------- | ------------- | ------------- ------------- | ------------- | ------------- | ------------- | -------------
**game_id** | Option<[**GameId**](GameId.md)> | | | **own_game_request_body** | Option<[**OwnGameRequestBody**](OwnGameRequestBody.md)> | | |
### Return type ### Return type

View File

@@ -0,0 +1,12 @@
# OwnGameRequestBody
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**game_id** | **String** | |
**location_id** | Option<**String**> | | [optional]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es
@@ -330,7 +330,7 @@ pub async fn game_get(configuration: &configuration::Configuration, game_id: Opt
} }
} }
pub async fn game_post(configuration: &configuration::Configuration, add_game_request_body: Option<models::AddGameRequestBody>) -> Result<(), Error<GamePostError>> { pub async fn game_post(configuration: &configuration::Configuration, add_game_request_body: Option<models::AddGameRequestBody>) -> Result<models::GameId, Error<GamePostError>> {
// add a prefix to parameters to efficiently prevent name collisions // add a prefix to parameters to efficiently prevent name collisions
let p_body_add_game_request_body = add_game_request_body; let p_body_add_game_request_body = add_game_request_body;
@@ -349,9 +349,20 @@ pub async fn game_post(configuration: &configuration::Configuration, add_game_re
let resp = configuration.client.execute(req).await?; let resp = configuration.client.execute(req).await?;
let status = resp.status(); let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() { if !status.is_client_error() && !status.is_server_error() {
Ok(()) let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GameId`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GameId`")))),
}
} else { } else {
let content = resp.text().await?; let content = resp.text().await?;
let entity: Option<GamePostError> = serde_json::from_str(&content).ok(); let entity: Option<GamePostError> = serde_json::from_str(&content).ok();
@@ -716,9 +727,9 @@ pub async fn locations_get(configuration: &configuration::Configuration, ) -> Re
} }
} }
pub async fn own_post(configuration: &configuration::Configuration, game_id: Option<models::GameId>) -> Result<(), Error<OwnPostError>> { pub async fn own_post(configuration: &configuration::Configuration, own_game_request_body: Option<models::OwnGameRequestBody>) -> Result<(), Error<OwnPostError>> {
// add a prefix to parameters to efficiently prevent name collisions // add a prefix to parameters to efficiently prevent name collisions
let p_body_game_id = game_id; let p_body_own_game_request_body = own_game_request_body;
let uri_str = format!("{}/own", configuration.base_path); let uri_str = format!("{}/own", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
@@ -729,7 +740,7 @@ pub async fn own_post(configuration: &configuration::Configuration, game_id: Opt
if let Some(ref token) = configuration.bearer_access_token { if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned()); req_builder = req_builder.bearer_auth(token.to_owned());
}; };
req_builder = req_builder.json(&p_body_game_id); req_builder = req_builder.json(&p_body_own_game_request_body);
let req = req_builder.build()?; let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?; let resp = configuration.client.execute(req).await?;

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -24,6 +24,8 @@ pub mod location_id;
pub use self::location_id::LocationId; pub use self::location_id::LocationId;
pub mod login; pub mod login;
pub use self::login::Login; pub use self::login::Login;
pub mod own_game_request_body;
pub use self::own_game_request_body::OwnGameRequestBody;
pub mod participants; pub mod participants;
pub use self::participants::Participants; pub use self::participants::Participants;
pub mod registration; pub mod registration;

View File

@@ -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 OwnGameRequestBody {
#[serde(rename = "game_id")]
pub game_id: String,
#[serde(rename = "location_id", skip_serializing_if = "Option::is_none")]
pub location_id: Option<String>,
}
impl OwnGameRequestBody {
pub fn new(game_id: String) -> OwnGameRequestBody {
OwnGameRequestBody {
game_id,
location_id: None,
}
}
}

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -1,7 +1,7 @@
/* /*
* Gamenight * Gamenight
* *
* Api specifaction for a Gamenight server * Api specification for a Gamenight server
* *
* The version of the OpenAPI document: 1.0 * The version of the OpenAPI document: 1.0
* Contact: dennis@brentj.es * Contact: dennis@brentj.es

View File

@@ -26,6 +26,6 @@ impl Display for Location {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, r#"name: {} write!(f, r#"name: {}
address: {} address: {}
note: {}"#, &self.name, &<std::option::Option<std::string::String> as Clone>::clone(&self.address).unwrap_or_default(), &<std::option::Option<std::string::String> as Clone>::clone(&self.note).unwrap_or_default()) note: {}"#, &self.name, &<Option<String> as Clone>::clone(&self.address).unwrap_or_default(), &<Option<String> as Clone>::clone(&self.note).unwrap_or_default())
} }
} }

View File

@@ -1,10 +1,11 @@
use std::fmt::Display; use std::fmt::Display;
use async_trait::async_trait; use async_trait::async_trait;
use gamenight_api_client_rs::{apis::default_api::game_post, models::AddGameRequestBody}; use gamenight_api_client_rs::{apis::default_api::game_post, models::AddGameRequestBody, models::OwnGameRequestBody};
use inquire::{Confirm, Text}; use gamenight_api_client_rs::apis::default_api::{locations_get, own_post};
use inquire::{Confirm, Select, Text};
use crate::flows::flow_helpers::LocationSelectData;
use crate::flows::own::Own;
use super::*; use super::*;
@@ -25,13 +26,10 @@ impl<'a> Flow<'a> for AddGame {
let add_game_request = AddGameRequestBody { let add_game_request = AddGameRequestBody {
name name
}; };
game_post(&state.api_configuration, Some(add_game_request)).await?; let game_id_response = game_post(&state.api_configuration, Some(add_game_request)).await?;
if let Some(owned) = Confirm::new("Do you own this game?").prompt_skippable()? { let own_flow = Own::new(Uuid::parse_str(&game_id_response.game_id)?);
if owned { return self.continue_with(state, &own_flow).await;
todo!()
}
}
} }
Ok((FlowOutcome::Cancelled, state)) Ok((FlowOutcome::Cancelled, state))
} }

View File

@@ -0,0 +1,25 @@
use std::fmt::{Display, Formatter};
use gamenight_api_client_rs::models::Location;
use uuid::Uuid;
use crate::flows::FlowError;
pub struct LocationSelectData {
pub id: Uuid,
pub name: String,
}
impl Display for LocationSelectData {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }
}
impl TryFrom<&Location> for LocationSelectData {
type Error = FlowError;
fn try_from(value: &Location) -> Result<Self, Self::Error> {
let uuid = Uuid::parse_str(&value.id)?;
Ok(LocationSelectData {
id: uuid,
name: value.name.clone(),
})
}
}

View File

@@ -60,7 +60,7 @@ impl<'a> Flow<'a> for LocationAuthorize {
authorized_user_ids.contains(&t.1.id) authorized_user_ids.contains(&t.1.id)
}).unzip(); }).unzip();
let selections = MultiSelect::new("Which users should be able to host gamenights in this location?", options) let selections = MultiSelect::new("Which users should be able to host game nights in this location?", options)
.with_default(&authorized_indices[..]) .with_default(&authorized_indices[..])
.prompt_skippable()?; .prompt_skippable()?;

View File

@@ -35,6 +35,7 @@ mod list_locations;
mod view_location; mod view_location;
mod add_location; mod add_location;
mod location_authorize; mod location_authorize;
mod flow_helpers;
pub struct GamenightState { pub struct GamenightState {
api_configuration: Configuration, api_configuration: Configuration,

View File

@@ -1,11 +1,14 @@
use std::fmt::Display; use std::fmt::Display;
use super::{Flow, FlowError, FlowOutcome, FlowResult, GamenightState};
use crate::flows::flow_helpers::LocationSelectData;
use async_trait::async_trait; use async_trait::async_trait;
use gamenight_api_client_rs::{apis::default_api::own_post, models::GameId}; use gamenight_api_client_rs::apis::default_api::locations_get;
use gamenight_api_client_rs::models::OwnGameRequestBody;
use gamenight_api_client_rs::apis::default_api::own_post;
use inquire::{Confirm, Select};
use uuid::Uuid; use uuid::Uuid;
use super::{Flow, FlowOutcome, FlowResult, GamenightState};
#[derive(Clone)] #[derive(Clone)]
pub struct Own { pub struct Own {
game_id: Uuid game_id: Uuid
@@ -22,7 +25,25 @@ impl Own {
#[async_trait] #[async_trait]
impl<'a> Flow<'a> for Own { impl<'a> Flow<'a> for Own {
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> {
let _ = own_post(&state.api_configuration, Some(GameId{game_id: self.game_id.to_string()})).await?;
let mut own_game_request = OwnGameRequestBody {
game_id: self.game_id.to_string(),
location_id: None
};
if let Some(owned) = Confirm::new("Do you own this game?").prompt_skippable()? {
if owned {
if let Some(willing_to_travel) = Confirm::new("Are you willing to travel with this game?").prompt_skippable()? {
if !willing_to_travel {
let locations = locations_get(&state.api_configuration).await?.iter().map(|x| { x.try_into() }).collect::<Result<Vec<LocationSelectData>, FlowError>>()?;
if let Some(location) = Select::new("What location can this game be played?", locations).prompt_skippable()? {
own_game_request.location_id = Some(location.id.to_string());
}
}
}
let _ = own_post(&state.api_configuration, Some(own_game_request)).await?;
}
}
clear_screen::clear(); clear_screen::clear();
Ok((FlowOutcome::Successful, state)) Ok((FlowOutcome::Successful, state))

View File

@@ -0,0 +1,3 @@
-- This file should undo anything in `up.sql`
alter table owned_game drop constraint FK_owned_games_location_id;
alter table owned_game drop column location_id;

View File

@@ -0,0 +1,6 @@
-- Your SQL goes here
ALTER TABLE owned_game
ADD location_id UUID;
ALTER TABLE owned_game
ADD CONSTRAINT FK_owned_games_location_id FOREIGN KEY(location_id) REFERENCES location(id);

View File

@@ -1,10 +1,10 @@
use crate::schema::game; use crate::schema::game;
use diesel::{ use diesel::{
ExpressionMethods, Insertable, PgConnection, QueryDsl, Queryable, RunQueryDsl, dsl::insert_into, ExpressionMethods, Insertable, QueryDsl, Queryable, RunQueryDsl, dsl::insert_into,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use uuid::Uuid; use uuid::Uuid;
use crate::DbConnection;
use super::error::DatabaseError; use super::error::DatabaseError;
#[derive(Serialize, Deserialize, Debug, Insertable, Queryable)] #[derive(Serialize, Deserialize, Debug, Insertable, Queryable)]
@@ -14,20 +14,20 @@ pub struct Game {
pub name: String, pub name: String,
} }
pub fn games(conn: &mut PgConnection) -> Result<Vec<Game>, DatabaseError> { pub fn games(conn: &mut DbConnection) -> Result<Vec<Game>, DatabaseError> {
Ok(game::table.load::<Game>(conn)?) Ok(game::table.load::<Game>(conn)?)
} }
pub fn load_game(conn: &mut PgConnection, id: Uuid) -> Result<Game, DatabaseError> { pub fn load_game(conn: &mut DbConnection, id: Uuid) -> Result<Game, DatabaseError> {
Ok(game::table.find(id).get_result(conn)?) Ok(game::table.find(id).get_result(conn)?)
} }
pub fn insert_game(conn: &mut PgConnection, game: Game) -> Result<usize, DatabaseError> { pub fn insert_game(conn: &mut DbConnection, game: &Game) -> Result<usize, DatabaseError> {
Ok(insert_into(game::table).values(&game).execute(conn)?) Ok(insert_into(game::table).values(game).execute(conn)?)
} }
pub fn rename_game( pub fn rename_game(
conn: &mut PgConnection, conn: &mut DbConnection,
id: Uuid, id: Uuid,
name: String, name: String,
) -> Result<usize, DatabaseError> { ) -> Result<usize, DatabaseError> {

View File

@@ -12,6 +12,7 @@ use uuid::Uuid;
pub struct OwnedGame { pub struct OwnedGame {
pub user_id: Uuid, pub user_id: Uuid,
pub game_id: Uuid, pub game_id: Uuid,
pub location_id: Option<Uuid>
} }
pub fn own_game(conn: &mut PgConnection, owned_game: OwnedGame) -> Result<usize, DatabaseError> { pub fn own_game(conn: &mut PgConnection, owned_game: OwnedGame) -> Result<usize, DatabaseError> {

View File

@@ -69,6 +69,7 @@ diesel::table! {
owned_game (user_id, game_id) { owned_game (user_id, game_id) {
user_id -> Uuid, user_id -> Uuid,
game_id -> Uuid, game_id -> Uuid,
location_id -> Nullable<Uuid>,
} }
} }
@@ -99,6 +100,7 @@ diesel::joinable!(location_owner -> client (user_id));
diesel::joinable!(location_owner -> location (location_id)); diesel::joinable!(location_owner -> location (location_id));
diesel::joinable!(owned_game -> client (user_id)); diesel::joinable!(owned_game -> client (user_id));
diesel::joinable!(owned_game -> game (game_id)); diesel::joinable!(owned_game -> game (game_id));
diesel::joinable!(owned_game -> location (location_id));
diesel::joinable!(pwd -> client (user_id)); diesel::joinable!(pwd -> client (user_id));
diesel::allow_tables_to_appear_in_same_query!( diesel::allow_tables_to_appear_in_same_query!(