diff options
author | Joris | 2022-01-09 13:39:10 +0100 |
---|---|---|
committer | Joris | 2022-01-09 13:39:10 +0100 |
commit | 5166efe517291f5c9fc6326f30651ef799d6db65 (patch) | |
tree | 36df3d65c9e7218bff2264391032ecd28001a688 /src/model | |
parent | 99af88a840bef534540a4b273d24a8a17e7fc9b9 (diff) |
Add id in event model
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/event.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/model/event.rs b/src/model/event.rs index a0bdc85..27587bc 100644 --- a/src/model/event.rs +++ b/src/model/event.rs @@ -1,10 +1,12 @@ use chrono::Timelike; use chrono::{NaiveDate, NaiveTime}; +use uuid::Uuid; pub static DATE_FORMAT: &str = "%d/%m/%Y"; #[derive(Debug, Clone)] pub struct Event { + pub id: Uuid, pub date: NaiveDate, pub start: Option<NaiveTime>, pub end: Option<NaiveTime>, @@ -50,7 +52,7 @@ fn parse_time(t: &str) -> Option<NaiveTime> { // Validation -pub fn validate(date: String, name: String, start: String, end: String) -> Option<Event> { +pub fn validate(id: Uuid, date: String, name: String, start: String, end: String) -> Option<Event> { let start = validate_time(start)?; let end = validate_time(end)?; @@ -60,6 +62,7 @@ pub fn validate(date: String, name: String, start: String, end: String) -> Optio } Some(Event { + id, date: NaiveDate::parse_from_str(&date, DATE_FORMAT).ok()?, name: validate_name(name)?, start, |