Started adding listitems

This commit is contained in:
konrad 2018-06-10 15:55:56 +02:00 committed by kolaente
parent abd21f0c14
commit 7bac9f490e
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
4 changed files with 37 additions and 0 deletions

View file

@ -10,6 +10,7 @@
* ID * ID
* Text * Text
* Description * Description
* Status (done, not done)
* Fälligkeitsdatum * Fälligkeitsdatum
* Erinnerungsdatum (und zeit) * Erinnerungsdatum (und zeit)
* Zuständig (später, mit teilen) * Zuständig (später, mit teilen)

27
models/list_items.go Normal file
View file

@ -0,0 +1,27 @@
package models
// ListItem represents an item in a todolist
type ListItem struct {
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"`
Text string `xorm:"varchar(250)" json:"text"`
Description string `xorm:"varchar(250)" json:"description"`
Done bool `json:"done"`
DueDateUnix int64 `xorm:"int(11)" json:"dueDate"`
ReminderUnix int64 `xorm:"int(11)" json:"reminderDate"`
CreatedByID int64 `xorm:"int(11)" json:"createdByID"` // ID of the user who put that item on the list
ListID int64 `xorm:"int(11)" json:"listID"`
Created int64 `xorm:"created" json:"created"`
Updated int64 `xorm:"updated" json:"updated"`
CreatedBy User `xorm:"-"`
}
// TableName returns the table name for listitems
func (ListItem) TableName() string {
return "items"
}
func GetItemsByListID(listID int64) (items []*ListItem, err error) {
err = x.Where("list_id = ?", listID).Find(&items)
return
}

View file

@ -9,6 +9,8 @@ type List struct {
Owner User `xorm:"-" json:"owner"` Owner User `xorm:"-" json:"owner"`
Created int64 `xorm:"created" json:"created"` Created int64 `xorm:"created" json:"created"`
Updated int64 `xorm:"updated" json:"updated"` Updated int64 `xorm:"updated" json:"updated"`
Items []*ListItem `xorm:"-"`
} }
// GetListByID returns a list by its ID // GetListByID returns a list by its ID
@ -31,6 +33,12 @@ func GetListByID(id int64) (list List, err error) {
list.Owner = user list.Owner = user
items, err := GetItemsByListID(list.ID)
if err != nil {
return
}
list.Items = items
return list, nil return list, nil
} }

View file

@ -34,6 +34,7 @@ func init() {
tables = append(tables, tables = append(tables,
new(User), new(User),
new(List), new(List),
new(ListItem),
) )
} }