Can create a movement
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
pub mod accounts;
|
||||
pub mod files;
|
||||
pub mod movements;
|
||||
pub mod tokens;
|
||||
pub mod users;
|
||||
|
47
moneymgr_backend/src/models/movements.rs
Normal file
47
moneymgr_backend/src/models/movements.rs
Normal file
@ -0,0 +1,47 @@
|
||||
use crate::models::accounts::AccountID;
|
||||
use crate::models::files::FileID;
|
||||
use crate::schema::*;
|
||||
use diesel::{Insertable, Queryable};
|
||||
|
||||
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
|
||||
pub struct MovementID(pub i32);
|
||||
|
||||
#[derive(Queryable, Debug, Clone, serde::Serialize)]
|
||||
pub struct Movement {
|
||||
id: i32,
|
||||
account_id: i32,
|
||||
pub time: i64,
|
||||
pub label: String,
|
||||
file_id: Option<i32>,
|
||||
pub amount: f32,
|
||||
pub checked: bool,
|
||||
pub time_create: i64,
|
||||
pub time_update: i64,
|
||||
}
|
||||
|
||||
impl Movement {
|
||||
pub fn id(&self) -> MovementID {
|
||||
MovementID(self.id)
|
||||
}
|
||||
|
||||
pub fn account_id(&self) -> AccountID {
|
||||
AccountID(self.account_id)
|
||||
}
|
||||
|
||||
pub fn file_id(&self) -> Option<FileID> {
|
||||
self.file_id.map(FileID)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Insertable, Debug)]
|
||||
#[diesel(table_name = movements)]
|
||||
pub struct NewMovement<'a> {
|
||||
pub account_id: i32,
|
||||
pub time: i64,
|
||||
pub label: &'a str,
|
||||
pub file_id: Option<i32>,
|
||||
pub amount: f32,
|
||||
pub checked: bool,
|
||||
pub time_create: i64,
|
||||
pub time_update: i64,
|
||||
}
|
Reference in New Issue
Block a user