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).await?; let uid = database::insert_user(spotify_uid.as_ref(), lobby.as_ref())?; spotify::load_profile(uid, spotify_uid.as_ref(), spotify_client).await } #[get("/token/")] pub fn token(name: String) -> Result { Ok(Redirect::to(spotify::token(name)?)) } #[get("/match//")] pub 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()) } #[get("/users/")] pub fn get_users(lobby: String) -> Result { database::get_users(lobby.as_str()) } //#[post("/lobby", format = "application/json", data = "")] #[post("/lobby/")] pub fn create_lobby(name: String) -> Result { database::create_lobby(name.as_str()) }