add local id to local task type
This commit is contained in:
parent
fc4cf55e78
commit
4022a6099a
|
@ -47,9 +47,9 @@ func TestListProcess(t *testing.T) {
|
|||
Project: "project2",
|
||||
}
|
||||
allTasks := []*task.Task{task1, task2, task3, task4}
|
||||
localTask2 := &task.LocalTask{Task: *task2}
|
||||
localTask3 := &task.LocalTask{Task: *task3}
|
||||
localTask4 := &task.LocalTask{Task: *task4}
|
||||
localTask2 := &task.LocalTask{Task: *task2, LocalId: 2}
|
||||
localTask3 := &task.LocalTask{Task: *task3, LocalId: 3}
|
||||
localTask4 := &task.LocalTask{Task: *task4, LocalId: 4}
|
||||
local := storage.NewMemory()
|
||||
test.OK(t, local.SetTasks(allTasks))
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ func TestSyncProcess(t *testing.T) {
|
|||
Folder: task.FOLDER_UNPLANNED,
|
||||
}
|
||||
|
||||
localTask1 := &task.LocalTask{Task: *task1}
|
||||
localTask2 := &task.LocalTask{Task: *task2}
|
||||
localTask1 := &task.LocalTask{Task: *task1, LocalId: 1}
|
||||
localTask2 := &task.LocalTask{Task: *task2, LocalId: 2}
|
||||
|
||||
mstorer, err := mstore.NewMemory(task.KnownFolders)
|
||||
test.OK(t, err)
|
||||
|
|
|
@ -52,7 +52,10 @@ func (m *Memory) FindAllInFolder(folder string) ([]*task.LocalTask, error) {
|
|||
tasks := []*task.LocalTask{}
|
||||
for _, t := range m.tasks {
|
||||
if t.Folder == folder {
|
||||
tasks = append(tasks, &task.LocalTask{Task: *t})
|
||||
tasks = append(tasks, &task.LocalTask{
|
||||
Task: *t,
|
||||
LocalId: m.localIds[t.Id],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,7 +66,10 @@ func (m *Memory) FindAllInProject(project string) ([]*task.LocalTask, error) {
|
|||
tasks := []*task.LocalTask{}
|
||||
for _, t := range m.tasks {
|
||||
if t.Project == project {
|
||||
tasks = append(tasks, &task.LocalTask{Task: *t})
|
||||
tasks = append(tasks, &task.LocalTask{
|
||||
Task: *t,
|
||||
LocalId: m.localIds[t.Id],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,9 +79,11 @@ func (m *Memory) FindAllInProject(project string) ([]*task.LocalTask, error) {
|
|||
func (m *Memory) FindById(id string) (*task.LocalTask, error) {
|
||||
for _, t := range m.tasks {
|
||||
if t.Id == id {
|
||||
return &task.LocalTask{Task: *t}, nil
|
||||
return &task.LocalTask{
|
||||
Task: *t,
|
||||
LocalId: m.localIds[t.Id],
|
||||
}, nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return &task.LocalTask{}, ErrTaskNotFound
|
||||
|
@ -84,7 +92,10 @@ func (m *Memory) FindById(id string) (*task.LocalTask, error) {
|
|||
func (m *Memory) FindByLocalId(localId int) (*task.LocalTask, error) {
|
||||
for _, t := range m.tasks {
|
||||
if m.localIds[t.Id] == localId {
|
||||
return &task.LocalTask{Task: *t}, nil
|
||||
return &task.LocalTask{
|
||||
Task: *t,
|
||||
LocalId: localId,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,9 +41,9 @@ func TestMemory(t *testing.T) {
|
|||
},
|
||||
}
|
||||
tasks := []*task.Task{task1, task2, task3}
|
||||
localTask1 := &task.LocalTask{Task: *task1}
|
||||
localTask2 := &task.LocalTask{Task: *task2}
|
||||
localTask3 := &task.LocalTask{Task: *task3}
|
||||
localTask1 := &task.LocalTask{Task: *task1, LocalId: 1}
|
||||
localTask2 := &task.LocalTask{Task: *task2, LocalId: 2}
|
||||
localTask3 := &task.LocalTask{Task: *task3, LocalId: 3}
|
||||
|
||||
t.Run("sync", func(t *testing.T) {
|
||||
mem := storage.NewMemory()
|
||||
|
|
|
@ -152,8 +152,9 @@ SET latest_sync = ?`,
|
|||
|
||||
func (s *Sqlite) FindAllInFolder(folder string) ([]*task.LocalTask, error) {
|
||||
rows, err := s.db.Query(`
|
||||
SELECT id, version, folder, action, project, due, recur
|
||||
SELECT task.id, local_id.local_id as local_id, version, folder, action, project, due, recur
|
||||
FROM task
|
||||
LEFT JOIN local_id ON task.id = local_id.id
|
||||
WHERE folder = ?`, folder)
|
||||
if err != nil {
|
||||
return []*task.LocalTask{}, fmt.Errorf("%w: %v", ErrSqliteFailure, err)
|
||||
|
@ -164,8 +165,9 @@ WHERE folder = ?`, folder)
|
|||
|
||||
func (s *Sqlite) FindAllInProject(project string) ([]*task.LocalTask, error) {
|
||||
rows, err := s.db.Query(`
|
||||
SELECT id, version, folder, action, project, due, recur
|
||||
SELECT task.id, local_id.local_id, version, folder, action, project, due, recur
|
||||
FROM task
|
||||
LEFT JOIN local_id ON task.id = local_id.id
|
||||
WHERE project = ?`, project)
|
||||
if err != nil {
|
||||
return []*task.LocalTask{}, fmt.Errorf("%w: %v", ErrSqliteFailure, err)
|
||||
|
@ -176,13 +178,14 @@ WHERE project = ?`, project)
|
|||
|
||||
func (s *Sqlite) FindById(id string) (*task.LocalTask, error) {
|
||||
var folder, action, project, due, recur string
|
||||
var version int
|
||||
var localId, version int
|
||||
row := s.db.QueryRow(`
|
||||
SELECT version, folder, action, project, due, recur
|
||||
SELECT local_id.local_id, version, folder, action, project, due, recur
|
||||
FROM task
|
||||
WHERE id = ?
|
||||
LEFT JOIN local_id ON task.id = local_id.id
|
||||
WHERE task.id = ?
|
||||
LIMIT 1`, id)
|
||||
if err := row.Scan(&version, &folder, &action, &project, &due, &recur); err != nil {
|
||||
if err := row.Scan(&localId, &version, &folder, &action, &project, &due, &recur); err != nil {
|
||||
return &task.LocalTask{}, fmt.Errorf("%w: %v", ErrSqliteFailure, err)
|
||||
}
|
||||
|
||||
|
@ -195,7 +198,9 @@ LIMIT 1`, id)
|
|||
Project: project,
|
||||
Due: task.NewDateFromString(due),
|
||||
Recur: task.NewRecurrer(recur),
|
||||
}}, nil
|
||||
},
|
||||
LocalId: localId,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Sqlite) FindByLocalId(localId int) (*task.LocalTask, error) {
|
||||
|
@ -239,8 +244,8 @@ func tasksFromRows(rows *sql.Rows) ([]*task.LocalTask, error) {
|
|||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var id, folder, action, project, due, recur string
|
||||
var version int
|
||||
if err := rows.Scan(&id, &version, &folder, &action, &project, &due, &recur); err != nil {
|
||||
var localId, version int
|
||||
if err := rows.Scan(&id, &localId, &version, &folder, &action, &project, &due, &recur); err != nil {
|
||||
return []*task.LocalTask{}, fmt.Errorf("%w: %v", ErrSqliteFailure, err)
|
||||
}
|
||||
tasks = append(tasks, &task.LocalTask{
|
||||
|
@ -252,7 +257,9 @@ func tasksFromRows(rows *sql.Rows) ([]*task.LocalTask, error) {
|
|||
Project: project,
|
||||
Due: task.NewDateFromString(due),
|
||||
Recur: task.NewRecurrer(recur),
|
||||
}})
|
||||
},
|
||||
LocalId: localId,
|
||||
})
|
||||
}
|
||||
|
||||
return tasks, nil
|
||||
|
|
|
@ -2,4 +2,5 @@ package task
|
|||
|
||||
type LocalTask struct {
|
||||
Task
|
||||
LocalId int
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue