Add the ability to add users
All checks were successful
Build Crate / build (push) Successful in 3m25s

This commit is contained in:
Jacob Kassman
2023-12-09 21:49:14 -05:00
parent cb5da9b966
commit 01eaf059dd
6 changed files with 99 additions and 8 deletions

View File

@@ -2,10 +2,11 @@
use crate::{
data::{
pool_match::{PoolMatch, PoolMatchList},
pool_match::{PoolMatch, PoolMatchList, UserList},
store::DATA,
},
endpoints::MATCH,
endpoints::USER,
};
use axum::{
extract::Json,
@@ -15,6 +16,7 @@ use std::thread;
pub fn register_routes(app: Router) -> Router {
let app = app.route(MATCH, post(post_match));
let app = app.route(USER, post(post_user));
app
}
@@ -32,3 +34,19 @@ async fn post_match(Json(pool_match): Json<PoolMatch>) -> Json<PoolMatchList> {
Json(matches)
}
async fn post_user(user: String) -> Json<UserList> {
// Update the store with the new match
let users = thread::spawn(move || {
// Get the store
let mut data = DATA.lock().unwrap();
let user_id = (*data).users.add_user(user);
println!("Added new user id: {}\nAll users: {:?}", user_id, (*data).users);
(*data).users.clone()
})
.join()
.unwrap();
Json(users)
}