From 9d3a5fb85dc02e87fab879855c4c3bace5f753f2 Mon Sep 17 00:00:00 2001 From: xengineering Date: Fri, 17 May 2024 22:49:15 +0200 Subject: model: Fix direct access to database Instead a database transaction has to be used. Each database interaction should be wrapped into a transaction to make sure any possible change (even side-effects) can be rolled back in case of errors. --- view/recipes.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'view') diff --git a/view/recipes.go b/view/recipes.go index bd4c72b..fe995b2 100644 --- a/view/recipes.go +++ b/view/recipes.go @@ -9,7 +9,8 @@ import ( func RecipesRead(w http.ResponseWriter, r *http.Request) { recipes := make(model.Recipes, 0) - err := recipes.Read() + var obj model.Object = &recipes + err := model.Transaction(obj.Read) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return -- cgit v1.2.3-70-g09d2