2021-02-03 23:03:47 +01:00
|
|
|
use crate::backend::{Backend, Person};
|
2020-11-28 22:01:59 +01:00
|
|
|
use anyhow::Result;
|
2020-11-22 11:17:27 +01:00
|
|
|
|
|
|
|
|
impl Backend {
|
|
|
|
|
/// Get all available persons from the server.
|
|
|
|
|
pub async fn get_persons(&self) -> Result<Vec<Person>> {
|
2020-11-28 22:01:59 +01:00
|
|
|
let body = self.get("persons").await?;
|
2020-11-22 11:17:27 +01:00
|
|
|
let persons: Vec<Person> = serde_json::from_str(&body)?;
|
|
|
|
|
Ok(persons)
|
|
|
|
|
}
|
2020-11-28 22:01:59 +01:00
|
|
|
|
2020-11-29 01:00:19 +01:00
|
|
|
/// Post a new person to the server.
|
2020-11-28 22:01:59 +01:00
|
|
|
pub async fn post_person(&self, data: &Person) -> Result<()> {
|
|
|
|
|
self.post("persons", serde_json::to_string(data)?).await?;
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
2020-11-22 11:17:27 +01:00
|
|
|
}
|