раскидал структуру для монорепозитория
This commit is contained in:
41
backend/src/models/category.rs
Normal file
41
backend/src/models/category.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize, ToSchema)]
|
||||
#[sea_orm(table_name = "category")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub family_id: i32,
|
||||
pub name: String,
|
||||
pub limit_amount: Decimal,
|
||||
pub created_at: DateTime,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::family::Entity",
|
||||
from = "Column::FamilyId",
|
||||
to = "super::family::Column::Id"
|
||||
)]
|
||||
Family,
|
||||
|
||||
#[sea_orm(has_many = "super::expense::Entity")]
|
||||
Expense,
|
||||
}
|
||||
|
||||
impl Related<super::family::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Family.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::expense::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Expense.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
32
backend/src/models/expense.rs
Normal file
32
backend/src/models/expense.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize, ToSchema)]
|
||||
#[sea_orm(table_name = "expense")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub category_id: i32,
|
||||
pub amount: Decimal,
|
||||
pub description: Option<String>,
|
||||
pub created_at: DateTime,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::category::Entity",
|
||||
from = "Column::CategoryId",
|
||||
to = "super::category::Column::Id"
|
||||
)]
|
||||
Category,
|
||||
}
|
||||
|
||||
impl Related<super::category::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Category.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
25
backend/src/models/family.rs
Normal file
25
backend/src/models/family.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize, ToSchema)]
|
||||
#[sea_orm(table_name = "family")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::category::Entity")]
|
||||
Category,
|
||||
}
|
||||
|
||||
impl Related<super::category::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Category.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
9
backend/src/models/mod.rs
Normal file
9
backend/src/models/mod.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
pub mod family;
|
||||
pub mod category;
|
||||
pub mod expense;
|
||||
pub mod user;
|
||||
|
||||
pub use family::Entity as Family;
|
||||
pub use category::Entity as Category;
|
||||
pub use expense::Entity as Expense;
|
||||
pub use user::Entity as User;
|
||||
18
backend/src/models/user.rs
Normal file
18
backend/src/models/user.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "user")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
#[sea_orm(unique)]
|
||||
pub username: String,
|
||||
pub password_hash: String,
|
||||
pub is_admin: bool,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
Reference in New Issue
Block a user