Can create a movement

This commit is contained in:
2025-04-15 22:39:42 +02:00
parent 5a51dee8b0
commit b4cf6624f7
9 changed files with 160 additions and 0 deletions

@ -1,4 +1,5 @@
pub mod accounts;
pub mod files;
pub mod movements;
pub mod tokens;
pub mod users;

@ -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,
}