diff options
Diffstat (limited to 'src/validation/payment.rs')
-rw-r--r-- | src/validation/payment.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/validation/payment.rs b/src/validation/payment.rs new file mode 100644 index 0000000..36aa852 --- /dev/null +++ b/src/validation/payment.rs @@ -0,0 +1,25 @@ +use std::collections::HashMap; + +use crate::model::payment::{Create, Update}; +use crate::validation::utils::*; + +pub fn create(form: &HashMap<String, String>) -> Option<Create> { + Some(Create { + name: non_empty(form, "name")?, + cost: parse::<i64>(form, "cost")?, + user_id: parse::<i64>(form, "user_id")?, + category_id: parse::<i64>(form, "category_id")?, + date: date(form, "date")?, + frequency: frequency(form, "frequency")?, + }) +} + +pub fn update(form: &HashMap<String, String>) -> Option<Update> { + Some(Update { + name: non_empty(form, "name")?, + cost: parse::<i64>(form, "cost")?, + user_id: parse::<i64>(form, "user_id")?, + category_id: parse::<i64>(form, "category_id")?, + date: date(form, "date")?, + }) +} |