use std::fmt::Write;
use crate::client::client;
use crate::model::allocation;
use crate::model::{enums, types};
pub async fn allocation(
client: &client::Client,
id: types::UUID,
) -> Result<allocation::Allocation, Box<dyn std::error::Error>> {
Ok(client
.read::<allocation::Allocation>(&format!("allocations/{id}"), None)
.await?)
}
pub async fn allocations(
client: &client::Client,
assignment_type: Option<enums::AssignmentType>,
member: Option<types::UUID>,
start_date: Option<types::Date>,
end_date: Option<types::Date>,
) -> Result<allocation::Allocations, Box<dyn std::error::Error>> {
let mut params = String::from("limit=100");
if let Some(assignment_type) = assignment_type {
write!(params, "&assignmentTypeId={}", assignment_type)?;
}
if let Some(member) = member {
write!(params, "&memberId={}", member)?;
}
if let Some(start_date) = start_date {
write!(params, "&startOnBefore={}", start_date)?;
}
if let Some(end_date) = end_date {
write!(params, "&endOnAfter={}", end_date)?;
}
Ok(client
.read::<allocation::Allocations>("allocations", Some(¶ms))
.await?)
}
#[cfg(test)]
mod tests;