diff options
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/event.rs | 14 | ||||
-rw-r--r-- | src/model/mod.rs | 1 | ||||
-rw-r--r-- | src/model/repetition.rs | 26 |
3 files changed, 40 insertions, 1 deletions
diff --git a/src/model/event.rs b/src/model/event.rs index 7ab0244..3765fec 100644 --- a/src/model/event.rs +++ b/src/model/event.rs @@ -2,6 +2,8 @@ use chrono::Timelike; use chrono::{NaiveDate, NaiveTime}; use uuid::Uuid; +use crate::model::repetition::Repetition; + pub static DATE_FORMAT: &str = "%d/%m/%Y"; #[derive(Debug, Clone)] @@ -11,6 +13,7 @@ pub struct Event { pub start: Option<NaiveTime>, pub end: Option<NaiveTime>, pub name: String, + pub repetition: Option<Repetition>, } pub fn init(date: NaiveDate) -> Event { @@ -20,6 +23,7 @@ pub fn init(date: NaiveDate) -> Event { start: None, end: None, name: "".to_string(), + repetition: None, } } @@ -62,7 +66,14 @@ fn parse_time(t: &str) -> Option<NaiveTime> { // Validation -pub fn validate(id: Uuid, date: String, name: String, start: String, end: String) -> Option<Event> { +pub fn validate( + id: Uuid, + date: String, + name: String, + start: String, + end: String, + repetition: Option<Repetition>, +) -> Option<Event> { let start = validate_time(start)?; let end = validate_time(end)?; @@ -77,6 +88,7 @@ pub fn validate(id: Uuid, date: String, name: String, start: String, end: String name: validate_name(name)?, start, end, + repetition, }) } diff --git a/src/model/mod.rs b/src/model/mod.rs index 53f1126..c1beb62 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -1 +1,2 @@ pub mod event; +pub mod repetition; diff --git a/src/model/repetition.rs b/src/model/repetition.rs new file mode 100644 index 0000000..80387d9 --- /dev/null +++ b/src/model/repetition.rs @@ -0,0 +1,26 @@ +use chrono::Weekday; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub enum Repetition { + Daily { frequency: u8 }, + Monthly { frequency: MonthFrequency }, + Yearly, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub enum MonthFrequency { + Day { day: u8 }, + FirstDay { day: Weekday }, +} + +// Validation + +pub fn validate_day(str: &str) -> Option<u8> { + let n = str.parse::<u8>().ok()?; + if n >= 1 && n <= 31 { + Some(n) + } else { + None + } +} |