summaryrefslogtreecommitdiff
path: root/internal/api
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api')
-rw-r--r--internal/api/google_calendar.go22
-rw-r--r--internal/api/interfaces.go1
-rw-r--r--internal/api/todoist.go23
3 files changed, 41 insertions, 5 deletions
diff --git a/internal/api/google_calendar.go b/internal/api/google_calendar.go
index 8dd48f0..2154351 100644
--- a/internal/api/google_calendar.go
+++ b/internal/api/google_calendar.go
@@ -76,15 +76,27 @@ func (c *GoogleCalendarClient) GetUpcomingEvents(ctx context.Context, maxResults
}
}
+ // Deduplicate events (same event may appear in multiple calendars)
+ seen := make(map[string]bool)
+ var uniqueEvents []models.CalendarEvent
+ for _, event := range allEvents {
+ // Use summary + start time as dedup key
+ key := event.Summary + event.Start.Format(time.RFC3339)
+ if !seen[key] {
+ seen[key] = true
+ uniqueEvents = append(uniqueEvents, event)
+ }
+ }
+
// Sort all events by start time
- sort.Slice(allEvents, func(i, j int) bool {
- return allEvents[i].Start.Before(allEvents[j].Start)
+ sort.Slice(uniqueEvents, func(i, j int) bool {
+ return uniqueEvents[i].Start.Before(uniqueEvents[j].Start)
})
// Limit to maxResults
- if len(allEvents) > maxResults {
- allEvents = allEvents[:maxResults]
+ if len(uniqueEvents) > maxResults {
+ uniqueEvents = uniqueEvents[:maxResults]
}
- return allEvents, nil
+ return uniqueEvents, nil
}
diff --git a/internal/api/interfaces.go b/internal/api/interfaces.go
index e2521f4..842814c 100644
--- a/internal/api/interfaces.go
+++ b/internal/api/interfaces.go
@@ -14,6 +14,7 @@ type TodoistAPI interface {
CreateTask(ctx context.Context, content, projectID string, dueDate *time.Time, priority int) (*models.Task, error)
UpdateTask(ctx context.Context, taskID string, updates map[string]interface{}) error
CompleteTask(ctx context.Context, taskID string) error
+ ReopenTask(ctx context.Context, taskID string) error
Sync(ctx context.Context, syncToken string) (*TodoistSyncResponse, error)
}
diff --git a/internal/api/todoist.go b/internal/api/todoist.go
index 689bf10..b3d4579 100644
--- a/internal/api/todoist.go
+++ b/internal/api/todoist.go
@@ -442,3 +442,26 @@ func (c *TodoistClient) CompleteTask(ctx context.Context, taskID string) error {
return nil
}
+
+// ReopenTask marks a completed task as active in Todoist
+func (c *TodoistClient) ReopenTask(ctx context.Context, taskID string) error {
+ url := fmt.Sprintf("%s/tasks/%s/reopen", c.baseURL, taskID)
+ req, err := http.NewRequestWithContext(ctx, "POST", url, nil)
+ if err != nil {
+ return fmt.Errorf("failed to create request: %w", err)
+ }
+ req.Header.Set("Authorization", "Bearer "+c.apiKey)
+
+ resp, err := c.httpClient.Do(req)
+ if err != nil {
+ return fmt.Errorf("failed to reopen task: %w", err)
+ }
+ defer resp.Body.Close()
+
+ if resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusOK {
+ body, _ := io.ReadAll(resp.Body)
+ return fmt.Errorf("todoist API error (status %d): %s", resp.StatusCode, string(body))
+ }
+
+ return nil
+}