mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Add medium client
This commit is contained in:
parent
3c61fd4568
commit
7dec8f76fe
3 changed files with 31 additions and 0 deletions
27
src/backend/client/mediums.rs
Normal file
27
src/backend/client/mediums.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
use super::Backend;
|
||||||
|
use crate::database::Medium;
|
||||||
|
use anyhow::Result;
|
||||||
|
|
||||||
|
impl Backend {
|
||||||
|
/// Get all available mediums from the server, that contain the specified
|
||||||
|
/// recording.
|
||||||
|
pub async fn get_mediums_for_recording(&self, recording_id: &str) -> Result<Vec<Medium>> {
|
||||||
|
let body = self.get(&format!("recordings/{}/mediums", recording_id)).await?;
|
||||||
|
let mediums: Vec<Medium> = serde_json::from_str(&body)?;
|
||||||
|
Ok(mediums)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get all available mediums from the server, that match the specified
|
||||||
|
/// DiscID.
|
||||||
|
pub async fn get_mediums_by_discid(&self, discid: &str) -> Result<Vec<Medium>> {
|
||||||
|
let body = self.get(&format!("discids/{}/mediums", discid)).await?;
|
||||||
|
let mediums: Vec<Medium> = serde_json::from_str(&body)?;
|
||||||
|
Ok(mediums)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Post a new medium to the server.
|
||||||
|
pub async fn post_medium(&self, data: &Medium) -> Result<()> {
|
||||||
|
self.post("mediums", serde_json::to_string(data)?).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,6 +13,9 @@ pub use ensembles::*;
|
||||||
pub mod instruments;
|
pub mod instruments;
|
||||||
pub use instruments::*;
|
pub use instruments::*;
|
||||||
|
|
||||||
|
pub mod mediums;
|
||||||
|
pub use mediums::*;
|
||||||
|
|
||||||
pub mod persons;
|
pub mod persons;
|
||||||
pub use persons::*;
|
pub use persons::*;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ run_command(
|
||||||
sources = files(
|
sources = files(
|
||||||
'backend/client/ensembles.rs',
|
'backend/client/ensembles.rs',
|
||||||
'backend/client/instruments.rs',
|
'backend/client/instruments.rs',
|
||||||
|
'backend/client/mediums.rs',
|
||||||
'backend/client/mod.rs',
|
'backend/client/mod.rs',
|
||||||
'backend/client/persons.rs',
|
'backend/client/persons.rs',
|
||||||
'backend/client/recordings.rs',
|
'backend/client/recordings.rs',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue