summaryrefslogtreecommitdiff
path: root/internal/api/todoist.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api/todoist.go')
-rw-r--r--internal/api/todoist.go54
1 files changed, 31 insertions, 23 deletions
diff --git a/internal/api/todoist.go b/internal/api/todoist.go
index 2745e3e..be699ce 100644
--- a/internal/api/todoist.go
+++ b/internal/api/todoist.go
@@ -166,34 +166,42 @@ func (c *TodoistClient) Sync(ctx context.Context, syncToken string) (*TodoistSyn
return &syncResp, nil
}
+// ConvertSyncItemToTask converts a single sync item to a Task model.
+// Returns the task and true if the item is active, or a zero Task and false if it should be skipped.
+func ConvertSyncItemToTask(item SyncItemResponse, projectMap map[string]string) (models.Task, bool) {
+ if item.IsCompleted || item.IsDeleted {
+ return models.Task{}, false
+ }
+
+ task := models.Task{
+ ID: item.ID,
+ Content: item.Content,
+ Description: item.Description,
+ ProjectID: item.ProjectID,
+ ProjectName: projectMap[item.ProjectID],
+ Priority: item.Priority,
+ Completed: false,
+ Labels: item.Labels,
+ URL: fmt.Sprintf("https://todoist.com/app/task/%s", item.ID),
+ }
+
+ if item.AddedAt != "" {
+ if createdAt, err := time.Parse(time.RFC3339, item.AddedAt); err == nil {
+ task.CreatedAt = createdAt
+ }
+ }
+
+ task.DueDate = parseDueDate(item.Due)
+ return task, true
+}
+
// ConvertSyncItemsToTasks converts sync API items to Task models
func ConvertSyncItemsToTasks(items []SyncItemResponse, projectMap map[string]string) []models.Task {
tasks := make([]models.Task, 0, len(items))
for _, item := range items {
- if item.IsCompleted || item.IsDeleted {
- continue
- }
-
- task := models.Task{
- ID: item.ID,
- Content: item.Content,
- Description: item.Description,
- ProjectID: item.ProjectID,
- ProjectName: projectMap[item.ProjectID],
- Priority: item.Priority,
- Completed: false,
- Labels: item.Labels,
- URL: fmt.Sprintf("https://todoist.com/app/task/%s", item.ID),
+ if task, ok := ConvertSyncItemToTask(item, projectMap); ok {
+ tasks = append(tasks, task)
}
-
- if item.AddedAt != "" {
- if createdAt, err := time.Parse(time.RFC3339, item.AddedAt); err == nil {
- task.CreatedAt = createdAt
- }
- }
-
- task.DueDate = parseDueDate(item.Due)
- tasks = append(tasks, task)
}
return tasks
}