todo-server/server/ajax/list/list.go

63 lines
1.0 KiB
Go
Executable File

package list
import (
"errors"
"local/todo-server/server/ajax/form"
"net/http"
)
type List struct {
Name string `json:"name"`
UUID string `json:"id"`
Sort int `json:"sort"`
Published int `json:"published"`
ShowCompl int `json:"showCompl"`
ShowNotes int `json:"showNotes"`
Hidden int `json:"hidden"`
Max int `json:"max"`
Index int `json:"index"`
}
func New(r *http.Request) (*List, error) {
name := form.Get(r, "name")
if name == "" {
return nil, errors.New("no name given")
}
return &List{
Name: name,
UUID: form.NewUUID(),
}, nil
}
func (l *List) SetName(name string) {
l.Name = name
}
func (l *List) SetPublished(state bool) {
set(state, &l.Published)
}
func (l *List) SetShowCompl(state bool) {
set(state, &l.ShowCompl)
}
func (l *List) SetShowNotes(state bool) {
set(state, &l.ShowNotes)
}
func (l *List) SetHideList(state bool) {
set(state, &l.Hidden)
}
func (l *List) NextIndex() int {
l.Max += 1
return l.Max
}
func set(b bool, i *int) {
*i = 1
if !b {
*i = 0
}
}