fix transaction

This commit is contained in:
yash 2024-01-22 20:07:02 +03:00
parent d16cc65a44
commit a28beb0e9c
1 changed files with 6 additions and 6 deletions

View File

@ -42,7 +42,7 @@ func (s *Storage) AddRecipe(ctx context.Context, recipe models.Recipe) error {
var id uint
// insert recipe
err = s.db.QueryRow(
err = tx.QueryRow(
ctx,
"insert into recipe (title, description, image, cooking_time, servings, cal) values ($1, $2, $3, $4, $5, $6) returning id",
recipe.Title, recipe.Description, recipe.Image, recipe.CookingTime, recipe.ServingsNum, recipe.Calories,
@ -54,7 +54,7 @@ func (s *Storage) AddRecipe(ctx context.Context, recipe models.Recipe) error {
// insert ingredients
for _, r := range recipe.Ingredients {
var ing_id uint
err = s.db.QueryRow(
err = tx.QueryRow(
ctx,
"insert into recipe_ingredients_group (recipe_id, title) values ($1, $2) returning id",
id, r.Title,
@ -64,7 +64,7 @@ func (s *Storage) AddRecipe(ctx context.Context, recipe models.Recipe) error {
}
for _, i := range r.Ingredients {
_, err = s.db.Exec(
_, err = tx.Exec(
ctx,
"insert into recipe_ingredients (recipe_ingredients_group_id, ingredient) values ($1, $2)",
ing_id, i,
@ -77,7 +77,7 @@ func (s *Storage) AddRecipe(ctx context.Context, recipe models.Recipe) error {
// insert steps
for i, step := range recipe.Recipe_steps {
_, err = s.db.Exec(
_, err = tx.Exec(
ctx,
"insert into recipe_steps (recipe_id, step_num, step_text) values ($1, $2, $3)",
id, i, step,
@ -89,7 +89,7 @@ func (s *Storage) AddRecipe(ctx context.Context, recipe models.Recipe) error {
// insert advices
for _, a := range recipe.Advices {
_, err = s.db.Exec(
_, err = tx.Exec(
ctx,
"insert into recipe_advices (recipe_id, advice) values ($1, $2)",
id, a,
@ -101,7 +101,7 @@ func (s *Storage) AddRecipe(ctx context.Context, recipe models.Recipe) error {
// insert categories
for _, c := range recipe.Categories {
_, err = s.db.Exec(
_, err = tx.Exec(
ctx,
"insert into recipe_categories (recipe_id, category) values ($1, $2)",
id, c,