This commit is contained in:
2025-11-30 21:47:03 +01:00
parent d38f8891f5
commit 73791a0760
12 changed files with 3226 additions and 70 deletions
+44 -24
View File
@@ -10,21 +10,38 @@ pub mod items {
mod auth;
mod proto_utils;
#[derive(Clone)]
pub struct User {
pub person: items::Person,
pub password_hash: String,
}
impl std::ops::Deref for User {
type Target = items::Person;
fn deref(&self) -> &Self::Target {
&self.person
}
}
#[get("/<name>")]
fn get_user(user_list: &rocket::State<Vec<items::Person>>, name: String) -> Option<items::Person> {
user_list.iter().find(|user| user.name == name).cloned()
fn get_user(user_list: &rocket::State<Vec<User>>, name: String) -> Option<items::Person> {
user_list
.iter()
.find(|user| user.person.name == name)
.map(|u| u.person.clone())
}
#[get("/")]
fn get_users(user_list: &rocket::State<Vec<items::Person>>) -> items::PersonList {
fn get_users(user_list: &rocket::State<Vec<User>>) -> items::PersonList {
items::PersonList {
person: user_list
.inner()
.to_vec()
.iter_mut()
.map(|x| {
x.opinion.clear();
x.clone()
.iter()
.map(|u| {
let mut p = u.person.clone();
p.opinion.clear();
p
})
.collect(),
}
@@ -44,22 +61,25 @@ async fn index_fallback() -> Option<rocket::fs::NamedFile> {
#[launch]
fn rocket() -> _ {
let mut user_list: Vec<items::Person> = Vec::new();
let mut user_list: Vec<User> = Vec::new();
user_list.push(items::Person {
name: "John".to_string(),
opinion: vec![items::Opinion {
game: Some(items::Game {
title: "Naramo Nuclear Plant V2".to_string(),
source: items::Source::Roblox.into(),
multiplayer: true,
min_players: 1,
max_players: 90,
price: 0,
remote_id: 0,
}),
would_play: true,
}],
user_list.push(User {
person: items::Person {
name: "John".to_string(),
opinion: vec![items::Opinion {
game: Some(items::Game {
title: "Naramo Nuclear Plant V2".to_string(),
source: items::Source::Roblox.into(),
multiplayer: true,
min_players: 1,
max_players: 90,
price: 0,
remote_id: 0,
}),
would_play: true,
}],
},
password_hash: bcrypt::hash("password123", bcrypt::DEFAULT_COST).unwrap(),
});
rocket::build()
@@ -71,5 +91,5 @@ fn rocket() -> _ {
routes![auth::login, auth::logout, auth::get_auth_status],
)
.mount("/", routes![index_fallback])
.mount("/", FileServer::new("../frontend/dist"))
.mount("/", FileServer::new("frontend/dist"))
}