diff --git a/src/model/mod.rs b/src/model/mod.rs index f25842fe10535cfe709d00ce1fabfc430233ae3e..a3e7f899ef399031d750c01b990f1ae0de083f31 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -1 +1,2 @@ +pub mod notification; pub mod subscriber; diff --git a/src/model/notification.rs b/src/model/notification.rs new file mode 100644 index 0000000000000000000000000000000000000000..23697e9ea45caa0931208dbc1d91f624df1176e1 --- /dev/null +++ b/src/model/notification.rs @@ -0,0 +1,40 @@ +use std::fmt::{Display, Formatter, Result}; + +use rocket::serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(crate = "rocket::serde")] +pub struct Notification { + pub product_title: String, + pub product_url: String, + pub product_type: String, + pub subscriber_name: String, + pub status: String, +} + +impl Display for Notification { + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + if self.status.to_uppercase().eq("CREATED") { + return write!( + f, + "Hello {}, let's try our new {} product: {}, only in BambangShop! Check it out: {}", + self.subscriber_name, + self.product_type.to_lowercase(), + self.product_title, + self.product_url + ); + } else if self.status.to_uppercase().eq("DELETED") { + return write!( + f, + "Hello {}, we informed that our {} product called {} already sold out...", + self.subscriber_name, + self.product_type.to_lowercase(), + self.product_title + ); + } else { + return write!(f, + "Hello {}, let's try our {} product: {}, grab it out before the stock ran out! Check it out: {}", + self.subscriber_name, self.product_type.to_lowercase(), self.product_title, self.product_url); + } + } +}