aboutsummaryrefslogtreecommitdiff
path: root/src/validation/payment.rs
blob: 36aa852e0771008ff9fc80c9b55a3ca01966ce6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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")?,
    })
}