aboutsummaryrefslogtreecommitdiff
path: root/src/validation/income.rs
blob: 972e42a754de2b765f3065878ef2cc889cdb327e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use std::collections::HashMap;

use crate::model::income::{Create, Update};
use crate::validation::utils::*;

pub fn create(form: &HashMap<String, String>) -> Option<Create> {
    Some(Create {
        user_id: parse::<i64>(form, "user_id")?,
        amount: parse::<i64>(form, "amount")?,
        month: parse::<u32>(form, "month")?,
        year: parse::<i32>(form, "year")?,
    })
}

pub fn update(form: &HashMap<String, String>) -> Option<Update> {
    Some(Update {
        user_id: parse::<i64>(form, "user_id")?,
        amount: parse::<i64>(form, "amount")?,
        month: parse::<u32>(form, "month")?,
        year: parse::<i32>(form, "year")?,
    })
}