Add first routes for accounts management
This commit is contained in:
35
moneymgr_backend/src/models/accounts.rs
Normal file
35
moneymgr_backend/src/models/accounts.rs
Normal file
@ -0,0 +1,35 @@
|
||||
use crate::models::users::UserID;
|
||||
use crate::schema::*;
|
||||
use diesel::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
|
||||
pub struct AccountID(pub i32);
|
||||
|
||||
#[derive(Queryable, Debug, Clone, serde::Serialize)]
|
||||
pub struct Account {
|
||||
id: i32,
|
||||
pub name: String,
|
||||
user_id: i32,
|
||||
pub time_create: i64,
|
||||
pub time_update: i64,
|
||||
pub default_account: bool,
|
||||
}
|
||||
|
||||
impl Account {
|
||||
pub fn id(&self) -> AccountID {
|
||||
AccountID(self.id)
|
||||
}
|
||||
|
||||
pub fn user_id(&self) -> UserID {
|
||||
UserID(self.user_id)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[diesel(table_name = accounts)]
|
||||
pub struct NewAccount<'a> {
|
||||
pub name: &'a str,
|
||||
pub user_id: i32,
|
||||
pub time_create: i64,
|
||||
pub time_update: i64,
|
||||
}
|
@ -1,2 +1,3 @@
|
||||
pub mod accounts;
|
||||
pub mod tokens;
|
||||
pub mod users;
|
||||
|
@ -63,7 +63,7 @@ impl Token {
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[diesel(table_name = token)]
|
||||
#[diesel(table_name = tokens)]
|
||||
pub struct NewToken<'a> {
|
||||
pub name: &'a str,
|
||||
pub user_id: i32,
|
||||
|
Reference in New Issue
Block a user