Add the ability to add users
All checks were successful
Build Crate / build (push) Successful in 3m25s
All checks were successful
Build Crate / build (push) Successful in 3m25s
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user