Item sharing progress

This commit is contained in:
roberto 2025-01-06 12:03:37 +01:00
parent f2100d5643
commit b4d3d1cb7e
2 changed files with 21 additions and 7 deletions

View File

@ -17,7 +17,7 @@
<div id="general" class="tab" style="display: block">
<div class="row">
<div class="col m6 s12">
<div class="col s12 m6 l6">
<p>
<label for="item-title">Title</label>
<input name="Title" id="item-title" type="text" value="{{.item.Title}}" />
@ -26,7 +26,7 @@
{{ widget_select "Type_id" "Type" .item.Type_id .types `style="width: 100%"` }}
</p>
</div>
<div class="col m6 s12">
<div class="col s12 m6 l6">
<p>
{{ widget_checkboxes "Notebooks" "Notebooks" .item.Notebooks .notebooks `` }}
</p>

View File

@ -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
}