forked from Roflin/gamenight
		
	Autogenerate only the models of the API for the backend-server
This commit is contained in:
		
							parent
							
								
									597a960bf1
								
							
						
					
					
						commit
						6950ac62e8
					
				
							
								
								
									
										2
									
								
								backend-actix/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								backend-actix/.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1 +1,3 @@
 | 
			
		||||
target
 | 
			
		||||
src/models/
 | 
			
		||||
docs/
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										276
									
								
								backend-actix/Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										276
									
								
								backend-actix/Cargo.lock
									
									
									
										generated
									
									
									
								
							@ -55,7 +55,7 @@ dependencies = [
 | 
			
		||||
 "foldhash",
 | 
			
		||||
 "futures-core",
 | 
			
		||||
 "h2",
 | 
			
		||||
 "http 0.2.12",
 | 
			
		||||
 "http",
 | 
			
		||||
 "httparse",
 | 
			
		||||
 "httpdate",
 | 
			
		||||
 "itoa",
 | 
			
		||||
@ -91,7 +91,7 @@ checksum = "13d324164c51f63867b57e73ba5936ea151b8a41a1d23d1031eeb9f70d0236f8"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "bytestring",
 | 
			
		||||
 "cfg-if",
 | 
			
		||||
 "http 0.2.12",
 | 
			
		||||
 "http",
 | 
			
		||||
 "regex",
 | 
			
		||||
 "regex-lite",
 | 
			
		||||
 "serde",
 | 
			
		||||
@ -330,7 +330,6 @@ dependencies = [
 | 
			
		||||
 "actix-web",
 | 
			
		||||
 "chrono",
 | 
			
		||||
 "env_logger",
 | 
			
		||||
 "gamenight-api-client-rs",
 | 
			
		||||
 "gamenight-database",
 | 
			
		||||
 "jsonwebtoken",
 | 
			
		||||
 "rand_core 0.9.3",
 | 
			
		||||
@ -760,15 +759,6 @@ dependencies = [
 | 
			
		||||
 "percent-encoding",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "futures-channel"
 | 
			
		||||
version = "0.3.31"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "futures-core",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "futures-core"
 | 
			
		||||
version = "0.3.31"
 | 
			
		||||
@ -800,17 +790,6 @@ dependencies = [
 | 
			
		||||
 "slab",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "gamenight-api-client-rs"
 | 
			
		||||
version = "0.1.0"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "reqwest",
 | 
			
		||||
 "serde",
 | 
			
		||||
 "serde_json",
 | 
			
		||||
 "serde_repr",
 | 
			
		||||
 "url",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "gamenight-database"
 | 
			
		||||
version = "0.1.0"
 | 
			
		||||
@ -877,7 +856,7 @@ dependencies = [
 | 
			
		||||
 "futures-core",
 | 
			
		||||
 "futures-sink",
 | 
			
		||||
 "futures-util",
 | 
			
		||||
 "http 0.2.12",
 | 
			
		||||
 "http",
 | 
			
		||||
 "indexmap",
 | 
			
		||||
 "slab",
 | 
			
		||||
 "tokio",
 | 
			
		||||
@ -914,40 +893,6 @@ dependencies = [
 | 
			
		||||
 "itoa",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "http"
 | 
			
		||||
version = "1.3.1"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "bytes",
 | 
			
		||||
 "fnv",
 | 
			
		||||
 "itoa",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "http-body"
 | 
			
		||||
version = "1.0.1"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "bytes",
 | 
			
		||||
 "http 1.3.1",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "http-body-util"
 | 
			
		||||
version = "0.1.3"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "bytes",
 | 
			
		||||
 "futures-core",
 | 
			
		||||
 "http 1.3.1",
 | 
			
		||||
 "http-body",
 | 
			
		||||
 "pin-project-lite",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "httparse"
 | 
			
		||||
version = "1.10.1"
 | 
			
		||||
@ -960,49 +905,6 @@ version = "1.0.3"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "hyper"
 | 
			
		||||
version = "1.6.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "cc2b571658e38e0c01b1fdca3bbbe93c00d3d71693ff2770043f8c29bc7d6f80"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "bytes",
 | 
			
		||||
 "futures-channel",
 | 
			
		||||
 "futures-util",
 | 
			
		||||
 "http 1.3.1",
 | 
			
		||||
 "http-body",
 | 
			
		||||
 "httparse",
 | 
			
		||||
 "itoa",
 | 
			
		||||
 "pin-project-lite",
 | 
			
		||||
 "smallvec",
 | 
			
		||||
 "tokio",
 | 
			
		||||
 "want",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "hyper-util"
 | 
			
		||||
version = "0.1.13"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "b1c293b6b3d21eca78250dc7dbebd6b9210ec5530e038cbfe0661b5c47ab06e8"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "base64",
 | 
			
		||||
 "bytes",
 | 
			
		||||
 "futures-channel",
 | 
			
		||||
 "futures-core",
 | 
			
		||||
 "futures-util",
 | 
			
		||||
 "http 1.3.1",
 | 
			
		||||
 "http-body",
 | 
			
		||||
 "hyper",
 | 
			
		||||
 "ipnet",
 | 
			
		||||
 "libc",
 | 
			
		||||
 "percent-encoding",
 | 
			
		||||
 "pin-project-lite",
 | 
			
		||||
 "socket2",
 | 
			
		||||
 "tokio",
 | 
			
		||||
 "tower-service",
 | 
			
		||||
 "tracing",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "iana-time-zone"
 | 
			
		||||
version = "0.1.63"
 | 
			
		||||
@ -1156,22 +1058,6 @@ dependencies = [
 | 
			
		||||
 "hashbrown",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "ipnet"
 | 
			
		||||
version = "2.11.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "iri-string"
 | 
			
		||||
version = "0.7.8"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "dbc5ebe9c3a1a7a5127f920a418f7585e9e758e911d0466ed004f393b0e380b2"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "memchr",
 | 
			
		||||
 "serde",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "is_terminal_polyfill"
 | 
			
		||||
version = "1.70.1"
 | 
			
		||||
@ -1327,16 +1213,6 @@ version = "0.3.17"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "mime_guess"
 | 
			
		||||
version = "2.0.5"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "mime",
 | 
			
		||||
 "unicase",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "miniz_oxide"
 | 
			
		||||
version = "0.8.8"
 | 
			
		||||
@ -1695,43 +1571,6 @@ version = "0.8.5"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "reqwest"
 | 
			
		||||
version = "0.12.18"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "e98ff6b0dbbe4d5a37318f433d4fc82babd21631f194d370409ceb2e40b2f0b5"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "base64",
 | 
			
		||||
 "bytes",
 | 
			
		||||
 "futures-core",
 | 
			
		||||
 "futures-util",
 | 
			
		||||
 "http 1.3.1",
 | 
			
		||||
 "http-body",
 | 
			
		||||
 "http-body-util",
 | 
			
		||||
 "hyper",
 | 
			
		||||
 "hyper-util",
 | 
			
		||||
 "ipnet",
 | 
			
		||||
 "js-sys",
 | 
			
		||||
 "log",
 | 
			
		||||
 "mime",
 | 
			
		||||
 "mime_guess",
 | 
			
		||||
 "once_cell",
 | 
			
		||||
 "percent-encoding",
 | 
			
		||||
 "pin-project-lite",
 | 
			
		||||
 "serde",
 | 
			
		||||
 "serde_json",
 | 
			
		||||
 "serde_urlencoded",
 | 
			
		||||
 "sync_wrapper",
 | 
			
		||||
 "tokio",
 | 
			
		||||
 "tower",
 | 
			
		||||
 "tower-http",
 | 
			
		||||
 "tower-service",
 | 
			
		||||
 "url",
 | 
			
		||||
 "wasm-bindgen",
 | 
			
		||||
 "wasm-bindgen-futures",
 | 
			
		||||
 "web-sys",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "ring"
 | 
			
		||||
version = "0.17.14"
 | 
			
		||||
@ -1811,17 +1650,6 @@ dependencies = [
 | 
			
		||||
 "serde",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "serde_repr"
 | 
			
		||||
version = "0.1.20"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "175ee3e80ae9982737ca543e96133087cbd9a485eecc3bc4de9c1a37b47ea59c"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "proc-macro2",
 | 
			
		||||
 "quote",
 | 
			
		||||
 "syn",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "serde_spanned"
 | 
			
		||||
version = "0.6.8"
 | 
			
		||||
@ -1935,15 +1763,6 @@ dependencies = [
 | 
			
		||||
 "unicode-ident",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "sync_wrapper"
 | 
			
		||||
version = "1.0.2"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "futures-core",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "synstructure"
 | 
			
		||||
version = "0.13.2"
 | 
			
		||||
@ -2087,51 +1906,6 @@ version = "0.1.1"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "bfb942dfe1d8e29a7ee7fcbde5bd2b9a25fb89aa70caea2eba3bee836ff41076"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "tower"
 | 
			
		||||
version = "0.5.2"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "futures-core",
 | 
			
		||||
 "futures-util",
 | 
			
		||||
 "pin-project-lite",
 | 
			
		||||
 "sync_wrapper",
 | 
			
		||||
 "tokio",
 | 
			
		||||
 "tower-layer",
 | 
			
		||||
 "tower-service",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "tower-http"
 | 
			
		||||
version = "0.6.4"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "0fdb0c213ca27a9f57ab69ddb290fd80d970922355b83ae380b395d3986b8a2e"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "bitflags",
 | 
			
		||||
 "bytes",
 | 
			
		||||
 "futures-util",
 | 
			
		||||
 "http 1.3.1",
 | 
			
		||||
 "http-body",
 | 
			
		||||
 "iri-string",
 | 
			
		||||
 "pin-project-lite",
 | 
			
		||||
 "tower",
 | 
			
		||||
 "tower-layer",
 | 
			
		||||
 "tower-service",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "tower-layer"
 | 
			
		||||
version = "0.3.3"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "tower-service"
 | 
			
		||||
version = "0.3.3"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "tracing"
 | 
			
		||||
version = "0.1.41"
 | 
			
		||||
@ -2177,24 +1951,12 @@ dependencies = [
 | 
			
		||||
 "once_cell",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "try-lock"
 | 
			
		||||
version = "0.2.5"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "typenum"
 | 
			
		||||
version = "1.18.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "unicase"
 | 
			
		||||
version = "2.8.1"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "unicode-ident"
 | 
			
		||||
version = "1.0.18"
 | 
			
		||||
@ -2290,15 +2052,6 @@ version = "0.9.5"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "want"
 | 
			
		||||
version = "0.3.1"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "try-lock",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "wasi"
 | 
			
		||||
version = "0.11.0+wasi-snapshot-preview1"
 | 
			
		||||
@ -2340,19 +2093,6 @@ dependencies = [
 | 
			
		||||
 "wasm-bindgen-shared",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "wasm-bindgen-futures"
 | 
			
		||||
version = "0.4.50"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "cfg-if",
 | 
			
		||||
 "js-sys",
 | 
			
		||||
 "once_cell",
 | 
			
		||||
 "wasm-bindgen",
 | 
			
		||||
 "web-sys",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "wasm-bindgen-macro"
 | 
			
		||||
version = "0.2.100"
 | 
			
		||||
@ -2385,16 +2125,6 @@ dependencies = [
 | 
			
		||||
 "unicode-ident",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "web-sys"
 | 
			
		||||
version = "0.3.77"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "js-sys",
 | 
			
		||||
 "wasm-bindgen",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "windows-core"
 | 
			
		||||
version = "0.61.2"
 | 
			
		||||
 | 
			
		||||
@ -6,7 +6,6 @@ edition = "2021"
 | 
			
		||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 | 
			
		||||
 | 
			
		||||
[dependencies]
 | 
			
		||||
gamenight-api-client-rs = { path = "../gamenight-api-client-rs" }
 | 
			
		||||
gamenight-database = { path = "../gamenight-database"}
 | 
			
		||||
actix-web = "4"
 | 
			
		||||
actix-cors = "0.7"
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										24
									
								
								backend-actix/build.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								backend-actix/build.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,24 @@
 | 
			
		||||
use std::{fs::{self, File}, io::Write, process::Command};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
fn main() {
 | 
			
		||||
    let _ = 
 | 
			
		||||
        Command::new("openapi-generator")
 | 
			
		||||
            .args(["generate", "-i", "gamenight-api.yaml", "-g", "rust", "--global-property", "models"])
 | 
			
		||||
            .output()
 | 
			
		||||
            .expect("Failed to generate models sources for the gamenight API");
 | 
			
		||||
 | 
			
		||||
    let mut file = File::create("src/models/mod.rs").unwrap();
 | 
			
		||||
    let paths = fs::read_dir("./src/models").unwrap();
 | 
			
		||||
    for path in paths {
 | 
			
		||||
        let path = path.unwrap();
 | 
			
		||||
        let path = path.path();
 | 
			
		||||
        let stem = path.file_stem().unwrap();
 | 
			
		||||
        if stem == "mod" {
 | 
			
		||||
            continue
 | 
			
		||||
        }
 | 
			
		||||
    
 | 
			
		||||
        let line = format!("pub mod {};\n", stem.to_str().unwrap());
 | 
			
		||||
        file.write(line.as_bytes()).unwrap();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -87,8 +87,6 @@ components:
 | 
			
		||||
  schemas:
 | 
			
		||||
    Gamenight:
 | 
			
		||||
      title: Gamenight
 | 
			
		||||
      x-stoplight:
 | 
			
		||||
        id: 0nmru75ph5wh3
 | 
			
		||||
      type: object
 | 
			
		||||
      properties:
 | 
			
		||||
        id:
 | 
			
		||||
@ -113,8 +111,6 @@ components:
 | 
			
		||||
      description: ''
 | 
			
		||||
    Token:
 | 
			
		||||
      title: Token
 | 
			
		||||
      x-stoplight:
 | 
			
		||||
        id: 8pz19kigm1jer
 | 
			
		||||
      type: object
 | 
			
		||||
      properties:
 | 
			
		||||
        jwt_token:
 | 
			
		||||
@ -152,19 +148,23 @@ components:
 | 
			
		||||
        - registration_token
 | 
			
		||||
    AddGamenightRequestBody:
 | 
			
		||||
      title: AddGamenightRequestBody
 | 
			
		||||
      x-stoplight:
 | 
			
		||||
        id: xw4z5jyym8q7r
 | 
			
		||||
      type: object
 | 
			
		||||
      properties:
 | 
			
		||||
        name:
 | 
			
		||||
          type: string
 | 
			
		||||
          x-stoplight:
 | 
			
		||||
            id: s5ny76cy54nty
 | 
			
		||||
        datetime:
 | 
			
		||||
          type: string
 | 
			
		||||
          x-stoplight:
 | 
			
		||||
            id: dh6vyvulj4xze
 | 
			
		||||
      x-internal: false
 | 
			
		||||
    User:
 | 
			
		||||
      type: object
 | 
			
		||||
      properties:
 | 
			
		||||
        id:
 | 
			
		||||
          type: string
 | 
			
		||||
        username:
 | 
			
		||||
          type: string
 | 
			
		||||
        email:
 | 
			
		||||
          type: string
 | 
			
		||||
      required:
 | 
			
		||||
        - username
 | 
			
		||||
  requestBodies:
 | 
			
		||||
    LoginRequest:
 | 
			
		||||
      content:
 | 
			
		||||
 | 
			
		||||
@ -1,3 +1,5 @@
 | 
			
		||||
#[allow(unused_imports)]
 | 
			
		||||
pub mod models;
 | 
			
		||||
pub mod request;
 | 
			
		||||
 | 
			
		||||
use actix_cors::Cors;
 | 
			
		||||
@ -6,7 +8,7 @@ use actix_web::HttpServer;
 | 
			
		||||
use actix_web::App;
 | 
			
		||||
use actix_web::http;
 | 
			
		||||
use actix_web::web;
 | 
			
		||||
use request::{login, register, gamenights, gamenight_post, gamenight_get};
 | 
			
		||||
use request::{*, login, register, gamenights};
 | 
			
		||||
use tracing_actix_web::TracingLogger;
 | 
			
		||||
use gamenight_database::*;
 | 
			
		||||
 | 
			
		||||
@ -40,6 +42,8 @@ async fn main() -> std::io::Result<()> {
 | 
			
		||||
            .service(gamenights)
 | 
			
		||||
            .service(gamenight_post)
 | 
			
		||||
            .service(gamenight_get)
 | 
			
		||||
            .service(get_user)
 | 
			
		||||
            .service(get_user_unauthenticated)
 | 
			
		||||
    })
 | 
			
		||||
    .bind(("::1", 8080))?
 | 
			
		||||
    .run()
 | 
			
		||||
 | 
			
		||||
@ -13,7 +13,6 @@ pub struct ApiError {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Display for ApiError {
 | 
			
		||||
    // This trait requires `fmt` with this exact signature.
 | 
			
		||||
    fn fmt(&self, f: &mut Formatter) -> Result {
 | 
			
		||||
        write!(f, "{}", self.message)
 | 
			
		||||
    }
 | 
			
		||||
@ -81,3 +80,12 @@ impl From<chrono::ParseError> for ApiError {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl From<uuid::Error> for ApiError {
 | 
			
		||||
    fn from(value: uuid::Error) -> Self {
 | 
			
		||||
        ApiError {
 | 
			
		||||
            status: 422,
 | 
			
		||||
            message: value.to_string()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -10,4 +10,6 @@ pub use user_handlers::login;
 | 
			
		||||
pub use user_handlers::register;
 | 
			
		||||
pub use gamenight_handlers::gamenights;
 | 
			
		||||
pub use gamenight_handlers::gamenight_post;
 | 
			
		||||
pub use gamenight_handlers::gamenight_get;
 | 
			
		||||
pub use gamenight_handlers::gamenight_get;
 | 
			
		||||
pub use user_handlers::get_user;
 | 
			
		||||
pub use user_handlers::get_user_unauthenticated;
 | 
			
		||||
@ -1,7 +1,10 @@
 | 
			
		||||
 | 
			
		||||
use actix_web::http::header::ContentType;
 | 
			
		||||
use actix_web::{web, get, post, HttpResponse, Responder};
 | 
			
		||||
use actix_web::{get, post, web, HttpResponse, Responder};
 | 
			
		||||
use serde::Deserialize;
 | 
			
		||||
use uuid::Uuid;
 | 
			
		||||
use validator::ValidateArgs;
 | 
			
		||||
use crate::models::user::User;
 | 
			
		||||
use crate::request::requests::{Login, Register, RegisterContext};
 | 
			
		||||
use crate::request::error::ApiError;
 | 
			
		||||
use crate::request::responses::LoginResponse;
 | 
			
		||||
@ -9,6 +12,8 @@ use crate::request::authorization::get_token;
 | 
			
		||||
use serde_json;
 | 
			
		||||
use gamenight_database::{DbPool, GetConnection};
 | 
			
		||||
 | 
			
		||||
use super::authorization::AuthUser;
 | 
			
		||||
 | 
			
		||||
impl From<Login> for gamenight_database::user::LoginUser {
 | 
			
		||||
    fn from(val: Login) -> Self {
 | 
			
		||||
        gamenight_database::user::LoginUser {
 | 
			
		||||
@ -63,4 +68,36 @@ pub async fn register(pool: web::Data<DbPool>, register_data: web::Json<Register
 | 
			
		||||
    Ok(HttpResponse::Ok())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Deserialize)]
 | 
			
		||||
struct UserInfo {
 | 
			
		||||
    pub uuid: String
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl From<gamenight_database::user::User> for User {
 | 
			
		||||
    fn from(value: gamenight_database::user::User) -> Self {
 | 
			
		||||
        Self {
 | 
			
		||||
            id: Some(value.id.to_string()),
 | 
			
		||||
            username: value.username,
 | 
			
		||||
            email: None,
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[get("/user/{user_id}")]
 | 
			
		||||
pub async fn get_user(pool: web::Data<DbPool>, _user: AuthUser, path: web::Path<UserInfo>) -> Result<impl Responder, ApiError> {
 | 
			
		||||
    let mut conn = pool.get_conn();
 | 
			
		||||
    
 | 
			
		||||
    let user = gamenight_database::user::get_user(&mut conn, Uuid::parse_str(&path.uuid)?)?;
 | 
			
		||||
    Ok(HttpResponse::Ok()
 | 
			
		||||
            .content_type(ContentType::json())
 | 
			
		||||
            .body(serde_json::to_string(&user)?))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[get("/user/{user_id}")]
 | 
			
		||||
pub async fn get_user_unauthenticated(_path: web::Path<UserInfo>) -> Result<impl Responder, ApiError> {
 | 
			
		||||
    Ok(HttpResponse::Forbidden())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user