use crate::Result;
use crate::UptrakitClient;
use crate::types_impl::batch_actions::{BatchActionRequest, BatchActionResponse};
use crate::types_impl::pagination::PaginatedResponse;
use crate::types_impl::system_services::{
ListSystemServicesQuery, SystemServiceResponse, UpdateSystemServiceRequest,
};
use uuid::Uuid;
impl UptrakitClient {
pub async fn list_system_services(
&self,
query: &ListSystemServicesQuery,
) -> Result<PaginatedResponse<SystemServiceResponse>> {
self.get_with_query(crate::paths::system_services::BASE, query)
.await
}
pub async fn list_all_system_services(
&self,
query: &ListSystemServicesQuery,
) -> Result<Vec<SystemServiceResponse>> {
self.fetch_all_pages(crate::paths::system_services::BASE, query)
.await
}
pub async fn get_system_service(&self, id: &Uuid) -> Result<SystemServiceResponse> {
self.get(&crate::paths::system_services::by_id(id)).await
}
pub async fn approve_system_service(&self, id: &Uuid) -> Result<SystemServiceResponse> {
self.post_empty(&crate::paths::system_services::approve(id))
.await
}
pub async fn reject_system_service(&self, id: &Uuid) -> Result<SystemServiceResponse> {
self.post_empty(&crate::paths::system_services::reject(id))
.await
}
pub async fn update_system_service(
&self,
id: &Uuid,
req: &UpdateSystemServiceRequest,
) -> Result<SystemServiceResponse> {
self.put_json(&crate::paths::system_services::by_id(id), req)
.await
}
pub async fn remove_system_service(&self, id: &Uuid) -> Result<()> {
self.delete(&crate::paths::system_services::by_id(id)).await
}
pub async fn batch_system_services(
&self,
req: &BatchActionRequest,
) -> Result<BatchActionResponse> {
self.post_json(crate::paths::system_services::BATCH, req)
.await
}
}
#[cfg(test)]
mod tests {
use crate::shared_types_impl::ServiceStatus;
use crate::types_impl::system_services::{ListSystemServicesQuery, UpdateSystemServiceRequest};
#[test]
fn list_system_services_query_serialization_with_all_fields() {
let query = ListSystemServicesQuery {
capability: Some("update_tracking".to_string()),
status: Some(ServiceStatus::Approved),
page: Some(2),
per_page: Some(50),
};
let qs = serde_urlencoded::to_string(&query).expect("serialize");
assert!(qs.contains("capability=update_tracking"));
assert!(qs.contains("status=approved"));
assert!(qs.contains("page=2"));
assert!(qs.contains("per_page=50"));
}
#[test]
fn list_system_services_query_serialization_skips_none() {
let query = ListSystemServicesQuery {
capability: None,
status: None,
page: None,
per_page: None,
};
let qs = serde_urlencoded::to_string(&query).expect("serialize");
assert!(qs.is_empty());
}
#[test]
fn update_system_service_request_cert_lifetime_hours_round_trip() {
let req = UpdateSystemServiceRequest {
ping_interval_seconds: None,
cert_lifetime_hours: Some(48),
};
let json = serde_json::to_string(&req).expect("serialize");
assert!(json.contains(r#""cert_lifetime_hours":48"#));
let parsed: UpdateSystemServiceRequest = serde_json::from_str(&json).expect("deserialize");
assert_eq!(parsed.cert_lifetime_hours, Some(48));
}
#[test]
fn update_system_service_request_omits_none_fields() {
let req = UpdateSystemServiceRequest {
ping_interval_seconds: None,
cert_lifetime_hours: None,
};
let json = serde_json::to_string(&req).expect("serialize");
assert!(!json.contains("ping_interval_seconds"));
assert!(!json.contains("cert_lifetime_hours"));
}
}