2024-07-26 12:14:08 +00:00
|
|
|
use super::api_error;
|
|
|
|
use super::FallibleApiResponse;
|
2024-07-24 09:07:24 +00:00
|
|
|
use mongodb::bson::doc;
|
|
|
|
use rocket::*;
|
|
|
|
|
|
|
|
use crate::library::Libary;
|
|
|
|
|
|
|
|
/// Get all artists
|
|
|
|
#[get("/artists")]
|
|
|
|
pub async fn artists_route(lib: &State<Libary>) -> FallibleApiResponse {
|
|
|
|
let artists = lib.get_artists().await;
|
|
|
|
Ok(serde_json::to_value(&artists).unwrap())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/artist/<id>")]
|
|
|
|
pub async fn artist_route(id: &str, lib: &State<Libary>) -> FallibleApiResponse {
|
|
|
|
Ok(serde_json::to_value(
|
|
|
|
&lib.get_artist_by_id(id)
|
|
|
|
.await
|
|
|
|
.ok_or_else(|| api_error("No artist with that ID found"))?,
|
|
|
|
)
|
|
|
|
.unwrap())
|
|
|
|
}
|