use crate::database; use crate::errors::Error; use crate::spotify; use rocket::response::Redirect; #[get("/callback///")] pub async fn get_tracks(name: String, lobby: String, url: String) -> Result<(), Error> { let (spotify_uid, spotify_client) = spotify::auth_user(name.as_ref(), url.as_str()).await?; let uid = database::insert_user(spotify_uid.as_ref(), lobby.as_ref()).await?; spotify::load_profile(uid, spotify_uid.as_ref(), spotify_client).await } #[get("/token//")] pub fn token(name: String, token: String) -> Result { Ok(Redirect::to(spotify::token(name, token)?)) } #[get("/match//")] pub async fn match_users(lobby: String, names: String) -> Result { //let bytes = base64::decode_config(names, base64::URL_SAFE).unwrap(); //let names = String::from_utf8(bytes).unwrap(); let names: Vec<&str> = names.split(',').collect(); database::match_users(lobby, names.as_slice()).await } #[get("/users/")] pub async fn get_users(lobby: String) -> Result { database::get_users(lobby.as_str()).await } //#[post("/lobby", format = "application/json", data = "")] #[post("/lobby/")] pub async fn create_lobby(name: String) -> Result { database::create_lobby(name.as_str()).await }