icinga2_api/api/action/
remove_comment.rs1use serde::{Deserialize, Serialize};
6
7use crate::types::action::StatusResponse;
8use crate::types::enums::object_type::IcingaObjectType;
9use crate::types::filter::IcingaFilter;
10use crate::types::query::ResultsWrapper;
11use crate::types::rest::{RestApiEndpoint, RestApiResponse};
12
13#[derive(Debug, Clone, derive_builder::Builder, Serialize, Deserialize)]
15#[builder(
16 build_fn(error = "crate::error::Error", validate = "Self::validate"),
17 derive(Debug)
18)]
19pub struct RemoveComment {
20 author: String,
22 #[builder(default, setter(strip_option, into))]
24 #[serde(flatten)]
25 filter: Option<IcingaFilter>,
26}
27
28impl RemoveComment {
29 #[must_use]
33 pub fn builder() -> RemoveCommentBuilder {
34 RemoveCommentBuilder::default()
35 }
36}
37
38impl RemoveCommentBuilder {
39 pub fn validate(&self) -> Result<(), crate::error::Error> {
45 if let Some(Some(filter)) = &self.filter {
46 if filter.object_type != IcingaObjectType::Host
47 && filter.object_type != IcingaObjectType::Service
48 {
49 Err(crate::error::Error::FilterObjectTypeMismatch(
50 vec![IcingaObjectType::Host, IcingaObjectType::Service],
51 filter.object_type.to_owned(),
52 ))
53 } else {
54 Ok(())
55 }
56 } else {
57 Ok(())
58 }
59 }
60}
61
62impl RestApiEndpoint for RemoveComment {
63 type RequestBody = RemoveComment;
64
65 fn method(&self) -> Result<reqwest::Method, crate::error::Error> {
66 Ok(reqwest::Method::POST)
67 }
68
69 fn url(&self, base_url: &url::Url) -> Result<url::Url, crate::error::Error> {
70 base_url
71 .join("v1/actions/remove-comment")
72 .map_err(crate::error::Error::CouldNotParseUrlFragment)
73 }
74
75 fn request_body(
76 &self,
77 ) -> Result<Option<std::borrow::Cow<Self::RequestBody>>, crate::error::Error>
78 where
79 Self::RequestBody: Clone + serde::Serialize + std::fmt::Debug,
80 {
81 Ok(Some(std::borrow::Cow::Borrowed(self)))
82 }
83}
84
85impl RestApiResponse<RemoveComment> for ResultsWrapper<StatusResponse> {}