From 3dedc040db8c42eae4112d3aaf64cd1a3f53ef81 Mon Sep 17 00:00:00 2001 From: ce72 Date: Mon, 6 Mar 2023 07:40:13 +0100 Subject: [PATCH] #1416: Step 1 Rename Reminders to ReminderDates --- pkg/integrations/task_test.go | 6 +-- pkg/models/task_collection_test.go | 8 +-- pkg/models/tasks.go | 52 +++++++++---------- pkg/models/tasks_test.go | 30 +++++------ .../microsoft-todo/microsoft_todo.go | 2 +- .../microsoft-todo/microsoft_todo_test.go | 2 +- pkg/modules/migration/ticktick/ticktick.go | 2 +- .../migration/ticktick/ticktick_test.go | 4 +- pkg/modules/migration/todoist/todoist.go | 2 +- pkg/modules/migration/todoist/todoist_test.go | 10 ++-- 10 files changed, 59 insertions(+), 59 deletions(-) diff --git a/pkg/integrations/task_test.go b/pkg/integrations/task_test.go index 1a09f92c90f..c8c4f29e53a 100644 --- a/pkg/integrations/task_test.go +++ b/pkg/integrations/task_test.go @@ -95,19 +95,19 @@ func TestTask(t *testing.T) { assert.Contains(t, rec.Body.String(), `"due_date":"0001-01-01T00:00:00Z"`) assert.NotContains(t, rec.Body.String(), `"due_date":"2020-02-10T10:00:00Z"`) }) - t.Run("Reminders", func(t *testing.T) { + t.Run("ReminderDates", func(t *testing.T) { rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"listtask": "1"}, `{"reminder_dates": ["2020-02-10T10:00:00Z","2020-02-11T10:00:00Z"]}`) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `"reminder_dates":["2020-02-10T10:00:00Z","2020-02-11T10:00:00Z"]`) assert.NotContains(t, rec.Body.String(), `"reminder_dates": null`) }) - t.Run("Reminders unset to empty array", func(t *testing.T) { + t.Run("ReminderDates unset to empty array", func(t *testing.T) { rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"listtask": "27"}, `{"reminder_dates": []}`) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `"reminder_dates":null`) assert.NotContains(t, rec.Body.String(), `"reminder_dates":[1543626724,1543626824]`) }) - t.Run("Reminders unset to null", func(t *testing.T) { + t.Run("ReminderDates unset to null", func(t *testing.T) { rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"listtask": "27"}, `{"reminder_dates": null}`) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `"reminder_dates":null`) diff --git a/pkg/models/task_collection_test.go b/pkg/models/task_collection_test.go index 7429ab5af8d..2e7e0c46149 100644 --- a/pkg/models/task_collection_test.go +++ b/pkg/models/task_collection_test.go @@ -169,7 +169,7 @@ func TestTaskCollection_ReadAll(t *testing.T) { label4, }, RelatedTasks: map[RelationKind][]*Task{}, - Reminders: []time.Time{ + ReminderDates: []time.Time{ time.Unix(1543626824, 0).In(loc), }, Created: time.Unix(1543626724, 0).In(loc), @@ -477,7 +477,7 @@ func TestTaskCollection_ReadAll(t *testing.T) { Index: 12, CreatedByID: 1, CreatedBy: user1, - Reminders: []time.Time{ + ReminderDates: []time.Time{ time.Unix(1543626724, 0).In(loc), time.Unix(1543626824, 0).In(loc), }, @@ -906,9 +906,9 @@ func TestTaskCollection_ReadAll(t *testing.T) { wantErr: false, }, { - name: "filtered reminders", + name: "filtered reminder dates", fields: fields{ - FilterBy: []string{"reminders", "reminders"}, + FilterBy: []string{"ReminderDates", "ReminderDates"}, FilterValue: []string{"2018-10-01T00:00:00+00:00", "2018-12-10T00:00:00+00:00"}, FilterComparator: []string{"greater", "less"}, }, diff --git a/pkg/models/tasks.go b/pkg/models/tasks.go index 0c79961cb3f..4af5429c3fb 100644 --- a/pkg/models/tasks.go +++ b/pkg/models/tasks.go @@ -62,7 +62,7 @@ type Task struct { // The time when the task is due. DueDate time.Time `xorm:"DATETIME INDEX null 'due_date'" json:"due_date"` // An array of datetimes when the user wants to be reminded of the task. - Reminders []time.Time `xorm:"-" json:"reminder_dates"` + ReminderDates []time.Time `xorm:"-" json:"reminder_dates"` // The list this task belongs to. ListID int64 `xorm:"bigint INDEX not null" json:"list_id" param:"list"` // An amount in seconds this task repeats itself. If this is set, when marking the task as done, it will mark itself as "undone" and then increase all remindes and the due date by its amount. @@ -334,7 +334,7 @@ func getRawTasksForLists(s *xorm.Session, lists []*List, a web.Auth, opts *taskO var filters = make([]builder.Cond, 0, len(opts.filters)) // To still find tasks with nil values, we exclude 0s when comparing with >/< values. for _, f := range opts.filters { - if f.field == "reminders" { + if f.field == "ReminderDates" { f.field = "reminder" // This is the name in the db filter, err := getFilterCond(f, opts.filterIncludeNulls) if err != nil { @@ -773,7 +773,7 @@ func addMoreInfoToTasks(s *xorm.Session, taskMap map[int64]*Task, a web.Auth) (e task.CreatedBy = users[task.CreatedByID] // Add the reminders - task.Reminders = taskReminders[task.ID] + task.ReminderDates = taskReminders[task.ID] // Prepare the subtasks task.RelatedTasks = make(RelatedTaskMap) @@ -965,7 +965,7 @@ func createTask(s *xorm.Session, t *Task, a web.Auth, updateAssignees bool) (err } // Update the reminders - if err := t.updateReminders(s, t.Reminders); err != nil { + if err := t.updateReminders(s, t.ReminderDates); err != nil { return err } @@ -1023,9 +1023,9 @@ func (t *Task) Update(s *xorm.Session, a web.Auth) (err error) { return } - ot.Reminders = make([]time.Time, len(reminders)) + ot.ReminderDates = make([]time.Time, len(reminders)) for i, r := range reminders { - ot.Reminders[i] = r.Reminder + ot.ReminderDates[i] = r.Reminder } targetBucket, err := setTaskBucket(s, t, &ot, t.BucketID != 0 && t.BucketID != ot.BucketID) @@ -1049,7 +1049,7 @@ func (t *Task) Update(s *xorm.Session, a web.Auth) (err error) { } // Update the reminders - if err := ot.updateReminders(s, t.Reminders); err != nil { + if err := ot.updateReminders(s, t.ReminderDates); err != nil { return err } @@ -1326,14 +1326,14 @@ func setTaskDatesDefault(oldTask, newTask *Task) { } } - newTask.Reminders = oldTask.Reminders + newTask.ReminderDates = oldTask.ReminderDates // When repeating from the current date, all reminders should keep their difference to each other. // To make this easier, we sort them first because we can then rely on the fact the first is the smallest - if len(oldTask.Reminders) > 0 { - for in, r := range oldTask.Reminders { - newTask.Reminders[in] = r.Add(repeatDuration) - for !newTask.Reminders[in].After(now) { - newTask.Reminders[in] = newTask.Reminders[in].Add(repeatDuration) + if len(oldTask.ReminderDates) > 0 { + for in, r := range oldTask.ReminderDates { + newTask.ReminderDates[in] = r.Add(repeatDuration) + for !newTask.ReminderDates[in].After(now) { + newTask.ReminderDates[in] = newTask.ReminderDates[in].Add(repeatDuration) } } } @@ -1361,10 +1361,10 @@ func setTaskDatesMonthRepeat(oldTask, newTask *Task) { newTask.DueDate = addOneMonthToDate(oldTask.DueDate) } - newTask.Reminders = oldTask.Reminders - if len(oldTask.Reminders) > 0 { - for in, r := range oldTask.Reminders { - newTask.Reminders[in] = addOneMonthToDate(r) + newTask.ReminderDates = oldTask.ReminderDates + if len(oldTask.ReminderDates) > 0 { + for in, r := range oldTask.ReminderDates { + newTask.ReminderDates[in] = addOneMonthToDate(r) } } @@ -1400,17 +1400,17 @@ func setTaskDatesFromCurrentDateRepeat(oldTask, newTask *Task) { newTask.DueDate = now.Add(repeatDuration) } - newTask.Reminders = oldTask.Reminders + newTask.ReminderDates = oldTask.ReminderDates // When repeating from the current date, all reminders should keep their difference to each other. // To make this easier, we sort them first because we can then rely on the fact the first is the smallest - if len(oldTask.Reminders) > 0 { - sort.Slice(oldTask.Reminders, func(i, j int) bool { - return oldTask.Reminders[i].Unix() < oldTask.Reminders[j].Unix() + if len(oldTask.ReminderDates) > 0 { + sort.Slice(oldTask.ReminderDates, func(i, j int) bool { + return oldTask.ReminderDates[i].Unix() < oldTask.ReminderDates[j].Unix() }) - first := oldTask.Reminders[0] - for in, r := range oldTask.Reminders { + first := oldTask.ReminderDates[0] + for in, r := range oldTask.ReminderDates { diff := r.Sub(first) - newTask.Reminders[in] = now.Add(repeatDuration + diff) + newTask.ReminderDates[in] = now.Add(repeatDuration + diff) } } @@ -1505,9 +1505,9 @@ func (t *Task) updateReminders(s *xorm.Session, reminders []time.Time) (err erro } } - t.Reminders = reminders + t.ReminderDates = reminders if len(reminders) == 0 { - t.Reminders = nil + t.ReminderDates = nil } err = updateListLastUpdated(s, &List{ID: t.ListID}) diff --git a/pkg/models/tasks_test.go b/pkg/models/tasks_test.go index a6bbc71c494..fc028520c43 100644 --- a/pkg/models/tasks_test.go +++ b/pkg/models/tasks_test.go @@ -376,7 +376,7 @@ func TestTask_Update(t *testing.T) { task := &Task{ ID: 1, Title: "test", - Reminders: []time.Time{ + ReminderDates: []time.Time{ time.Unix(1674745156, 0), time.Unix(1674745156, 223), }, @@ -487,7 +487,7 @@ func TestUpdateDone(t *testing.T) { oldTask := &Task{ Done: false, RepeatAfter: 8600, - Reminders: []time.Time{ + ReminderDates: []time.Time{ time.Unix(1550000000, 0), time.Unix(1555000000, 0), }, @@ -506,9 +506,9 @@ func TestUpdateDone(t *testing.T) { expected2 = expected2.Add(time.Duration(oldTask.RepeatAfter) * time.Second) } - assert.Len(t, newTask.Reminders, 2) - assert.Equal(t, expected1, newTask.Reminders[0]) - assert.Equal(t, expected2, newTask.Reminders[1]) + assert.Len(t, newTask.ReminderDates, 2) + assert.Equal(t, expected1, newTask.ReminderDates[0]) + assert.Equal(t, expected2, newTask.ReminderDates[1]) assert.False(t, newTask.Done) }) t.Run("update start date", func(t *testing.T) { @@ -585,7 +585,7 @@ func TestUpdateDone(t *testing.T) { Done: false, RepeatAfter: 8600, RepeatMode: TaskRepeatModeFromCurrentDate, - Reminders: []time.Time{ + ReminderDates: []time.Time{ time.Unix(1550000000, 0), time.Unix(1555000000, 0), }, @@ -595,12 +595,12 @@ func TestUpdateDone(t *testing.T) { } updateDone(oldTask, newTask) - diff := oldTask.Reminders[1].Sub(oldTask.Reminders[0]) + diff := oldTask.ReminderDates[1].Sub(oldTask.ReminderDates[0]) - assert.Len(t, newTask.Reminders, 2) + assert.Len(t, newTask.ReminderDates, 2) // Only comparing unix timestamps because time.Time use nanoseconds which can't ever possibly have the same value - assert.Equal(t, time.Now().Add(time.Duration(oldTask.RepeatAfter)*time.Second).Unix(), newTask.Reminders[0].Unix()) - assert.Equal(t, time.Now().Add(diff+time.Duration(oldTask.RepeatAfter)*time.Second).Unix(), newTask.Reminders[1].Unix()) + assert.Equal(t, time.Now().Add(time.Duration(oldTask.RepeatAfter)*time.Second).Unix(), newTask.ReminderDates[0].Unix()) + assert.Equal(t, time.Now().Add(diff+time.Duration(oldTask.RepeatAfter)*time.Second).Unix(), newTask.ReminderDates[1].Unix()) assert.False(t, newTask.Done) }) t.Run("start date", func(t *testing.T) { @@ -678,7 +678,7 @@ func TestUpdateDone(t *testing.T) { oldTask := &Task{ Done: false, RepeatMode: TaskRepeatModeMonth, - Reminders: []time.Time{ + ReminderDates: []time.Time{ time.Unix(1550000000, 0), time.Unix(1555000000, 0), }, @@ -686,13 +686,13 @@ func TestUpdateDone(t *testing.T) { newTask := &Task{ Done: true, } - oldReminders := make([]time.Time, len(oldTask.Reminders)) - copy(oldReminders, oldTask.Reminders) + oldReminders := make([]time.Time, len(oldTask.ReminderDates)) + copy(oldReminders, oldTask.ReminderDates) updateDone(oldTask, newTask) - assert.Len(t, newTask.Reminders, len(oldReminders)) - for i, r := range newTask.Reminders { + assert.Len(t, newTask.ReminderDates, len(oldReminders)) + for i, r := range newTask.ReminderDates { assert.True(t, r.After(oldReminders[i])) assert.NotEqual(t, oldReminders[i].Month(), r.Month()) } diff --git a/pkg/modules/migration/microsoft-todo/microsoft_todo.go b/pkg/modules/migration/microsoft-todo/microsoft_todo.go index 0cf390f7f61..e2fd5a1d8d8 100644 --- a/pkg/modules/migration/microsoft-todo/microsoft_todo.go +++ b/pkg/modules/migration/microsoft-todo/microsoft_todo.go @@ -329,7 +329,7 @@ func convertMicrosoftTodoData(todoData []*list) (vikunjsStructure []*models.Name return nil, err } - task.Reminders = []time.Time{reminder} + task.ReminderDates = []time.Time{reminder} } // Due Date diff --git a/pkg/modules/migration/microsoft-todo/microsoft_todo_test.go b/pkg/modules/migration/microsoft-todo/microsoft_todo_test.go index a995115671e..7c3a663338f 100644 --- a/pkg/modules/migration/microsoft-todo/microsoft_todo_test.go +++ b/pkg/modules/migration/microsoft-todo/microsoft_todo_test.go @@ -141,7 +141,7 @@ func TestConverting(t *testing.T) { { Task: models.Task{ Title: "Task 5", - Reminders: []time.Time{ + ReminderDates: []time.Time{ testtimeTime, }, }, diff --git a/pkg/modules/migration/ticktick/ticktick.go b/pkg/modules/migration/ticktick/ticktick.go index b553b567bdd..0870ae87dbf 100644 --- a/pkg/modules/migration/ticktick/ticktick.go +++ b/pkg/modules/migration/ticktick/ticktick.go @@ -147,7 +147,7 @@ func convertTickTickToVikunja(tasks []*tickTickTask) (result []*models.Namespace } if !t.DueDate.IsZero() && t.Reminder > 0 { - task.Task.Reminders = []time.Time{ + task.Task.ReminderDates = []time.Time{ t.DueDate.Add(t.Reminder * -1), } } diff --git a/pkg/modules/migration/ticktick/ticktick_test.go b/pkg/modules/migration/ticktick/ticktick_test.go index a6834442ed0..1638b376956 100644 --- a/pkg/modules/migration/ticktick/ticktick_test.go +++ b/pkg/modules/migration/ticktick/ticktick_test.go @@ -101,7 +101,7 @@ func TestConvertTicktickTasksToVikunja(t *testing.T) { {Title: "label1"}, {Title: "label2"}, }) - //assert.Equal(t, vikunjaTasks[0].Lists[0].Tasks[0].Reminders, tickTickTasks[0].) // TODO + //assert.Equal(t, vikunjaTasks[0].Lists[0].Tasks[0].ReminderDates, tickTickTasks[0].) // TODO assert.Equal(t, vikunjaTasks[0].Lists[0].Tasks[0].Position, tickTickTasks[0].Order) assert.Equal(t, vikunjaTasks[0].Lists[0].Tasks[0].Done, false) @@ -127,7 +127,7 @@ func TestConvertTicktickTasksToVikunja(t *testing.T) { {Title: "label2"}, {Title: "other label"}, }) - //assert.Equal(t, vikunjaTasks[0].Lists[0].Tasks[0].Reminders, tickTickTasks[0].) // TODO + //assert.Equal(t, vikunjaTasks[0].Lists[0].Tasks[0].ReminderDates, tickTickTasks[0].) // TODO assert.Equal(t, vikunjaTasks[0].Lists[0].Tasks[2].Position, tickTickTasks[2].Order) assert.Equal(t, vikunjaTasks[0].Lists[0].Tasks[2].Done, false) diff --git a/pkg/modules/migration/todoist/todoist.go b/pkg/modules/migration/todoist/todoist.go index 269b5d3de3c..c0fce82318f 100644 --- a/pkg/modules/migration/todoist/todoist.go +++ b/pkg/modules/migration/todoist/todoist.go @@ -471,7 +471,7 @@ func convertTodoistToVikunja(sync *sync, doneItems map[string]*doneItem) (fullVi return nil, err } - tasks[r.ItemID].Reminders = append(tasks[r.ItemID].Reminders, date.In(config.GetTimeZone())) + tasks[r.ItemID].ReminderDates = append(tasks[r.ItemID].ReminderDates, date.In(config.GetTimeZone())) } return []*models.NamespaceWithListsAndTasks{ diff --git a/pkg/modules/migration/todoist/todoist_test.go b/pkg/modules/migration/todoist/todoist_test.go index d75a0a469e8..dd697d47f07 100644 --- a/pkg/modules/migration/todoist/todoist_test.go +++ b/pkg/modules/migration/todoist/todoist_test.go @@ -388,7 +388,7 @@ func TestConvertTodoistToVikunja(t *testing.T) { Description: "Lorem Ipsum dolor sit amet", Done: false, Created: time1, - Reminders: []time.Time{ + ReminderDates: []time.Time{ time.Date(2020, time.June, 15, 23, 59, 0, 0, time.UTC).In(config.GetTimeZone()), time.Date(2020, time.June, 16, 7, 0, 0, 0, time.UTC).In(config.GetTimeZone()), }, @@ -407,7 +407,7 @@ func TestConvertTodoistToVikunja(t *testing.T) { Title: "Task400000002", Done: false, Created: time1, - Reminders: []time.Time{ + ReminderDates: []time.Time{ time.Date(2020, time.July, 15, 7, 0, 0, 0, time.UTC).In(config.GetTimeZone()), }, }, @@ -421,7 +421,7 @@ func TestConvertTodoistToVikunja(t *testing.T) { Created: time1, DoneAt: time3, Labels: vikunjaLabels, - Reminders: []time.Time{ + ReminderDates: []time.Time{ time.Date(2020, time.June, 15, 7, 0, 0, 0, time.UTC).In(config.GetTimeZone()), }, }, @@ -441,7 +441,7 @@ func TestConvertTodoistToVikunja(t *testing.T) { DueDate: dueTime, Created: time1, DoneAt: time3, - Reminders: []time.Time{ + ReminderDates: []time.Time{ time.Date(2020, time.June, 15, 7, 0, 0, 0, time.UTC).In(config.GetTimeZone()), }, }, @@ -531,7 +531,7 @@ func TestConvertTodoistToVikunja(t *testing.T) { Title: "Task400000009", Done: false, Created: time1, - Reminders: []time.Time{ + ReminderDates: []time.Time{ time.Date(2020, time.June, 15, 7, 0, 0, 0, time.UTC).In(config.GetTimeZone()), }, },