Ingredients can now be manually ordered

This commit is contained in:
Greg Burri 2025-01-16 00:17:08 +01:00
parent afd42ba1d0
commit ca2227037f
11 changed files with 205 additions and 32 deletions

View file

@ -23,8 +23,8 @@ VALUES (
INSERT INTO [Recipe] ([id], [user_id], [title], [is_published], [creation_datetime])
VALUES (1, 1, 'Croissant au jambon', true, '2025-01-07T10:41:05.697884837+00:00');
INSERT INTO [Recipe] ([id], [user_id], [title], [is_published], [creation_datetime])
VALUES (2, 1, 'Gratin de thon aux olives', true, '2025-01-07T10:41:05.697884837+00:00');
INSERT INTO [Recipe] ([id], [user_id], [title], [is_published], [creation_datetime], [servings], [estimated_time], [difficulty])
VALUES (2, 1, 'Gratin de thon aux olives', true, '2025-01-07T10:41:05.697884837+00:00', 4, 40, 1);
INSERT INTO [Recipe] ([id], [user_id], [title], [is_published], [creation_datetime])
VALUES (3, 1, 'Saumon en croute', true, '2025-01-07T10:41:05.697884837+00:00');
@ -58,20 +58,20 @@ VALUES (2, 2, "Sel à l'origan", "", 1, "c-à-c");
INSERT INTO [Step] ([id], [order], [group_id], [action])
VALUES (3, 3, 2, "Mélanger au fouet et verser sur le thon dans le plat");
INSERT INTO [Ingredient] ([id], [step_id], [name], [comment], [quantity_value], [quantity_unit])
VALUES (3, 3, "Concentré de tomate", "", 4, "c-à-s");
INSERT INTO [Ingredient] ([id], [order], [step_id], [name], [comment], [quantity_value], [quantity_unit])
VALUES (3, 0, 3, "Concentré de tomate", "", 4, "c-à-s");
INSERT INTO [Ingredient] ([id], [step_id], [name], [comment], [quantity_value], [quantity_unit])
VALUES (4, 3, "Poivre", "", 0.25, "c-à-c");
INSERT INTO [Ingredient] ([id], [order], [step_id], [name], [comment], [quantity_value], [quantity_unit])
VALUES (4, 1, 3, "Poivre", "", 0.25, "c-à-c");
INSERT INTO [Ingredient] ([id], [step_id], [name], [comment], [quantity_value], [quantity_unit])
VALUES (5, 3, "Herbe de Provence", "", 0.5, "c-à-c");
INSERT INTO [Ingredient] ([id], [order], [step_id], [name], [comment], [quantity_value], [quantity_unit])
VALUES (5, 2, 3, "Herbe de Provence", "", 0.5, "c-à-c");
INSERT INTO [Ingredient] ([id], [step_id], [name], [comment], [quantity_value], [quantity_unit])
VALUES (6, 3, "Crème à café ou demi-crème", "", 2, "dl");
INSERT INTO [Ingredient] ([id], [order], [step_id], [name], [comment], [quantity_value], [quantity_unit])
VALUES (6, 3, 3, "Crème à café ou demi-crème", "", 2, "dl");
INSERT INTO [Ingredient] ([id], [step_id], [name], [comment], [quantity_value], [quantity_unit])
VALUES (7, 3, "Olives farcies coupées en deuxs", "", 50, "g");
INSERT INTO [Ingredient] ([id], [order], [step_id], [name], [comment], [quantity_value], [quantity_unit])
VALUES (7, 4, 3, "Olives farcies coupées en deuxs", "", 50, "g");
INSERT INTO [Group] ([id], [order], [recipe_id], [name], [comment])

View file

@ -56,6 +56,7 @@ CREATE TABLE [Recipe] (
[lang] TEXT NOT NULL DEFAULT 'en',
[estimated_time] INTEGER, -- in [s].
[description] TEXT NOT NULL DEFAULT '',
-- 0: Unknown, 1: Easy, 2: Medium, 4: Hard.
[difficulty] INTEGER NOT NULL DEFAULT 0,
[servings] INTEGER DEFAULT 4,
[is_published] INTEGER NOT NULL DEFAULT FALSE,
@ -64,6 +65,28 @@ CREATE TABLE [Recipe] (
FOREIGN KEY([user_id]) REFERENCES [User]([id]) ON DELETE SET NULL
) STRICT;
CREATE TRIGGER [Recipe_trigger_update_difficulty]
BEFORE UPDATE OF [difficulty]
ON [Recipe]
BEGIN
SELECT
CASE
WHEN NEW.[difficulty] < 0 OR NEW.[difficulty] > 3 THEN
RAISE (ABORT, 'Invalid [difficulty] value')
END;
END;
CREATE TRIGGER [Recipe_trigger_insert_difficulty]
BEFORE INSERT
ON [Recipe]
BEGIN
SELECT
CASE
WHEN NEW.[difficulty] < 0 OR NEW.[difficulty] > 3 THEN
RAISE (ABORT, 'Invalid [difficulty] value')
END;
END;
CREATE TABLE [Image] (
[Id] INTEGER PRIMARY KEY,
[recipe_id] INTEGER NOT NULL,
@ -124,6 +147,7 @@ CREATE INDEX [Step_order_index] ON [Group]([order]);
CREATE TABLE [Ingredient] (
[id] INTEGER PRIMARY KEY,
[order] INTEGER NOT NULL DEFAULT 0,
[step_id] INTEGER NOT NULL,
[name] TEXT NOT NULL DEFAULT '',
@ -134,14 +158,4 @@ CREATE TABLE [Ingredient] (
FOREIGN KEY([step_id]) REFERENCES [Step]([id]) ON DELETE CASCADE
) STRICT;
-- CREATE TABLE [IntermediateSubstance] (
-- [id] INTEGER PRIMARY KEY,
-- [name] TEXT NOT NULL DEFAULT '',
-- [quantity_value] REAL,
-- [quantity_unit] TEXT NOT NULL DEFAULT '',
-- [output_group_id] INTEGER NOT NULL,
-- [input_group_id] INTEGER NOT NULL,
-- FOREIGN KEY([output_group_id]) REFERENCES [group]([id]) ON DELETE CASCADE,
-- FOREIGN KEY([input_group_id]) REFERENCES [group]([id]) ON DELETE CASCADE
-- ) STRICT;
CREATE INDEX [Ingredient_order_index] ON [Ingredient]([order]);