diff --git a/assets/templates/items/form.tmpl b/assets/templates/items/form.tmpl index 7593c65..96294ba 100644 --- a/assets/templates/items/form.tmpl +++ b/assets/templates/items/form.tmpl @@ -17,7 +17,7 @@
-
+

@@ -26,7 +26,7 @@ {{ widget_select "Type_id" "Type" .item.Type_id .types `style="width: 100%"` }}

-
+

{{ widget_checkboxes "Notebooks" "Notebooks" .item.Notebooks .notebooks `` }}

diff --git a/models/itemshare.go b/models/itemshare.go index 123925d..ec67eb1 100644 --- a/models/itemshare.go +++ b/models/itemshare.go @@ -1,6 +1,10 @@ package models -import "brainminder.speedtech.it/internal/database" +import ( + "brainminder.speedtech.it/internal/database" + "database/sql" + "errors" +) type ItemShareModel struct { DB *database.DB @@ -9,20 +13,18 @@ type ItemShareModel struct { type ItemShare struct { Id int64 `db:"id"` Token string `db:"token"` - Summary string `db:"summary"` Item_id int64 `db:"item_id"` - Read int `db:"crypted"` Update int `db:"hidden"` Start_datetime string `db:"start_datetime"` End_datetime string `db:"end_datetime"` - password string `db:"password"` + Password string `db:"password"` } func (model *ItemShareModel) Create(ItemShare *ItemShare) (int64, error) { ctx, cancel := database.GetContext() defer cancel() - query := `INSERT INTO bm_items_share (title, description, icon, hidden) VALUES (:title, :description, :icon, :hidden)` + query := `INSERT INTO bm_items_share (token, item_id, update, start_datetime, end_datetime, password) VALUES (:token, :item_id, :update, :start_datetime, :end_datetime, :password)` result, err := model.DB.NamedExecContext(ctx, query, ItemShare) if err != nil { @@ -36,3 +38,15 @@ func (model *ItemShareModel) Create(ItemShare *ItemShare) (int64, error) { return id, err } + +func (model *ItemShareModel) Delete(id int) (bool, error) { + ctx, cancel := database.GetContext() + defer cancel() + + _, err := model.DB.ExecContext(ctx, `DELETE FROM bm_item_share WHERE id = $1`, id) + if errors.Is(err, sql.ErrNoRows) { + return false, nil + } + + return true, err +}