From 5166efe517291f5c9fc6326f30651ef799d6db65 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 9 Jan 2022 13:39:10 +0100 Subject: Add id in event model --- src/model/event.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/model') 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, pub end: Option, @@ -50,7 +52,7 @@ fn parse_time(t: &str) -> Option { // Validation -pub fn validate(date: String, name: String, start: String, end: String) -> Option { +pub fn validate(id: Uuid, date: String, name: String, start: String, end: String) -> Option { 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, -- cgit v1.2.3