aboutsummaryrefslogtreecommitdiff
path: root/src/validation
diff options
context:
space:
mode:
authorJoris2023-04-17 20:56:53 +0200
committerJoris2023-04-17 20:56:53 +0200
commit3932daa26360d6e03807381d0b8ffa2d0e704847 (patch)
tree099f92c176ba783bccc5c307927e1effe7c2cd9c /src/validation
parent8dcb9c6fff82f9e353e0f92b417dd803199f4257 (diff)
Validate income date from body
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)?,
})
}