From 4eccbad671d10399b1fe5e7779585ccf25c0b70a Mon Sep 17 00:00:00 2001 From: kolaente Date: Fri, 24 May 2019 22:14:13 +0200 Subject: [PATCH] Started fixing not getting infos across --- pkg/models/list_task_readall.go | 34 ++++++- pkg/models/list_task_readall_test.go | 146 +++++++++++++++++++++++++++ pkg/models/list_tasks.go | 15 +++ 3 files changed, 192 insertions(+), 3 deletions(-) diff --git a/pkg/models/list_task_readall.go b/pkg/models/list_task_readall.go index 290e924b6..0c5a1a823 100644 --- a/pkg/models/list_task_readall.go +++ b/pkg/models/list_task_readall.go @@ -8,6 +8,7 @@ package models import ( "code.vikunja.io/web" + "sort" "time" ) @@ -66,7 +67,7 @@ func (t *ListTask) ReadAll(search string, a web.Auth, page int) (interface{}, er } //GetTasksByUser returns all tasks for a user -func GetTasksByUser(search string, u *User, page int, sortby SortBy, startDate time.Time, endDate time.Time) (tasks []*ListTask, err error) { +func GetTasksByUser(search string, u *User, page int, sortby SortBy, startDate time.Time, endDate time.Time) ([]*ListTask, error) { // Get all lists lists, err := getRawListsForUser("", u, page) if err != nil { @@ -91,6 +92,8 @@ func GetTasksByUser(search string, u *User, page int, sortby SortBy, startDate t orderby = "due_date_unix asc" } + taskMap := make(map[int64]*ListTask) + // Then return all tasks for that lists if startDate.Unix() != 0 || endDate.Unix() != 0 { @@ -111,7 +114,7 @@ func GetTasksByUser(search string, u *User, page int, sortby SortBy, startDate t "(end_date_unix BETWEEN ? and ?))", startDateUnix, endDateUnix, startDateUnix, endDateUnix, startDateUnix, endDateUnix). And("(parent_task_id = 0 OR parent_task_id IS NULL)"). OrderBy(orderby). - Find(&tasks); err != nil { + Find(&taskMap); err != nil { return nil, err } } else { @@ -119,10 +122,35 @@ func GetTasksByUser(search string, u *User, page int, sortby SortBy, startDate t Where("text LIKE ?", "%"+search+"%"). And("(parent_task_id = 0 OR parent_task_id IS NULL)"). OrderBy(orderby). - Find(&tasks); err != nil { + Find(&taskMap); err != nil { return nil, err } } + tasks, err := addMoreInfoToTasks(taskMap) + if err != nil { + return nil, err + } + // Because the list is sorted by id which we don't want (since we're dealing with maps) + // we have to manually sort the tasks again here. + switch sortby { + case SortTasksByPriorityDesc: + sort.Slice(tasks, func(i, j int) bool { + return tasks[i].Priority > tasks[j].Priority + }) + case SortTasksByPriorityAsc: + sort.Slice(tasks, func(i, j int) bool { + return tasks[i].Priority < tasks[j].Priority + }) + case SortTasksByDueDateDesc: + sort.Slice(tasks, func(i, j int) bool { + return tasks[i].DueDateUnix > tasks[j].DueDateUnix + }) + case SortTasksByDueDateAsc: + sort.Slice(tasks, func(i, j int) bool { + return tasks[i].DueDateUnix < tasks[j].DueDateUnix + }) + } + return tasks, err } diff --git a/pkg/models/list_task_readall_test.go b/pkg/models/list_task_readall_test.go index 5f6e1f102..3a4efbe4a 100644 --- a/pkg/models/list_task_readall_test.go +++ b/pkg/models/list_task_readall_test.go @@ -16,12 +16,26 @@ import ( ) func sortTasksForTesting(by SortBy) (tasks []*ListTask) { + user1 := User{ + ID: 1, + Username: "user1", + Password: "$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.", + IsActive: true, + } + user6 := User{ + ID: 6, + Username: "user6", + Password: "$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.", + IsActive: true, + } + tasks = []*ListTask{ { ID: 1, Text: "task #1", Description: "Lorem Ipsum", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -31,6 +45,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { Text: "task #2 done", Done: true, CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -39,6 +54,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 3, Text: "task #3 high prio", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -48,6 +64,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 4, Text: "task #4 low prio", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -57,6 +74,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 5, Text: "task #5 higher due date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -66,6 +84,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 6, Text: "task #6 lower due date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -75,6 +94,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 7, Text: "task #7 with start date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -84,6 +104,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 8, Text: "task #8 with end date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -93,6 +114,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 9, Text: "task #9 with start and end date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -103,6 +125,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 10, Text: "task #10 basic", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -111,6 +134,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 11, Text: "task #11 basic", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -119,6 +143,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 12, Text: "task #12 basic", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -127,6 +152,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 15, Text: "task #15", CreatedByID: 6, + CreatedBy: user6, ListID: 6, Created: 1543626724, Updated: 1543626724, @@ -135,6 +161,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 16, Text: "task #16", CreatedByID: 6, + CreatedBy: user6, ListID: 7, Created: 1543626724, Updated: 1543626724, @@ -143,6 +170,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 17, Text: "task #17", CreatedByID: 6, + CreatedBy: user6, ListID: 8, Created: 1543626724, Updated: 1543626724, @@ -151,6 +179,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 18, Text: "task #18", CreatedByID: 6, + CreatedBy: user6, ListID: 9, Created: 1543626724, Updated: 1543626724, @@ -159,6 +188,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 19, Text: "task #19", CreatedByID: 6, + CreatedBy: user6, ListID: 10, Created: 1543626724, Updated: 1543626724, @@ -167,6 +197,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 20, Text: "task #20", CreatedByID: 6, + CreatedBy: user6, ListID: 11, Created: 1543626724, Updated: 1543626724, @@ -175,6 +206,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 21, Text: "task #21", CreatedByID: 6, + CreatedBy: user6, ListID: 12, Created: 1543626724, Updated: 1543626724, @@ -183,6 +215,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 22, Text: "task #22", CreatedByID: 6, + CreatedBy: user6, ListID: 13, Created: 1543626724, Updated: 1543626724, @@ -191,6 +224,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 23, Text: "task #23", CreatedByID: 6, + CreatedBy: user6, ListID: 14, Created: 1543626724, Updated: 1543626724, @@ -199,6 +233,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 24, Text: "task #24", CreatedByID: 6, + CreatedBy: user6, ListID: 15, Created: 1543626724, Updated: 1543626724, @@ -207,6 +242,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 25, Text: "task #25", CreatedByID: 6, + CreatedBy: user6, ListID: 16, Created: 1543626724, Updated: 1543626724, @@ -215,6 +251,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 26, Text: "task #26", CreatedByID: 6, + CreatedBy: user6, ListID: 17, Created: 1543626724, Updated: 1543626724, @@ -223,6 +260,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 27, Text: "task #27 with reminders", CreatedByID: 1, + CreatedBy: user1, RemindersUnix: []int64{1543626724, 1543626824}, ListID: 1, Created: 1543626724, @@ -232,6 +270,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 28, Text: "task #28 with repeat after", CreatedByID: 1, + CreatedBy: user1, ListID: 1, RepeatAfter: 3600, Created: 1543626724, @@ -241,6 +280,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { ID: 30, Text: "task #30 with assignees", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -250,6 +290,7 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { Text: "task #31 with color", HexColor: "f0f0f0", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -284,6 +325,21 @@ func sortTasksForTesting(by SortBy) (tasks []*ListTask) { func TestListTask_ReadAll(t *testing.T) { assert.NoError(t, LoadFixtures()) + + // Dummy users + user1 := User{ + ID: 1, + Username: "user1", + Password: "$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.", + IsActive: true, + } + user6 := User{ + ID: 6, + Username: "user6", + Password: "$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.", + IsActive: true, + } + type fields struct { ID int64 Text string @@ -358,6 +414,7 @@ func TestListTask_ReadAll(t *testing.T) { Text: "task #1", Description: "Lorem Ipsum", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -367,6 +424,7 @@ func TestListTask_ReadAll(t *testing.T) { Text: "task #2 done", Done: true, CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -375,6 +433,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 5, Text: "task #5 higher due date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -384,6 +443,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 6, Text: "task #6 lower due date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -393,6 +453,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 7, Text: "task #7 with start date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -402,6 +463,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 8, Text: "task #8 with end date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -411,6 +473,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 9, Text: "task #9 with start and end date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -421,6 +484,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 10, Text: "task #10 basic", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -429,6 +493,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 11, Text: "task #11 basic", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -437,6 +502,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 12, Text: "task #12 basic", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -444,6 +510,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 15, Text: "task #15", CreatedByID: 6, + CreatedBy: user6, ListID: 6, Created: 1543626724, Updated: 1543626724, @@ -452,6 +519,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 16, Text: "task #16", CreatedByID: 6, + CreatedBy: user6, ListID: 7, Created: 1543626724, Updated: 1543626724, @@ -460,6 +528,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 17, Text: "task #17", CreatedByID: 6, + CreatedBy: user6, ListID: 8, Created: 1543626724, Updated: 1543626724, @@ -468,6 +537,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 18, Text: "task #18", CreatedByID: 6, + CreatedBy: user6, ListID: 9, Created: 1543626724, Updated: 1543626724, @@ -476,6 +546,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 19, Text: "task #19", CreatedByID: 6, + CreatedBy: user6, ListID: 10, Created: 1543626724, Updated: 1543626724, @@ -484,6 +555,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 20, Text: "task #20", CreatedByID: 6, + CreatedBy: user6, ListID: 11, Created: 1543626724, Updated: 1543626724, @@ -492,6 +564,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 21, Text: "task #21", CreatedByID: 6, + CreatedBy: user6, ListID: 12, Created: 1543626724, Updated: 1543626724, @@ -500,6 +573,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 22, Text: "task #22", CreatedByID: 6, + CreatedBy: user6, ListID: 13, Created: 1543626724, Updated: 1543626724, @@ -508,6 +582,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 23, Text: "task #23", CreatedByID: 6, + CreatedBy: user6, ListID: 14, Created: 1543626724, Updated: 1543626724, @@ -516,6 +591,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 24, Text: "task #24", CreatedByID: 6, + CreatedBy: user6, ListID: 15, Created: 1543626724, Updated: 1543626724, @@ -524,6 +600,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 25, Text: "task #25", CreatedByID: 6, + CreatedBy: user6, ListID: 16, Created: 1543626724, Updated: 1543626724, @@ -532,6 +609,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 26, Text: "task #26", CreatedByID: 6, + CreatedBy: user6, ListID: 17, Created: 1543626724, Updated: 1543626724, @@ -540,6 +618,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 27, Text: "task #27 with reminders", CreatedByID: 1, + CreatedBy: user1, RemindersUnix: []int64{1543626724, 1543626824}, ListID: 1, Created: 1543626724, @@ -549,6 +628,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 28, Text: "task #28 with repeat after", CreatedByID: 1, + CreatedBy: user1, ListID: 1, RepeatAfter: 3600, Created: 1543626724, @@ -558,6 +638,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 30, Text: "task #30 with assignees", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -567,6 +648,7 @@ func TestListTask_ReadAll(t *testing.T) { Text: "task #31 with color", HexColor: "f0f0f0", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -575,6 +657,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 4, Text: "task #4 low prio", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -584,6 +667,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 3, Text: "task #3 high prio", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -620,6 +704,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 5, Text: "task #5 higher due date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -629,6 +714,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 6, Text: "task #6 lower due date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -639,6 +725,7 @@ func TestListTask_ReadAll(t *testing.T) { Text: "task #1", Description: "Lorem Ipsum", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -648,6 +735,7 @@ func TestListTask_ReadAll(t *testing.T) { Text: "task #2 done", Done: true, CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -656,6 +744,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 3, Text: "task #3 high prio", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -665,6 +754,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 4, Text: "task #4 low prio", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -674,6 +764,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 7, Text: "task #7 with start date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -683,6 +774,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 8, Text: "task #8 with end date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -692,6 +784,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 9, Text: "task #9 with start and end date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -702,6 +795,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 10, Text: "task #10 basic", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -710,6 +804,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 11, Text: "task #11 basic", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -718,6 +813,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 12, Text: "task #12 basic", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -726,6 +822,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 15, Text: "task #15", CreatedByID: 6, + CreatedBy: user6, ListID: 6, Created: 1543626724, Updated: 1543626724, @@ -734,6 +831,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 16, Text: "task #16", CreatedByID: 6, + CreatedBy: user6, ListID: 7, Created: 1543626724, Updated: 1543626724, @@ -742,6 +840,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 17, Text: "task #17", CreatedByID: 6, + CreatedBy: user6, ListID: 8, Created: 1543626724, Updated: 1543626724, @@ -750,6 +849,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 18, Text: "task #18", CreatedByID: 6, + CreatedBy: user6, ListID: 9, Created: 1543626724, Updated: 1543626724, @@ -758,6 +858,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 19, Text: "task #19", CreatedByID: 6, + CreatedBy: user6, ListID: 10, Created: 1543626724, Updated: 1543626724, @@ -766,6 +867,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 20, Text: "task #20", CreatedByID: 6, + CreatedBy: user6, ListID: 11, Created: 1543626724, Updated: 1543626724, @@ -774,6 +876,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 21, Text: "task #21", CreatedByID: 6, + CreatedBy: user6, ListID: 12, Created: 1543626724, Updated: 1543626724, @@ -782,6 +885,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 22, Text: "task #22", CreatedByID: 6, + CreatedBy: user6, ListID: 13, Created: 1543626724, Updated: 1543626724, @@ -790,6 +894,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 23, Text: "task #23", CreatedByID: 6, + CreatedBy: user6, ListID: 14, Created: 1543626724, Updated: 1543626724, @@ -798,6 +903,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 24, Text: "task #24", CreatedByID: 6, + CreatedBy: user6, ListID: 15, Created: 1543626724, Updated: 1543626724, @@ -806,6 +912,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 25, Text: "task #25", CreatedByID: 6, + CreatedBy: user6, ListID: 16, Created: 1543626724, Updated: 1543626724, @@ -814,6 +921,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 26, Text: "task #26", CreatedByID: 6, + CreatedBy: user6, ListID: 17, Created: 1543626724, Updated: 1543626724, @@ -822,6 +930,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 27, Text: "task #27 with reminders", CreatedByID: 1, + CreatedBy: user1, RemindersUnix: []int64{1543626724, 1543626824}, ListID: 1, Created: 1543626724, @@ -831,6 +940,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 28, Text: "task #28 with repeat after", CreatedByID: 1, + CreatedBy: user1, ListID: 1, RepeatAfter: 3600, Created: 1543626724, @@ -840,6 +950,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 30, Text: "task #30 with assignees", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -849,6 +960,7 @@ func TestListTask_ReadAll(t *testing.T) { Text: "task #31 with color", HexColor: "f0f0f0", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -872,6 +984,7 @@ func TestListTask_ReadAll(t *testing.T) { Text: "task #1", Description: "Lorem Ipsum", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -881,6 +994,7 @@ func TestListTask_ReadAll(t *testing.T) { Text: "task #2 done", Done: true, CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -889,6 +1003,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 3, Text: "task #3 high prio", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -898,6 +1013,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 4, Text: "task #4 low prio", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -907,6 +1023,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 7, Text: "task #7 with start date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -916,6 +1033,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 8, Text: "task #8 with end date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -925,6 +1043,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 9, Text: "task #9 with start and end date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -935,6 +1054,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 10, Text: "task #10 basic", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -943,6 +1063,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 11, Text: "task #11 basic", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -951,6 +1072,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 12, Text: "task #12 basic", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -959,6 +1081,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 15, Text: "task #15", CreatedByID: 6, + CreatedBy: user6, ListID: 6, Created: 1543626724, Updated: 1543626724, @@ -967,6 +1090,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 16, Text: "task #16", CreatedByID: 6, + CreatedBy: user6, ListID: 7, Created: 1543626724, Updated: 1543626724, @@ -975,6 +1099,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 17, Text: "task #17", CreatedByID: 6, + CreatedBy: user6, ListID: 8, Created: 1543626724, Updated: 1543626724, @@ -983,6 +1108,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 18, Text: "task #18", CreatedByID: 6, + CreatedBy: user6, ListID: 9, Created: 1543626724, Updated: 1543626724, @@ -991,6 +1117,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 19, Text: "task #19", CreatedByID: 6, + CreatedBy: user6, ListID: 10, Created: 1543626724, Updated: 1543626724, @@ -999,6 +1126,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 20, Text: "task #20", CreatedByID: 6, + CreatedBy: user6, ListID: 11, Created: 1543626724, Updated: 1543626724, @@ -1007,6 +1135,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 21, Text: "task #21", CreatedByID: 6, + CreatedBy: user6, ListID: 12, Created: 1543626724, Updated: 1543626724, @@ -1015,6 +1144,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 22, Text: "task #22", CreatedByID: 6, + CreatedBy: user6, ListID: 13, Created: 1543626724, Updated: 1543626724, @@ -1023,6 +1153,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 23, Text: "task #23", CreatedByID: 6, + CreatedBy: user6, ListID: 14, Created: 1543626724, Updated: 1543626724, @@ -1031,6 +1162,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 24, Text: "task #24", CreatedByID: 6, + CreatedBy: user6, ListID: 15, Created: 1543626724, Updated: 1543626724, @@ -1039,6 +1171,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 25, Text: "task #25", CreatedByID: 6, + CreatedBy: user6, ListID: 16, Created: 1543626724, Updated: 1543626724, @@ -1047,6 +1180,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 26, Text: "task #26", CreatedByID: 6, + CreatedBy: user6, ListID: 17, Created: 1543626724, Updated: 1543626724, @@ -1055,6 +1189,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 27, Text: "task #27 with reminders", CreatedByID: 1, + CreatedBy: user1, RemindersUnix: []int64{1543626724, 1543626824}, ListID: 1, Created: 1543626724, @@ -1064,6 +1199,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 28, Text: "task #28 with repeat after", CreatedByID: 1, + CreatedBy: user1, ListID: 1, RepeatAfter: 3600, Created: 1543626724, @@ -1073,6 +1209,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 30, Text: "task #30 with assignees", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -1082,6 +1219,7 @@ func TestListTask_ReadAll(t *testing.T) { Text: "task #31 with color", HexColor: "f0f0f0", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -1090,6 +1228,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 6, Text: "task #6 lower due date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -1099,6 +1238,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 5, Text: "task #5 higher due date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -1137,6 +1277,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 7, Text: "task #7 with start date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -1146,6 +1287,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 9, Text: "task #9 with start and end date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -1171,6 +1313,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 8, Text: "task #8 with end date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -1180,6 +1323,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 9, Text: "task #9 with start and end date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -1204,6 +1348,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 8, Text: "task #8 with end date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, @@ -1213,6 +1358,7 @@ func TestListTask_ReadAll(t *testing.T) { ID: 9, Text: "task #9 with start and end date", CreatedByID: 1, + CreatedBy: user1, ListID: 1, Created: 1543626724, Updated: 1543626724, diff --git a/pkg/models/list_tasks.go b/pkg/models/list_tasks.go index 5f83cbe08..85bc6c1d5 100644 --- a/pkg/models/list_tasks.go +++ b/pkg/models/list_tasks.go @@ -249,12 +249,27 @@ func addMoreInfoToTasks(taskMap map[int64]*ListTask) (tasks []*ListTask, err err return } + // Get all reminders and put them in a map to have it easier later + reminders := []*TaskReminder{} + err = x.Table("task_reminders").In("task_id", taskIDs).Find(&reminders) + if err != nil { + return + } + + taskRemindersUnix := make(map[int64][]int64) + for _, r := range reminders { + taskRemindersUnix[r.TaskID] = append(taskRemindersUnix[r.TaskID], r.ReminderUnix) + } + // Add all user objects to the appropriate tasks for _, task := range taskMap { // Make created by user objects taskMap[task.ID].CreatedBy = *users[task.CreatedByID] + // Add the reminders + taskMap[task.ID].RemindersUnix = taskRemindersUnix[task.ID] + // Reorder all subtasks if task.ParentTaskID != 0 { taskMap[task.ParentTaskID].Subtasks = append(taskMap[task.ParentTaskID].Subtasks, task)