impl DomainExtention for FolderConfig and create corresponding types and

constructors
This commit is contained in:
Vincent Stuyck 2025-12-20 01:59:41 +01:00
parent 52cff0c9fa
commit 91be1f0acb

View File

@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::fmt::Display;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
@ -41,6 +42,57 @@ pub struct FolderAttributes {
// pub management: ManagementProtocol,
}
impl FolderAttributes {
pub fn set_site(&mut self, site: String) {
self.site = Some(site.to_string());
}
pub fn with_site(mut self, site: String) -> Self {
self.set_site(site);
self
}
pub fn set_contactgroups(&mut self, contactgroups: HostContactGroups) {
self.contactgroups = Some(contactgroups);
}
pub fn with_contactgroups(mut self, contactgroups: HostContactGroups) -> Self {
self.set_contactgroups(contactgroups);
self
}
pub fn add_parent(&mut self, parent: impl Display) {
self.parents.push(parent.to_string());
}
pub fn with_parent(mut self, parent: impl Display) -> Self {
self.add_parent(parent);
self
}
pub fn set_snmp_community(&mut self, community: SnmpCommunity) {
self.snmp_community = Some(community);
}
pub fn with_snmp_community(mut self, community: SnmpCommunity) -> Self {
self.set_snmp_community(community);
self
}
pub fn add_label(&mut self, labelkey: String, labelvalue: String) {
self.labels.insert(labelkey, labelvalue);
}
pub fn with_label(mut self, taggroup: String, tagvalue: String) -> Self {
self.add_label(taggroup, tagvalue);
self
}
pub fn add_tag(&mut self, taggroup: impl Display, tagvalue: String) {
self.tags
.insert(format!("tag_{taggroup}"), tagvalue.to_string());
}
pub fn with_tag(mut self, taggroup: impl Display, tagvalue: String) -> Self {
self.add_tag(taggroup, tagvalue);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MetaData {
pub created_at: DateTime<Utc>,
@ -49,6 +101,94 @@ pub struct MetaData {
pub created_by: Option<String>,
}
// impl DomainExtention for FolderConfig {
impl DomainExtention for FolderConfig {
const DOMAIN_TYPE: super::DomainType = super::DomainType::FolderConfig;
// }
type CreationRequest = FolderCreationRequest;
type CreationQuery = FolderCreationQuery;
type ReadQuery = FolderReadQuery;
type UpdateRequest = FolderUpdateRequest;
type DeleteQuery = FolderDeleteQuery;
}
#[derive(Debug, Serialize)]
pub struct FolderCreationRequest {
pub name: String,
pub title: String,
pub parent: String,
pub attributes: FolderAttributes
}
impl FolderCreationRequest {
pub fn new(
name: String,
title: String,
parent: String,
attributes: FolderAttributes
) -> Self {
Self {
name,
title,
parent,
attributes,
}
}
}
#[derive(Debug, Serialize)]
pub struct FolderCreationQuery;
#[derive(Debug, Serialize)]
pub struct FolderReadQuery;
#[derive(Debug, Serialize)]
pub struct FolderUpdateRequest {
pub title: String,
pub attributes: Option<FolderAttributes>,
pub update_attributes: Option<FolderAttributes>,
pub remove_attributes: Option<FolderAttributes>,
}
impl FolderUpdateRequest {
pub fn replace(title: String, attributes: FolderAttributes) -> Self {
Self {
title,
attributes: Some(attributes),
update_attributes: None,
remove_attributes: None
}
}
pub fn update(title: String, attributes: FolderAttributes) -> Self {
Self {
title,
attributes: None,
update_attributes: Some(attributes),
remove_attributes: None
}
}
pub fn remove(title: String, attributes: FolderAttributes) -> Self {
Self {
title,
attributes: None,
update_attributes: None,
remove_attributes: Some(attributes)
}
}
}
#[derive(Debug, Serialize)]
pub struct FolderDeleteQuery {
pub delete_mode: FolderDeleteMode
}
impl FolderDeleteQuery {
pub fn new(delete_mode: FolderDeleteMode) -> Self {
Self { delete_mode }
}
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum FolderDeleteMode {
Recursive,
AbotyOnNonEmpty
}