Get/Set implementation for all RFC8620/8261 objects.
This commit is contained in:
33
src/vacation_response/get.rs
Normal file
33
src/vacation_response/get.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use crate::Get;
|
||||
|
||||
use super::VacationResponse;
|
||||
|
||||
impl VacationResponse<Get> {
|
||||
pub fn id(&self) -> &str {
|
||||
self.id.as_ref().unwrap()
|
||||
}
|
||||
|
||||
pub fn is_enabled(&self) -> bool {
|
||||
self.is_enabled.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn from_date(&self) -> Option<i64> {
|
||||
self.from_date.as_ref().map(|dt| dt.timestamp())
|
||||
}
|
||||
|
||||
pub fn to_date(&self) -> Option<i64> {
|
||||
self.to_date.as_ref().map(|dt| dt.timestamp())
|
||||
}
|
||||
|
||||
pub fn subject(&self) -> Option<&str> {
|
||||
self.subject.as_deref()
|
||||
}
|
||||
|
||||
pub fn text_body(&self) -> Option<&str> {
|
||||
self.text_body.as_deref()
|
||||
}
|
||||
|
||||
pub fn html_body(&self) -> Option<&str> {
|
||||
self.html_body.as_deref()
|
||||
}
|
||||
}
|
||||
42
src/vacation_response/mod.rs
Normal file
42
src/vacation_response/mod.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
pub mod get;
|
||||
pub mod set;
|
||||
|
||||
use crate::core::set::date_not_set;
|
||||
use crate::core::set::string_not_set;
|
||||
use crate::Get;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct VacationResponse<State = Get> {
|
||||
#[serde(skip)]
|
||||
_state: std::marker::PhantomData<State>,
|
||||
|
||||
#[serde(rename = "id")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
id: Option<String>,
|
||||
|
||||
#[serde(rename = "isEnabled")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
is_enabled: Option<bool>,
|
||||
|
||||
#[serde(rename = "fromDate")]
|
||||
#[serde(skip_serializing_if = "date_not_set")]
|
||||
from_date: Option<DateTime<Utc>>,
|
||||
|
||||
#[serde(rename = "toDate")]
|
||||
#[serde(skip_serializing_if = "date_not_set")]
|
||||
to_date: Option<DateTime<Utc>>,
|
||||
|
||||
#[serde(rename = "subject")]
|
||||
#[serde(skip_serializing_if = "string_not_set")]
|
||||
subject: Option<String>,
|
||||
|
||||
#[serde(rename = "textBody")]
|
||||
#[serde(skip_serializing_if = "string_not_set")]
|
||||
text_body: Option<String>,
|
||||
|
||||
#[serde(rename = "htmlBody")]
|
||||
#[serde(skip_serializing_if = "string_not_set")]
|
||||
html_body: Option<String>,
|
||||
}
|
||||
50
src/vacation_response/set.rs
Normal file
50
src/vacation_response/set.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
use crate::{core::set::from_timestamp, Set};
|
||||
|
||||
use super::VacationResponse;
|
||||
|
||||
impl VacationResponse<Set> {
|
||||
pub fn is_enabled(mut self, is_enabled: bool) -> Self {
|
||||
self.is_enabled = Some(is_enabled);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn from_date(mut self, from_date: Option<i64>) -> Self {
|
||||
self.from_date = from_date.map(from_timestamp);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn to_date(mut self, to_date: Option<i64>) -> Self {
|
||||
self.to_date = to_date.map(from_timestamp);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn subject(mut self, subject: Option<String>) -> Self {
|
||||
self.subject = subject;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn text_body(mut self, text_body: Option<String>) -> Self {
|
||||
self.text_body = text_body;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn html_body(mut self, html_body: Option<String>) -> Self {
|
||||
self.html_body = html_body;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl VacationResponse {
|
||||
pub fn new() -> VacationResponse<Set> {
|
||||
VacationResponse {
|
||||
_state: Default::default(),
|
||||
id: None,
|
||||
is_enabled: None,
|
||||
from_date: from_timestamp(0).into(),
|
||||
to_date: from_timestamp(0).into(),
|
||||
subject: "".to_string().into(),
|
||||
text_body: "".to_string().into(),
|
||||
html_body: "".to_string().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user