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 album::Album;
|
||||||
use artist::Artist;
|
use artist::Artist;
|
||||||
use mongod::{Model, Referencable, Reference};
|
use mongod::{reference_of, Model, Referencable, Reference};
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use track::Track;
|
use track::Track;
|
||||||
|
@ -127,8 +127,22 @@ impl Libary {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_albums_by_artist(&self, artist: &str) -> Vec<Album> {
|
pub async fn get_albums_by_artist(&self, artist: &str) -> Vec<Album> {
|
||||||
let artist = format!("artist::{artist}");
|
Album::find(
|
||||||
Album::find(doc! { "artist_id": artist}, None)
|
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
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,12 @@ use crate::route::to_api;
|
||||||
#[get("/artist/<artist_id>/albums")]
|
#[get("/artist/<artist_id>/albums")]
|
||||||
pub async fn albums_route(artist_id: &str, lib: &State<Libary>) -> FallibleApiResponse {
|
pub async fn albums_route(artist_id: &str, lib: &State<Libary>) -> FallibleApiResponse {
|
||||||
let albums = lib.get_albums_by_artist(artist_id).await;
|
let albums = lib.get_albums_by_artist(artist_id).await;
|
||||||
|
let singles = lib.get_singles_by_artist(artist_id).await;
|
||||||
|
|
||||||
Ok(json!({
|
Ok(json!({
|
||||||
"artist": artist_id,
|
"artist": artist_id,
|
||||||
"albums": to_api(&albums).await
|
"albums": to_api(&albums).await,
|
||||||
|
"singles": to_api(&singles).await
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue