Skip to content

Commit

Permalink
refactor!: rename recipe ingredient and recipe ingredient draft to re…
Browse files Browse the repository at this point in the history
…cipe step ingredient and draft respectively

This messes up the database migration.
  • Loading branch information
Toromyx committed Feb 6, 2024
1 parent 6b81bad commit 7a81616
Show file tree
Hide file tree
Showing 48 changed files with 721 additions and 677 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ Types of changes:

- Implement recipe editing
- Implement recipe files (image/video/audio) with optical character recognition
- Add field "quality" to recipe ingredients
- Add field "quality" to recipe step ingredients
- Implement getting external recipes
- Implement unit conversion

### Changed

- Improve user experience of adding multiple recipe ingredients
- Improve user experience of adding multiple recipe step ingredients
- **BREAKING**: Refactor database migrations to only be one per major version

## [0.0.2] - 2023-02-15
Expand Down
10 changes: 5 additions & 5 deletions docs/architecture/database/schema.puml
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ entity "Recipe Step" as recipe_step {
}
recipe_step }o--|| "recipe_id" recipe

entity "Recipe Ingredient" as recipe_ingredient {
entity "Recipe Step Ingredient" as recipe_step_ingredient {
id: INTEGER
--
order: INTEGER
quantity: ?REAL
unit: ?TEXT
quality: ?TEXT
}
recipe_ingredient }o--|| "step_id" recipe_step
recipe_step_ingredient }o--|| "recipe_id" recipe

entity "Recipe Ingredient Draft" as recipe_ingredient_draft {
entity "Recipe Step Ingredient Draft" as recipe_step_ingredient_draft {
id: INTEGER
--
order: INTEGER
text: TEXT
}
recipe_ingredient_draft }o--|| "step_id" recipe_step
recipe_step_ingredient_draft }o--|| "step_id" recipe_step

entity "Ingredient" as ingredient {
id: INTEGER
--
name: TEXT
}
ingredient "ingredient_id" ||--o{ recipe_ingredient
ingredient "ingredient_id" ||--o{ recipe_step_ingredient

entity "Recipe File" as recipe_file {
id: INTEGER
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/command/entity.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod ingredient;
pub mod recipe;
pub mod recipe_file;
pub mod recipe_ingredient;
pub mod recipe_ingredient_draft;
pub mod recipe_step;
pub mod recipe_step_ingredient;
pub mod recipe_step_ingredient_draft;
pub mod unit_name;
56 changes: 0 additions & 56 deletions src-tauri/src/command/entity/recipe_ingredient.rs

This file was deleted.

56 changes: 0 additions & 56 deletions src-tauri/src/command/entity/recipe_ingredient_draft.rs

This file was deleted.

56 changes: 56 additions & 0 deletions src-tauri/src/command/entity/recipe_step_ingredient.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use crate::{
command::error::{CommandError, CommandError::NotFound},
entity::recipe_step_ingredient::Model,
entity_crud::{
recipe_step_ingredient::{
RecipeStepIngredientCondition, RecipeStepIngredientCreate, RecipeStepIngredientCrud,
RecipeStepIngredientFilter, RecipeStepIngredientUpdate,
},
EntityCrudTrait,
},
};

#[tauri::command]
pub async fn entity_create_recipe_step_ingredient(
create: RecipeStepIngredientCreate,
) -> Result<i64, CommandError> {
let id = RecipeStepIngredientCrud::create(create).await?;
Ok(id)
}

#[tauri::command]
pub async fn entity_read_recipe_step_ingredient(id: i64) -> Result<Model, CommandError> {
let model_option = RecipeStepIngredientCrud::read(id).await?;
let model = model_option.ok_or(NotFound)?;
Ok(model)
}

#[tauri::command]
pub async fn entity_update_recipe_step_ingredient(
update: RecipeStepIngredientUpdate,
) -> Result<(), CommandError> {
RecipeStepIngredientCrud::update(update).await?;
Ok(())
}

#[tauri::command]
pub async fn entity_delete_recipe_step_ingredient(id: i64) -> Result<(), CommandError> {
RecipeStepIngredientCrud::delete(id).await?;
Ok(())
}

#[tauri::command]
pub async fn entity_list_recipe_step_ingredient(
filter: RecipeStepIngredientFilter,
) -> Result<Vec<i64>, CommandError> {
let list = RecipeStepIngredientCrud::list(filter).await?;
Ok(list)
}

#[tauri::command]
pub async fn entity_count_recipe_step_ingredient(
condition: Option<RecipeStepIngredientCondition>,
) -> Result<i64, CommandError> {
let count = RecipeStepIngredientCrud::count(condition).await?;
Ok(count)
}
57 changes: 57 additions & 0 deletions src-tauri/src/command/entity/recipe_step_ingredient_draft.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use crate::{
command::error::{CommandError, CommandError::NotFound},
entity::recipe_step_ingredient_draft::Model,
entity_crud::{
recipe_step_ingredient_draft::{
RecipeStepIngredientDraftCondition, RecipeStepIngredientDraftCreate,
RecipeStepIngredientDraftCrud, RecipeStepIngredientDraftFilter,
RecipeStepIngredientDraftUpdate,
},
EntityCrudTrait,
},
};

#[tauri::command]
pub async fn entity_create_recipe_step_ingredient_draft(
create: RecipeStepIngredientDraftCreate,
) -> Result<i64, CommandError> {
let id = RecipeStepIngredientDraftCrud::create(create).await?;
Ok(id)
}

#[tauri::command]
pub async fn entity_read_recipe_step_ingredient_draft(id: i64) -> Result<Model, CommandError> {
let model_option = RecipeStepIngredientDraftCrud::read(id).await?;
let model = model_option.ok_or(NotFound)?;
Ok(model)
}

#[tauri::command]
pub async fn entity_update_recipe_step_ingredient_draft(
update: RecipeStepIngredientDraftUpdate,
) -> Result<(), CommandError> {
RecipeStepIngredientDraftCrud::update(update).await?;
Ok(())
}

#[tauri::command]
pub async fn entity_delete_recipe_step_ingredient_draft(id: i64) -> Result<(), CommandError> {
RecipeStepIngredientDraftCrud::delete(id).await?;
Ok(())
}

#[tauri::command]
pub async fn entity_list_recipe_step_ingredient_draft(
filter: RecipeStepIngredientDraftFilter,
) -> Result<Vec<i64>, CommandError> {
let list = RecipeStepIngredientDraftCrud::list(filter).await?;
Ok(list)
}

#[tauri::command]
pub async fn entity_count_recipe_step_ingredient_draft(
condition: Option<RecipeStepIngredientDraftCondition>,
) -> Result<i64, CommandError> {
let count = RecipeStepIngredientDraftCrud::count(condition).await?;
Ok(count)
}
6 changes: 4 additions & 2 deletions src-tauri/src/command/external_recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use crate::{
entity_crud::{
recipe::{RecipeCreate, RecipeCrud},
recipe_file::{RecipeFileCreate, RecipeFileCreateUri, RecipeFileCrud},
recipe_ingredient_draft::{RecipeIngredientDraftCreate, RecipeIngredientDraftCrud},
recipe_step::{RecipeStepCreate, RecipeStepCrud},
recipe_step_ingredient_draft::{
RecipeStepIngredientDraftCreate, RecipeStepIngredientDraftCrud,
},
EntityCrudTrait,
},
};
Expand All @@ -27,7 +29,7 @@ pub async fn external_recipe(url: String) -> Result<i64, CommandError> {
.unwrap();
for (i, ingredient) in step.ingredients.into_iter().enumerate() {
tokio::spawn(async move {
RecipeIngredientDraftCrud::create(RecipeIngredientDraftCreate {
RecipeStepIngredientDraftCrud::create(RecipeStepIngredientDraftCreate {
order: (i + 1) as i64,
text: ingredient,
recipe_step_id,
Expand Down
10 changes: 5 additions & 5 deletions src-tauri/src/command/unit_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use sea_orm::{
use crate::{
command::error::CommandError,
database,
entity::{recipe_ingredient, unit_name},
entity::{recipe_step_ingredient, unit_name},
};

#[derive(EnumIter, DeriveIden)]
Expand All @@ -16,15 +16,15 @@ enum ResultColumn {

/// Get the unit names currently in use.
///
/// This includes values inside [`recipe_ingredient::Column::Unit`] and [`unit_name::Column::Name`].
/// This includes values inside [`recipe_step_ingredient::Column::Unit`] and [`unit_name::Column::Name`].
#[tauri::command]
pub async fn unit_list_get() -> Result<Vec<String>, CommandError> {
let db = database::connect().await;
let query = Query::select()
.column(recipe_ingredient::Column::Unit)
.column(recipe_step_ingredient::Column::Unit)
.distinct()
.from(recipe_ingredient::Entity.table_ref())
.and_where(Expr::col(recipe_ingredient::Column::Unit).is_not_null())
.from(recipe_step_ingredient::Entity.table_ref())
.and_where(Expr::col(recipe_step_ingredient::Column::Unit).is_not_null())
.union(
UnionType::Distinct,
Query::select()
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pub mod ingredient;
pub mod recipe;
pub mod recipe_file;
pub mod recipe_ingredient;
pub mod recipe_ingredient_draft;
pub mod recipe_step;
pub mod recipe_step_ingredient;
pub mod recipe_step_ingredient_draft;
pub mod unit_name;
8 changes: 4 additions & 4 deletions src-tauri/src/entity/ingredient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ pub struct Model {

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::recipe_ingredient::Entity")]
RecipeIngredient,
#[sea_orm(has_many = "super::recipe_step_ingredient::Entity")]
RecipeStepIngredient,
}

impl Related<super::recipe_ingredient::Entity> for Entity {
impl Related<super::recipe_step_ingredient::Entity> for Entity {
fn to() -> RelationDef {
Relation::RecipeIngredient.def()
Relation::RecipeStepIngredient.def()
}
}

Expand Down
8 changes: 4 additions & 4 deletions src-tauri/src/entity/recipe_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pub enum Relation {
on_delete = "Cascade"
)]
Recipe,
#[sea_orm(has_many = "super::recipe_ingredient::Entity")]
RecipeIngredient,
#[sea_orm(has_many = "super::recipe_step_ingredient::Entity")]
RecipeStepIngredient,
#[sea_orm(has_many = "super::recipe_file::Entity")]
RecipeFile,
}
Expand All @@ -42,9 +42,9 @@ impl Related<super::recipe::Entity> for Entity {
}
}

impl Related<super::recipe_ingredient::Entity> for Entity {
impl Related<super::recipe_step_ingredient::Entity> for Entity {
fn to() -> RelationDef {
Relation::RecipeIngredient.def()
Relation::RecipeStepIngredient.def()
}
}

Expand Down
Loading

0 comments on commit 7a81616

Please sign in to comment.