Get/Set implementation for all RFC8620/8261 objects.

This commit is contained in:
Mauro D
2022-05-09 17:40:04 +00:00
parent 1680fdcd30
commit cd74566ca3
23 changed files with 1924 additions and 7 deletions

View 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()
}
}

View 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>,
}

View 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(),
}
}
}