aboutsummaryrefslogtreecommitdiff
path: root/src/validation
diff options
context:
space:
mode:
Diffstat (limited to 'src/validation')
-rw-r--r--src/validation/income.rs13
1 files changed, 9 insertions, 4 deletions
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<String, String>) -> Option<Create> {
+ let month = parse::<u32>(form, "month")?;
+ let year = parse::<i32>(form, "year")?;
+
Some(Create {
user_id: parse::<i64>(form, "user_id")?,
amount: parse::<i64>(form, "amount")?,
- month: parse::<u32>(form, "month")?,
- year: parse::<i32>(form, "year")?,
+ date: NaiveDate::from_ymd_opt(year, month, 1)?,
})
}
pub fn update(form: &HashMap<String, String>) -> Option<Update> {
+ let month = parse::<u32>(form, "month")?;
+ let year = parse::<i32>(form, "year")?;
+
Some(Update {
user_id: parse::<i64>(form, "user_id")?,
amount: parse::<i64>(form, "amount")?,
- month: parse::<u32>(form, "month")?,
- year: parse::<i32>(form, "year")?,
+ date: NaiveDate::from_ymd_opt(year, month, 1)?,
})
}