56 lines
939 B
Go
Executable File
56 lines
939 B
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"`
|
|
}
|
|
|
|
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 set(b bool, i *int) {
|
|
*i = 1
|
|
if !b {
|
|
*i = 0
|
|
}
|
|
}
|