From 3932daa26360d6e03807381d0b8ffa2d0e704847 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 17 Apr 2023 20:56:53 +0200 Subject: Validate income date from body --- src/validation/income.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/validation') diff --git a/src/validation/income.rs b/src/validation/income.rs index 972e42a..0579f4a 100644 --- a/src/validation/income.rs +++ b/src/validation/income.rs @@ -1,22 +1,27 @@ +use chrono::NaiveDate; use std::collections::HashMap; use crate::model::income::{Create, Update}; use crate::validation::utils::*; pub fn create(form: &HashMap) -> Option { + let month = parse::(form, "month")?; + let year = parse::(form, "year")?; + Some(Create { user_id: parse::(form, "user_id")?, amount: parse::(form, "amount")?, - month: parse::(form, "month")?, - year: parse::(form, "year")?, + date: NaiveDate::from_ymd_opt(year, month, 1)?, }) } pub fn update(form: &HashMap) -> Option { + let month = parse::(form, "month")?; + let year = parse::(form, "year")?; + Some(Update { user_id: parse::(form, "user_id")?, amount: parse::(form, "amount")?, - month: parse::(form, "month")?, - year: parse::(form, "year")?, + date: NaiveDate::from_ymd_opt(year, month, 1)?, }) } -- cgit v1.2.3