24 lines
611 B
Rust
24 lines
611 B
Rust
|
use mongodb::bson::doc;
|
||
|
use rocket::*;
|
||
|
use super::FallibleApiResponse;
|
||
|
use super::api_error;
|
||
|
|
||
|
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())
|
||
|
}
|