From 7bac9f490ef6936228ef2307bbfe71dafedd6de3 Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 10 Jun 2018 15:55:56 +0200 Subject: [PATCH] Started adding listitems --- Featurecreep.md | 1 + models/list_items.go | 27 +++++++++++++++++++++++++++ models/lists.go | 8 ++++++++ models/models.go | 1 + 4 files changed, 37 insertions(+) create mode 100644 models/list_items.go diff --git a/Featurecreep.md b/Featurecreep.md index af2ac8d336a..3189791ee13 100644 --- a/Featurecreep.md +++ b/Featurecreep.md @@ -10,6 +10,7 @@ * ID * Text * Description +* Status (done, not done) * Fälligkeitsdatum * Erinnerungsdatum (und zeit) * Zuständig (später, mit teilen) diff --git a/models/list_items.go b/models/list_items.go new file mode 100644 index 00000000000..3a9052b4159 --- /dev/null +++ b/models/list_items.go @@ -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 +} diff --git a/models/lists.go b/models/lists.go index de09b99ba78..2bca618fd6a 100644 --- a/models/lists.go +++ b/models/lists.go @@ -9,6 +9,8 @@ type List struct { Owner User `xorm:"-" json:"owner"` Created int64 `xorm:"created" json:"created"` Updated int64 `xorm:"updated" json:"updated"` + + Items []*ListItem `xorm:"-"` } // GetListByID returns a list by its ID @@ -31,6 +33,12 @@ func GetListByID(id int64) (list List, err error) { list.Owner = user + items, err := GetItemsByListID(list.ID) + if err != nil { + return + } + list.Items = items + return list, nil } diff --git a/models/models.go b/models/models.go index 2ecedfc104e..14130a44314 100644 --- a/models/models.go +++ b/models/models.go @@ -34,6 +34,7 @@ func init() { tables = append(tables, new(User), new(List), + new(ListItem), ) }