Add first routes for accounts management

This commit is contained in:
2025-04-03 23:14:55 +02:00
parent 03f57a0ad7
commit 72e67d9e91
14 changed files with 202 additions and 43 deletions

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

View File

@ -1,2 +1,3 @@
pub mod accounts;
pub mod tokens;
pub mod users;

View File

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