server: Allow to store recipes
This commit is contained in:
parent
1c4d4a71e5
commit
82b466f52c
9 changed files with 281 additions and 1 deletions
|
|
@ -30,4 +30,13 @@ impl Related<super::household::Entity> for Entity {
|
|||
}
|
||||
}
|
||||
|
||||
impl Related<super::recipe::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
super::recipe_ingerdients::Relation::Recipe.def()
|
||||
}
|
||||
fn via() -> Option<RelationDef> {
|
||||
Some(super::recipe_ingerdients::Relation::Ingredient.def().rev())
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,7 @@ pub mod prelude;
|
|||
pub mod household;
|
||||
pub mod household_members;
|
||||
pub mod ingredient;
|
||||
pub mod recipe;
|
||||
pub mod recipe_ingerdients;
|
||||
pub mod recipe_steps;
|
||||
pub mod user;
|
||||
|
|
|
|||
|
|
@ -3,4 +3,7 @@
|
|||
pub use super::household::Entity as Household;
|
||||
pub use super::household_members::Entity as HouseholdMembers;
|
||||
pub use super::ingredient::Entity as Ingredient;
|
||||
pub use super::recipe::Entity as Recipe;
|
||||
pub use super::recipe_ingerdients::Entity as RecipeIngerdients;
|
||||
pub use super::recipe_steps::Entity as RecipeSteps;
|
||||
pub use super::user::Entity as User;
|
||||
|
|
|
|||
36
src/entity/recipe.rs
Normal file
36
src/entity/recipe.rs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "recipe")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i64,
|
||||
#[sea_orm(column_type = "Text")]
|
||||
pub name: String,
|
||||
pub ranking: i32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::recipe_steps::Entity")]
|
||||
RecipeSteps,
|
||||
}
|
||||
|
||||
impl Related<super::recipe_steps::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::RecipeSteps.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::ingredient::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
super::recipe_ingerdients::Relation::Ingredient.def()
|
||||
}
|
||||
fn via() -> Option<RelationDef> {
|
||||
Some(super::recipe_ingerdients::Relation::Recipe.def().rev())
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
48
src/entity/recipe_ingerdients.rs
Normal file
48
src/entity/recipe_ingerdients.rs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||
#[sea_orm(table_name = "recipe_ingerdients")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub recipe_id: i64,
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub ingredient_id: i64,
|
||||
#[sea_orm(column_type = "Double")]
|
||||
pub amount: f64,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::ingredient::Entity",
|
||||
from = "Column::IngredientId",
|
||||
to = "super::ingredient::Column::Id",
|
||||
on_update = "Restrict",
|
||||
on_delete = "Restrict"
|
||||
)]
|
||||
Ingredient,
|
||||
#[sea_orm(
|
||||
belongs_to = "super::recipe::Entity",
|
||||
from = "Column::RecipeId",
|
||||
to = "super::recipe::Column::Id",
|
||||
on_update = "Restrict",
|
||||
on_delete = "Restrict"
|
||||
)]
|
||||
Recipe,
|
||||
}
|
||||
|
||||
impl Related<super::ingredient::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Ingredient.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::recipe::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Recipe.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
34
src/entity/recipe_steps.rs
Normal file
34
src/entity/recipe_steps.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "recipe_steps")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub recipe_id: i64,
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub num: i32,
|
||||
#[sea_orm(column_type = "Text")]
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::recipe::Entity",
|
||||
from = "Column::RecipeId",
|
||||
to = "super::recipe::Column::Id",
|
||||
on_update = "Restrict",
|
||||
on_delete = "Restrict"
|
||||
)]
|
||||
Recipe,
|
||||
}
|
||||
|
||||
impl Related<super::recipe::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Recipe.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue