2024-07-26 12:14:08 +00:00
|
|
|
use super::api_error;
|
2024-08-01 14:36:54 +00:00
|
|
|
use super::to_api;
|
2024-07-26 12:14:08 +00:00
|
|
|
use super::FallibleApiResponse;
|
2024-08-01 14:36:54 +00:00
|
|
|
use super::ToAPI;
|
|
|
|
use mongod::Model;
|
2024-07-24 09:07:24 +00:00
|
|
|
use mongodb::bson::doc;
|
|
|
|
use rocket::*;
|
|
|
|
|
2024-08-01 14:36:54 +00:00
|
|
|
use crate::library::artist::Artist;
|
2024-07-24 09:07:24 +00:00
|
|
|
use crate::library::Libary;
|
|
|
|
|
|
|
|
/// Get all artists
|
|
|
|
#[get("/artists")]
|
|
|
|
pub async fn artists_route(lib: &State<Libary>) -> FallibleApiResponse {
|
|
|
|
let artists = lib.get_artists().await;
|
2024-08-01 14:36:54 +00:00
|
|
|
Ok(serde_json::to_value(&to_api(&artists).await).unwrap())
|
2024-07-24 09:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/artist/<id>")]
|
2024-08-01 14:36:54 +00:00
|
|
|
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)
|
2024-07-24 09:07:24 +00:00
|
|
|
}
|