use crate::client::FishPi;
use crate::domain::breezemoon::Breezemoon;
use crate::ids::UserName;
use crate::utils::build_http_path;
use crate::utils::error::Error;
use crate::wire::breezemoon::WireBreezemoonList;
pub struct BreezemoonApi(pub(crate) FishPi);
impl FishPi {
pub fn breezemoon(&self) -> BreezemoonApi {
BreezemoonApi(self.clone())
}
}
impl BreezemoonApi {
pub async fn list(
&self,
page: u32,
size: u32,
user: Option<impl Into<UserName>>,
) -> Result<Vec<Breezemoon>, Error> {
let base = if let Some(u) = user {
format!("user/{}/", u.into())
} else {
String::new()
};
let path = build_http_path(
&format!("api/{}breezemoons", base),
&[
("p", page.to_string()),
("size", size.to_string()),
("apiKey", self.0.api_key().to_string()),
],
);
let wire: WireBreezemoonList = self.0.get_data(&path).await?;
Ok(wire.breezemoons.into_iter().map(Breezemoon::from).collect())
}
pub async fn send(&self, content: impl Into<String>) -> Result<(), Error> {
let body = serde_json::json!({
"apiKey": self.0.api_key().as_str(),
"breezemoonContent": content.into(),
});
self.0.post_raw("breezemoon", &body).await?;
Ok(())
}
}