diff --git a/backend-actix/Cargo.lock b/backend-actix/Cargo.lock index 50cc2d2..1795f47 100644 --- a/backend-actix/Cargo.lock +++ b/backend-actix/Cargo.lock @@ -65,7 +65,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "465a6172cf69b960917811022d8f29bc0b7fa1398bc4f78b3c466673db1213b6" dependencies = [ "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -180,7 +180,7 @@ dependencies = [ "actix-router", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -313,9 +313,9 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ "generic-array", ] @@ -461,9 +461,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.92" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a140f260e6f3f79013b8bfc65e7ce630c9ab4388c6a89c71e07226f49487b72" +checksum = "a9c00419335c41018365ddf7e4d5f1c12ee3659ddcf3e01974650ba1de73d038" dependencies = [ "cc", "cxxbridge-flags", @@ -473,9 +473,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.92" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da6383f459341ea689374bf0a42979739dc421874f112ff26f829b8040b8e613" +checksum = "fb8307ad413a98fff033c8545ecf133e3257747b3bae935e7602aab8aa92d4ca" dependencies = [ "cc", "codespan-reporting", @@ -483,24 +483,24 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn", + "syn 2.0.9", ] [[package]] name = "cxxbridge-flags" -version = "1.0.92" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90201c1a650e95ccff1c8c0bb5a343213bdd317c6e600a93075bca2eff54ec97" +checksum = "edc52e2eb08915cb12596d29d55f0b5384f00d697a646dbd269b6ecb0fbd9d31" [[package]] name = "cxxbridge-macro" -version = "1.0.92" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b75aed41bb2e6367cae39e6326ef817a851db13c13e4f3263714ca3cfb8de56" +checksum = "631569015d0d8d54e6c241733f944042623ab6df7bc3be7466874b05fcdb1c5f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.9", ] [[package]] @@ -513,7 +513,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn", + "syn 1.0.109", ] [[package]] @@ -540,7 +540,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -552,7 +552,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -602,27 +602,27 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" +checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd" [[package]] name = "futures-sink" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" +checksum = "ec93083a4aecafb2a80a885c9de1f0ccae9dbd32c2bb54b0c3a65690e0b8d2f2" [[package]] name = "futures-task" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" +checksum = "fd65540d33b37b16542a0438c12e6aeead10d4ac5d05bd3f805b8f35ab592879" [[package]] name = "futures-util" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" +checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" dependencies = [ "futures-core", "futures-task", @@ -716,16 +716,16 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] name = "iana-time-zone" -version = "0.1.53" +version = "0.1.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" +checksum = "0c17cc76786e99f8d2f055c11159e7f0091c42474dcc3189fbab96072e873e6d" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "winapi", + "windows", ] [[package]] @@ -827,9 +827,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.139" +version = "0.2.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" [[package]] name = "link-cplusplus" @@ -891,9 +891,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "mime" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "miniz_oxide" @@ -998,9 +998,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba" +checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" [[package]] name = "pem" @@ -1059,7 +1059,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "version_check", ] @@ -1076,18 +1076,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.51" +version = "1.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "ba466839c78239c09faf015484e5cc04860f88242cff4d03eb038f04b4699b73" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ "proc-macro2", ] @@ -1144,9 +1144,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +checksum = "cce168fea28d3e05f158bda4576cf0c844d5045bc2cc3620fa0292ed5bb5814c" dependencies = [ "aho-corasick", "memchr", @@ -1155,9 +1155,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.28" +version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "ring" @@ -1212,35 +1212,35 @@ checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1" [[package]] name = "semver" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a" +checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" [[package]] name = "serde" -version = "1.0.152" +version = "1.0.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +checksum = "771d4d9c4163ee138805e12c710dd365e4f44be8be0503cb1bb9eb989425d9c9" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.152" +version = "1.0.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +checksum = "e801c1712f48475582b7696ac71e0ca34ebb30e09338425384269d9717c62cad" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.9", ] [[package]] name = "serde_json" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76" +checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea" dependencies = [ "itoa", "ryu", @@ -1339,6 +1339,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0da4a3c17e109f700685ec577c0f85efd9b19bcf15c913985f14dc1ac01775aa" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "termcolor" version = "1.2.0" @@ -1350,22 +1361,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.39" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5ab016db510546d856297882807df8da66a16fb8c4101cb8b30054b0d5b2d9c" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.39" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.9", ] [[package]] @@ -1482,15 +1493,15 @@ checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] name = "unicode-bidi" -version = "0.3.10" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54675592c1dbefd78cbd98db9bacd89886e1ca50692a0692baefffdeb92dd58" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "775c11906edafc97bc378816b94585fbd9a054eabaf86fdd0ced94af449efab7" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" [[package]] name = "unicode-normalization" @@ -1562,7 +1573,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn", + "syn 1.0.109", "validator_types", ] @@ -1573,7 +1584,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "111abfe30072511849c5910134e8baf8dc05de4c0e5903d681cbd5c9c4d611e3" dependencies = [ "proc-macro2", - "syn", + "syn 1.0.109", ] [[package]] @@ -1621,7 +1632,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-shared", ] @@ -1643,7 +1654,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1695,6 +1706,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdacb41e6a96a052c6cb63a144f24900236121c6f63f4f8219fef5977ecb0c25" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.45.0" @@ -1706,9 +1726,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -1721,45 +1741,45 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" [[package]] name = "windows_aarch64_msvc" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" [[package]] name = "windows_i686_gnu" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" [[package]] name = "windows_i686_msvc" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" [[package]] name = "windows_x86_64_gnu" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" [[package]] name = "windows_x86_64_msvc" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" [[package]] name = "zstd" diff --git a/backend-actix/diesel.toml b/backend-actix/diesel.toml new file mode 100644 index 0000000..ae76b11 --- /dev/null +++ b/backend-actix/diesel.toml @@ -0,0 +1,2 @@ +[print_schema] +file = "src/schema/schema.rs" diff --git a/backend-actix/migrations/2022-03-19-191822_initial/down.sql b/backend-actix/migrations/2022-03-19-191822_initial/down.sql new file mode 100644 index 0000000..be43968 --- /dev/null +++ b/backend-actix/migrations/2022-03-19-191822_initial/down.sql @@ -0,0 +1,4 @@ +-- This file should undo anything in `up.sql` + +drop table gamenight; +drop table known_games; \ No newline at end of file diff --git a/backend-actix/migrations/2022-03-19-191822_initial/up.sql b/backend-actix/migrations/2022-03-19-191822_initial/up.sql new file mode 100644 index 0000000..3513943 --- /dev/null +++ b/backend-actix/migrations/2022-03-19-191822_initial/up.sql @@ -0,0 +1,12 @@ +-- Your SQL goes here + +CREATE TABLE gamenight ( + id UUID NOT NULL PRIMARY KEY, + name VARCHAR NOT NULL, + datetime VARCHAR NOT NULL +); + +CREATE TABLE known_games ( + id UUID NOT NULL PRIMARY KEY, + name VARCHAR UNIQUE NOT NULL +); \ No newline at end of file diff --git a/backend-actix/migrations/2022-04-17-175115_user-system/down.sql b/backend-actix/migrations/2022-04-17-175115_user-system/down.sql new file mode 100644 index 0000000..0f009fb --- /dev/null +++ b/backend-actix/migrations/2022-04-17-175115_user-system/down.sql @@ -0,0 +1,6 @@ +-- This file should undo anything in `up.sql` + +drop table pwd; +drop table users; + +drop type Role; \ No newline at end of file diff --git a/backend-actix/migrations/2022-04-17-175115_user-system/up.sql b/backend-actix/migrations/2022-04-17-175115_user-system/up.sql new file mode 100644 index 0000000..da862fb --- /dev/null +++ b/backend-actix/migrations/2022-04-17-175115_user-system/up.sql @@ -0,0 +1,28 @@ +CREATE TYPE Role AS ENUM ('user', 'admin'); + +CREATE TABLE users ( + id UUID NOT NULL PRIMARY KEY, + username VARCHAR UNIQUE NOT NULL, + email VARCHAR UNIQUE NOT NULL, + role Role NOT NULL +); + +CREATE TABLE pwd ( + user_id UUID NOT NULL PRIMARY KEY, + password VARCHAR NOT NULL, + CONSTRAINT FK_UserId FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE +); + +--Initialize default admin user, with password "gamenight!" +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; +DO $$ +DECLARE + admin_uuid uuid = uuid_generate_v4(); +BEGIN + INSERT INTO users (id, username, email, role) + values(admin_uuid, 'admin', '', 'admin'); + + insert INTO pwd (user_id, password) + values(admin_uuid, '$argon2id$v=19$m=4096,t=3,p=1$zEdUjCAnZqd8DziYWzlFHw$YBLQhKvYIZBY43B8zM6hyBvLKuqTeh0EM5pKOfbWQSI'); +END $$; + diff --git a/backend-actix/migrations/2022-05-14-104118_gamenight_owners/down.sql b/backend-actix/migrations/2022-05-14-104118_gamenight_owners/down.sql new file mode 100644 index 0000000..4ac10b3 --- /dev/null +++ b/backend-actix/migrations/2022-05-14-104118_gamenight_owners/down.sql @@ -0,0 +1,4 @@ +-- This file should undo anything in `up.sql` + +ALTER TABLE gamenight +DROP COLUMN owner_id; \ No newline at end of file diff --git a/backend-actix/migrations/2022-05-14-104118_gamenight_owners/up.sql b/backend-actix/migrations/2022-05-14-104118_gamenight_owners/up.sql new file mode 100644 index 0000000..76b28ff --- /dev/null +++ b/backend-actix/migrations/2022-05-14-104118_gamenight_owners/up.sql @@ -0,0 +1,19 @@ +ALTER TABLE gamenight RENAME TO _gamenight_old; + +CREATE TABLE gamenight ( + id UUID NOT NULL PRIMARY KEY, + name VARCHAR NOT NULL, + datetime VARCHAR NOT NULL, + owner_id UUID NOT NULL, + CONSTRAINT FK_OwnerId FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE +); + +SET session_replication_role = 'replica'; + +INSERT INTO gamenight (id, name, datetime, owner_id) +select id, name, datetime, '00000000-0000-0000-0000-000000000000' +FROM _gamenight_old; + +drop table _gamenight_old; + +SET session_replication_role = 'origin'; \ No newline at end of file diff --git a/backend-actix/migrations/2022-05-27-183310_gamenight_gamelist/down.sql b/backend-actix/migrations/2022-05-27-183310_gamenight_gamelist/down.sql new file mode 100644 index 0000000..fbf6a0e --- /dev/null +++ b/backend-actix/migrations/2022-05-27-183310_gamenight_gamelist/down.sql @@ -0,0 +1,3 @@ +-- This file should undo anything in `up.sql` + +drop table gamenight_gamelist; \ No newline at end of file diff --git a/backend-actix/migrations/2022-05-27-183310_gamenight_gamelist/up.sql b/backend-actix/migrations/2022-05-27-183310_gamenight_gamelist/up.sql new file mode 100644 index 0000000..153a8f4 --- /dev/null +++ b/backend-actix/migrations/2022-05-27-183310_gamenight_gamelist/up.sql @@ -0,0 +1,9 @@ +-- Your SQL goes here + +create table gamenight_gamelist ( + gamenight_id UUID NOT NULL, + game_id UUID NOT NULL, + CONSTRAINT FK_gamenight_id FOREIGN KEY (gamenight_id) REFERENCES gamenight(id) ON DELETE CASCADE, + CONSTRAINT FK_game_id FOREIGN KEY (game_id) REFERENCES known_games(id) ON DELETE CASCADE, + PRIMARY KEY(gamenight_id, game_id) +); \ No newline at end of file diff --git a/backend-actix/migrations/2022-05-28-142526_gamenight participants/down.sql b/backend-actix/migrations/2022-05-28-142526_gamenight participants/down.sql new file mode 100644 index 0000000..e32c462 --- /dev/null +++ b/backend-actix/migrations/2022-05-28-142526_gamenight participants/down.sql @@ -0,0 +1,3 @@ +-- This file should undo anything in `up.sql` + +drop table gamenight_participants; \ No newline at end of file diff --git a/backend-actix/migrations/2022-05-28-142526_gamenight participants/up.sql b/backend-actix/migrations/2022-05-28-142526_gamenight participants/up.sql new file mode 100644 index 0000000..1115fc9 --- /dev/null +++ b/backend-actix/migrations/2022-05-28-142526_gamenight participants/up.sql @@ -0,0 +1,9 @@ +-- Your SQL goes here + +create table gamenight_participants ( + gamenight_id UUID NOT NULL, + user_id UUID NOT NULL, + CONSTRAINT FK_gamenight_id FOREIGN KEY (gamenight_id) REFERENCES gamenight(id) ON DELETE CASCADE, + CONSTRAINT FK_user_id FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, + PRIMARY KEY(gamenight_id, user_id) +) \ No newline at end of file diff --git a/backend-actix/migrations/2022-06-04-141858_registration_tokens/down.sql b/backend-actix/migrations/2022-06-04-141858_registration_tokens/down.sql new file mode 100644 index 0000000..a238b3b --- /dev/null +++ b/backend-actix/migrations/2022-06-04-141858_registration_tokens/down.sql @@ -0,0 +1,6 @@ +-- This file should undo anything in `up.sql` + +drop table registration_tokens; + +ALTER TABLE gamenight +ALTER datetime TYPE VARCHAR; \ No newline at end of file diff --git a/backend-actix/migrations/2022-06-04-141858_registration_tokens/up.sql b/backend-actix/migrations/2022-06-04-141858_registration_tokens/up.sql new file mode 100644 index 0000000..118a1e2 --- /dev/null +++ b/backend-actix/migrations/2022-06-04-141858_registration_tokens/up.sql @@ -0,0 +1,11 @@ +-- Your SQL goes here + +create table registration_tokens ( + id UUID PRIMARY KEY, + token CHARACTER(32) NOT NULL, + single_use BOOLEAN NOT NULL, + expires TIMESTAMPTZ +); + +ALTER TABLE gamenight +ALTER datetime TYPE TIMESTAMPTZ using datetime::timestamp; diff --git a/backend-actix/src/request/error.rs b/backend-actix/src/request/error.rs index 024d9d5..6519952 100644 --- a/backend-actix/src/request/error.rs +++ b/backend-actix/src/request/error.rs @@ -1,5 +1,5 @@ use std::fmt::{Display, Formatter, Result}; -use actix_web::{ResponseError, error::BlockingError}; +use actix_web::{ResponseError, error::BlockingError, HttpResponse, http::{header::ContentType, StatusCode}}; use serde::{Serialize, Deserialize}; use validator::ValidationErrors; @@ -7,22 +7,32 @@ use crate::schema::error::DatabaseError; #[derive(Serialize, Deserialize, Debug)] pub struct ApiError { - pub error: String + #[serde(skip_serializing)] + pub status: u16, + pub message: String } impl Display for ApiError { // This trait requires `fmt` with this exact signature. fn fmt(&self, f: &mut Formatter) -> Result { - write!(f, "{}", self.error) + write!(f, "{}", self.message) } } -impl ResponseError for ApiError { } +impl ResponseError for ApiError { + fn error_response(&self) -> HttpResponse { + HttpResponse::build(StatusCode::from_u16(self.status).unwrap()) + .content_type(ContentType::json()) + .body(serde_json::to_string(&self).unwrap()) + } +} impl From for ApiError { fn from(value: DatabaseError) -> Self { ApiError { - error: value.0 + //Todo, split this in unrecoverable and schema error + status: 500, + message: value.0 } } } @@ -30,7 +40,8 @@ impl From for ApiError { impl From for ApiError { fn from(value: BlockingError) -> Self { ApiError { - error: value.to_string() + status: 500, + message: value.to_string() } } } @@ -38,15 +49,17 @@ impl From for ApiError { impl From for ApiError { fn from(value: serde_json::Error) -> Self { ApiError { - error: value.to_string() + status: 500, + message: value.to_string() } } } impl From for ApiError { fn from(value: jsonwebtoken::errors::Error) -> Self { - ApiError { - error: value.to_string() + ApiError { + status: 500, + message: value.to_string() } } } @@ -54,7 +67,8 @@ impl From for ApiError { impl From for ApiError { fn from(value: ValidationErrors) -> Self { ApiError { - error: value.to_string() + status: 422, + message: value.to_string() } } } diff --git a/backend-actix/src/request/handler.rs b/backend-actix/src/request/handler.rs index 6ff120d..a088bf2 100644 --- a/backend-actix/src/request/handler.rs +++ b/backend-actix/src/request/handler.rs @@ -6,7 +6,7 @@ use serde::{Serialize, Deserialize}; use uuid::Uuid; use validator::ValidateArgs; use crate::DbPool; -use crate::request::request_data::{Login, Register}; +use crate::request::requests::{Login, Register}; use crate::request::error::ApiError; use crate::request::responses::LoginResponse; use crate::schema::user::Role; @@ -83,6 +83,7 @@ pub async fn register(pool: web::Data, register_data: web::Json Uuid, + name -> Varchar, + datetime -> Timestamptz, + owner_id -> Uuid, + } +} + +diesel::table! { + gamenight_gamelist (gamenight_id, game_id) { + gamenight_id -> Uuid, + game_id -> Uuid, + } +} + +diesel::table! { + gamenight_participants (gamenight_id, user_id) { + gamenight_id -> Uuid, + user_id -> Uuid, + } +} + +diesel::table! { + known_games (id) { + id -> Uuid, + name -> Varchar, + } +} + +diesel::table! { + pwd (user_id) { + user_id -> Uuid, + password -> Varchar, + } +} + +diesel::table! { + registration_tokens (id) { + id -> Uuid, + token -> Bpchar, + single_use -> Bool, + expires -> Nullable, + } +} + +diesel::table! { + use diesel::sql_types::*; + use super::sql_types::Role; + + users (id) { + id -> Uuid, + username -> Varchar, + email -> Varchar, + role -> Role, + } +} + +diesel::joinable!(gamenight -> users (owner_id)); +diesel::joinable!(gamenight_gamelist -> known_games (game_id)); +diesel::joinable!(gamenight_participants -> users (user_id)); +diesel::joinable!(pwd -> users (user_id)); + +diesel::allow_tables_to_appear_in_same_query!( + gamenight, + gamenight_gamelist, + gamenight_participants, + known_games, + pwd, + registration_tokens, + users, +); diff --git a/backend-actix/src/schema/user.rs b/backend-actix/src/schema/user.rs index 6c9b290..ed7c32b 100644 --- a/backend-actix/src/schema/user.rs +++ b/backend-actix/src/schema/user.rs @@ -1,7 +1,7 @@ use diesel::Connection; use serde::{Serialize, Deserialize}; use uuid::Uuid; -use diesel::{PgConnection, ExpressionMethods, QueryDsl, RunQueryDsl, table, Insertable, Queryable}; +use diesel::{PgConnection, ExpressionMethods, QueryDsl, RunQueryDsl, Insertable, Queryable}; use diesel_derive_enum::DbEnum; use argon2::password_hash::SaltString; use argon2::PasswordHash; @@ -11,6 +11,7 @@ use argon2::{ Argon2, }; use validator::ValidationError; +use super::schema::{pwd, users}; pub use super::error::DatabaseError; @@ -30,10 +31,11 @@ pub struct User { pub role: Role, } -#[derive(Debug, Serialize, Deserialize, DbEnum, Clone, Copy, PartialEq)] +#[derive(DbEnum, Debug, Serialize, Deserialize, Clone, Copy, PartialEq)] +#[ExistingTypePath = "crate::schema::schema::sql_types::Role"] pub enum Role { Admin, - User, + User } pub struct LoginUser { @@ -59,23 +61,6 @@ pub struct Register { pub password: String } - -table! { - users(id) { - id -> diesel::sql_types::Uuid, - username -> VarChar, - email -> VarChar, - role -> crate::schema::user::RoleMapping, - } -} - -table! { - pwd(user_id) { - user_id -> diesel::sql_types::Uuid, - password -> VarChar, - } -} - pub fn login(conn: &mut PgConnection, user: LoginUser) -> Result, DatabaseError> { let id: Uuid = users::table .filter(users::username.eq(&user.username))