use std::sync::Arc;
use crate::{error::Result, http::HttpClient};
use super::types::*;
pub struct CustomFieldsApi {
http: Arc<HttpClient>,
}
impl CustomFieldsApi {
pub fn new(http: Arc<HttpClient>) -> Self {
Self { http }
}
pub async fn list(&self, location_id: &str) -> Result<GetCustomFieldsResponse> {
#[derive(serde::Serialize)]
struct Q<'a> {
#[serde(rename = "locationId")]
location_id: &'a str,
}
self.http
.get_with_query("/custom-fields", &Q { location_id })
.await
}
pub async fn get(&self, field_id: &str) -> Result<GetCustomFieldResponse> {
self.http.get(&format!("/custom-fields/{field_id}")).await
}
pub async fn create(
&self,
params: &CreateCustomFieldParams,
) -> Result<GetCustomFieldResponse> {
self.http.post("/custom-fields", params).await
}
pub async fn update(
&self,
field_id: &str,
params: &CreateCustomFieldParams,
) -> Result<GetCustomFieldResponse> {
self.http.put(&format!("/custom-fields/{field_id}"), params).await
}
pub async fn delete(&self, field_id: &str) -> Result<DeleteCustomFieldResponse> {
self.http.delete(&format!("/custom-fields/{field_id}")).await
}
}