Item sharing progress
This commit is contained in:
parent
f2100d5643
commit
b4d3d1cb7e
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
<div id="general" class="tab" style="display: block">
|
<div id="general" class="tab" style="display: block">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col m6 s12">
|
<div class="col s12 m6 l6">
|
||||||
<p>
|
<p>
|
||||||
<label for="item-title">Title</label>
|
<label for="item-title">Title</label>
|
||||||
<input name="Title" id="item-title" type="text" value="{{.item.Title}}" />
|
<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%"` }}
|
{{ widget_select "Type_id" "Type" .item.Type_id .types `style="width: 100%"` }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col m6 s12">
|
<div class="col s12 m6 l6">
|
||||||
<p>
|
<p>
|
||||||
{{ widget_checkboxes "Notebooks" "Notebooks" .item.Notebooks .notebooks `` }}
|
{{ widget_checkboxes "Notebooks" "Notebooks" .item.Notebooks .notebooks `` }}
|
||||||
</p>
|
</p>
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import "brainminder.speedtech.it/internal/database"
|
import (
|
||||||
|
"brainminder.speedtech.it/internal/database"
|
||||||
|
"database/sql"
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
type ItemShareModel struct {
|
type ItemShareModel struct {
|
||||||
DB *database.DB
|
DB *database.DB
|
||||||
@ -9,20 +13,18 @@ type ItemShareModel struct {
|
|||||||
type ItemShare struct {
|
type ItemShare struct {
|
||||||
Id int64 `db:"id"`
|
Id int64 `db:"id"`
|
||||||
Token string `db:"token"`
|
Token string `db:"token"`
|
||||||
Summary string `db:"summary"`
|
|
||||||
Item_id int64 `db:"item_id"`
|
Item_id int64 `db:"item_id"`
|
||||||
Read int `db:"crypted"`
|
|
||||||
Update int `db:"hidden"`
|
Update int `db:"hidden"`
|
||||||
Start_datetime string `db:"start_datetime"`
|
Start_datetime string `db:"start_datetime"`
|
||||||
End_datetime string `db:"end_datetime"`
|
End_datetime string `db:"end_datetime"`
|
||||||
password string `db:"password"`
|
Password string `db:"password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (model *ItemShareModel) Create(ItemShare *ItemShare) (int64, error) {
|
func (model *ItemShareModel) Create(ItemShare *ItemShare) (int64, error) {
|
||||||
ctx, cancel := database.GetContext()
|
ctx, cancel := database.GetContext()
|
||||||
defer cancel()
|
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)
|
result, err := model.DB.NamedExecContext(ctx, query, ItemShare)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -36,3 +38,15 @@ func (model *ItemShareModel) Create(ItemShare *ItemShare) (int64, error) {
|
|||||||
|
|
||||||
return id, err
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user