use super::api_error; use super::to_api; use super::FallibleApiResponse; use super::ToAPI; use fs::NamedFile; use mongod::Model; use mongodb::bson::doc; use rocket::*; use crate::library::artist::Artist; use crate::library::Libary; /// Get all artists #[get("/artists")] pub async fn artists_route(lib: &State) -> FallibleApiResponse { let artists = lib.get_artists().await; Ok(serde_json::to_value(&to_api(&artists).await).unwrap()) } #[get("/artist//image")] pub async fn artist_image_route(id: &str) -> Option { let image = Artist::get_image_of(id).await?; NamedFile::open(image).await.ok() } #[get("/artist/")] pub async fn artist_route(id: &str) -> FallibleApiResponse { Ok(Artist::get(id) .await .ok_or_else(|| api_error("No artist with that ID found"))? .api() .await) }