[API-1] chore: little updates
This commit is contained in:
parent
96a091f068
commit
292ff60720
7 changed files with 121 additions and 37 deletions
|
@ -16,6 +16,7 @@ lazy_static! {
|
|||
}
|
||||
|
||||
pub fn init() {
|
||||
log::info!("Initializing db pool.");
|
||||
lazy_static::initialize(&POOL);
|
||||
let _conn = connection().expect("Failed to get db connection.");
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use jsonwebtoken::{decode, DecodingKey, EncodingKey, TokenData, Validation};
|
|||
const JWT_SECRET: &str = "secret";
|
||||
|
||||
pub fn get_token(token: &str) -> Result<TokenData<JWTClaims>, Error> {
|
||||
let token = decode::<JWTClaims>(&token, &get_decoding_key(), &Validation::default())?;
|
||||
let token = decode::<JWTClaims>(token, &get_decoding_key(), &Validation::default())?;
|
||||
Ok(token)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
use crate::middlewares::error::ErrorResponse;
|
||||
use crate::models::playlists::{PlaylistCreator, Playlists};
|
||||
use crate::models::tracks::TracksWithArtists;
|
||||
use actix_web::{get, web, HttpResponse};
|
||||
use actix_web::{get, web, HttpResponse, Scope};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub fn routes() -> Scope {
|
||||
web::scope("/playlists").service(get_playlist)
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
struct GetPlaylistResponse {
|
||||
pub id: String,
|
||||
|
@ -15,7 +19,7 @@ struct GetPlaylistResponse {
|
|||
}
|
||||
|
||||
#[get("/{playlist_id}")]
|
||||
pub async fn get_playlist(path: web::Path<String>) -> Result<HttpResponse, ErrorResponse> {
|
||||
async fn get_playlist(path: web::Path<String>) -> Result<HttpResponse, ErrorResponse> {
|
||||
let playlist_id = path.into_inner();
|
||||
let playlist = Playlists::find(playlist_id.as_str())?;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::middlewares::error::ErrorResponse;
|
||||
use crate::models::spotify;
|
||||
use crate::services::spotify as Spotify;
|
||||
use crate::{middlewares::error::ErrorResponse, models::tracks::Tracks};
|
||||
use actix_web::{get, web, HttpResponse, Result, Scope};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
@ -21,11 +21,18 @@ struct SearchResponse {
|
|||
#[derive(Serialize)]
|
||||
struct SearchTracks {
|
||||
pub id: String,
|
||||
pub title: String,
|
||||
// pub artists: String,
|
||||
pub duration_ms: i32,
|
||||
}
|
||||
|
||||
impl From<spotify::Track> for SearchTracks {
|
||||
fn from(value: spotify::Track) -> SearchTracks {
|
||||
SearchTracks { id: value.id }
|
||||
SearchTracks {
|
||||
id: value.id,
|
||||
title: value.name,
|
||||
duration_ms: value.duration_ms,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -106,8 +106,6 @@ impl Service for Spotify {
|
|||
.send()
|
||||
.await;
|
||||
|
||||
println!("Hello");
|
||||
|
||||
match response {
|
||||
Ok(res) => {
|
||||
let data = res.json::<SpotifyResponse>().await;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue