musicus/client/src/instruments.rs

21 lines
665 B
Rust
Raw Normal View History

2021-02-04 21:47:22 +01:00
use crate::{Client, Result};
2021-04-25 23:36:27 +02:00
use log::info;
2021-02-04 21:47:22 +01:00
use musicus_database::Instrument;
2020-11-28 23:07:31 +01:00
2021-02-04 21:47:22 +01:00
impl Client {
2020-11-28 23:07:31 +01:00
/// Get all available instruments from the server.
pub async fn get_instruments(&self) -> Result<Vec<Instrument>> {
2021-04-25 23:36:27 +02:00
info!("Get instruments");
2020-11-28 23:07:31 +01:00
let body = self.get("instruments").await?;
let instruments: Vec<Instrument> = serde_json::from_str(&body)?;
Ok(instruments)
}
2020-11-29 01:00:19 +01:00
/// Post a new instrument to the server.
2020-11-28 23:07:31 +01:00
pub async fn post_instrument(&self, data: &Instrument) -> Result<()> {
2021-04-25 23:36:27 +02:00
info!("Post instrument {:?}", data);
2020-11-28 23:07:31 +01:00
self.post("instruments", serde_json::to_string(data)?).await?;
Ok(())
}
}