1
0

Task collection improvements (#109)

This commit is contained in:
konrad
2019-12-01 13:38:11 +00:00
parent d96831fe3a
commit 7e4deab8f7
81 changed files with 44585 additions and 38569 deletions

View File

@ -35,7 +35,8 @@ type List struct {
// The user who created this list.
Owner *User `xorm:"-" json:"owner" valid:"-"`
// An array of tasks which belong to the list.
Tasks []*Task `xorm:"-" json:"tasks"`
// Deprecated: you should use the dedicated task list endpoint because it has support for pagination and filtering
Tasks []*Task `xorm:"-" json:"-"`
// A unix timestamp when this list was created. You cannot change this value.
Created int64 `xorm:"created not null" json:"created"`
@ -122,12 +123,6 @@ func (l *List) ReadAll(a web.Auth, search string, page int, perPage int) (result
// @Failure 500 {object} models.Message "Internal error"
// @Router /lists/{id} [get]
func (l *List) ReadOne() (err error) {
// Get list tasks
l.Tasks, err = GetTasksByListID(l.ID)
if err != nil {
return err
}
// Get list owner
l.Owner, err = GetUserByID(l.OwnerID)
return
@ -233,20 +228,11 @@ func getRawListsForUser(search string, u *User, page int, perPage int) (lists []
// AddListDetails adds owner user objects and list tasks to all lists in the slice
func AddListDetails(lists []*List) (err error) {
var listIDs []int64
var ownerIDs []int64
for _, l := range lists {
listIDs = append(listIDs, l.ID)
ownerIDs = append(ownerIDs, l.OwnerID)
}
// Get all tasks
ts := []*Task{}
err = x.In("list_id", listIDs).Find(&ts)
if err != nil {
return
}
// Get all list owners
owners := []*User{}
err = x.In("id", ownerIDs).Find(&owners)
@ -263,13 +249,6 @@ func AddListDetails(lists []*List) (err error) {
break
}
}
// Tasks
for _, task := range ts {
if task.ListID == list.ID {
lists[in].Tasks = append(lists[in].Tasks, task)
}
}
}
return

View File

@ -471,22 +471,11 @@ func TestTask_ReadAll(t *testing.T) {
}
type fields struct {
ID int64
Text string
Description string
Done bool
DueDateUnix int64
RemindersUnix []int64
CreatedByID int64
ListID int64
RepeatAfter int64
Priority int64
Sorting string
StartDateSortUnix int64
EndDateSortUnix int64
Created int64
Updated int64
CreatedBy *User
Lists []*List
CRUDable web.CRUDable
Rights web.Rights
}
@ -708,23 +697,11 @@ func TestTask_ReadAll(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
lt := &Task{
ID: tt.fields.ID,
Text: tt.fields.Text,
Description: tt.fields.Description,
Done: tt.fields.Done,
DueDateUnix: tt.fields.DueDateUnix,
RemindersUnix: tt.fields.RemindersUnix,
CreatedByID: tt.fields.CreatedByID,
lt := &TaskCollection{
ListID: tt.fields.ListID,
RepeatAfter: tt.fields.RepeatAfter,
Priority: tt.fields.Priority,
Sorting: tt.fields.Sorting,
StartDateSortUnix: tt.fields.StartDateSortUnix,
EndDateSortUnix: tt.fields.EndDateSortUnix,
Created: tt.fields.Created,
Updated: tt.fields.Updated,
CreatedBy: tt.fields.CreatedBy,
CRUDable: tt.fields.CRUDable,
Rights: tt.fields.Rights,
}

View File

@ -117,7 +117,16 @@ const (
SortTasksByPriorityDesc
)
// ReadAll gets all tasks for a user
type taskOptions struct {
search string
sortby SortBy
startDate time.Time
endDate time.Time
page int
perPage int
}
// ReadAll is a dummy function to still have that endpoint documented
// @Summary Get tasks
// @Description Returns all tasks on any list the user has access to.
// @tags task
@ -134,21 +143,7 @@ const (
// @Failure 500 {object} models.Message "Internal error"
// @Router /tasks/all [get]
func (t *Task) ReadAll(a web.Auth, search string, page int, perPage int) (result interface{}, resultCount int, totalItems int64, err error) {
tc := &TaskCollection{
Sorting: t.Sorting,
StartDateSortUnix: t.StartDateSortUnix,
EndDateSortUnix: t.EndDateSortUnix,
}
return tc.ReadAll(a, search, page, perPage)
}
type taskOptions struct {
search string
sortby SortBy
startDate time.Time
endDate time.Time
page int
perPage int
return nil, 0, 0, nil
}
func getRawTasksForLists(lists []*List, opts *taskOptions) (taskMap map[int64]*Task, resultCount int, totalItems int64, err error) {