singles
This commit is contained in:
parent
52482085bc
commit
952129d454
2 changed files with 22 additions and 6 deletions
|
@ -2,7 +2,7 @@ use std::path::{Path, PathBuf};
|
|||
|
||||
use album::Album;
|
||||
use artist::Artist;
|
||||
use mongod::{Model, Referencable, Reference};
|
||||
use mongod::{reference_of, Model, Referencable, Reference};
|
||||
use mongodb::bson::doc;
|
||||
use serde_json::json;
|
||||
use track::Track;
|
||||
|
@ -127,10 +127,24 @@ impl Libary {
|
|||
}
|
||||
|
||||
pub async fn get_albums_by_artist(&self, artist: &str) -> Vec<Album> {
|
||||
let artist = format!("artist::{artist}");
|
||||
Album::find(doc! { "artist_id": artist}, None)
|
||||
.await
|
||||
.unwrap()
|
||||
Album::find(
|
||||
doc! { "artist_id": reference_of!(Artist, artist).unwrap()},
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub async fn get_singles_by_artist(&self, artist: &str) -> Vec<Track> {
|
||||
Track::find(
|
||||
doc! {
|
||||
"album_id": None::<String>,
|
||||
"artist_id": reference_of!(Artist, artist).unwrap()
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub async fn get_album_by_id(&self, album: &str) -> Option<Album> {
|
||||
|
|
|
@ -16,10 +16,12 @@ use crate::route::to_api;
|
|||
#[get("/artist/<artist_id>/albums")]
|
||||
pub async fn albums_route(artist_id: &str, lib: &State<Libary>) -> FallibleApiResponse {
|
||||
let albums = lib.get_albums_by_artist(artist_id).await;
|
||||
let singles = lib.get_singles_by_artist(artist_id).await;
|
||||
|
||||
Ok(json!({
|
||||
"artist": artist_id,
|
||||
"albums": to_api(&albums).await
|
||||
"albums": to_api(&albums).await,
|
||||
"singles": to_api(&singles).await
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue