add: profile connections, spotify connection
This commit is contained in:
parent
a5c2356940
commit
33ba576d4a
31 changed files with 931 additions and 19 deletions
42
crates/app/src/routes/api/v1/auth/connections/spotify.rs
Normal file
42
crates/app/src/routes/api/v1/auth/connections/spotify.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use axum::{response::IntoResponse, Extension, Json};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::{
|
||||
database::connections::spotify::SpotifyConnection,
|
||||
model::{
|
||||
auth::{ConnectionService, ExternalConnectionData},
|
||||
ApiReturn, Error,
|
||||
},
|
||||
};
|
||||
use crate::{get_user_from_token, State};
|
||||
|
||||
pub async fn create_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let mut user = match get_user_from_token!(jar, data) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
let con = (
|
||||
SpotifyConnection::connection(),
|
||||
ExternalConnectionData::default(),
|
||||
);
|
||||
|
||||
user.connections
|
||||
.insert(ConnectionService::Spotify, con.clone());
|
||||
|
||||
if let Err(e) = data
|
||||
.update_user_connections(user.id, user.connections)
|
||||
.await
|
||||
{
|
||||
return Json(e.into());
|
||||
}
|
||||
|
||||
Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Connection created".to_string(),
|
||||
payload: Some(con.0.data),
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue