diff options
Diffstat (limited to 'internal/api')
| -rw-r--r-- | internal/api/interfaces.go | 1 | ||||
| -rw-r--r-- | internal/api/todoist.go | 31 |
2 files changed, 31 insertions, 1 deletions
diff --git a/internal/api/interfaces.go b/internal/api/interfaces.go index 33bef59..32d0120 100644 --- a/internal/api/interfaces.go +++ b/internal/api/interfaces.go @@ -12,6 +12,7 @@ type TodoistAPI interface { GetTasks(ctx context.Context) ([]models.Task, error) GetProjects(ctx context.Context) ([]models.Project, error) 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 Sync(ctx context.Context, syncToken string) (*TodoistSyncResponse, error) } diff --git a/internal/api/todoist.go b/internal/api/todoist.go index b51fffd..14c6c0b 100644 --- a/internal/api/todoist.go +++ b/internal/api/todoist.go @@ -266,7 +266,7 @@ func ConvertSyncItemsToTasks(items []SyncItemResponse, projectMap map[string]str Priority: item.Priority, Completed: false, Labels: item.Labels, - URL: fmt.Sprintf("https://todoist.com/showTask?id=%s", item.ID), + URL: fmt.Sprintf("https://todoist.com/app/task/%s", item.ID), } // Parse added_at @@ -389,6 +389,35 @@ func (c *TodoistClient) CreateTask(ctx context.Context, content, projectID strin return task, nil } +// UpdateTask updates a task with the specified changes +func (c *TodoistClient) UpdateTask(ctx context.Context, taskID string, updates map[string]interface{}) error { + jsonData, err := json.Marshal(updates) + if err != nil { + return fmt.Errorf("failed to marshal updates: %w", err) + } + + url := fmt.Sprintf("%s/tasks/%s", c.baseURL, taskID) + req, err := http.NewRequestWithContext(ctx, "POST", url, bytes.NewBuffer(jsonData)) + if err != nil { + return fmt.Errorf("failed to create request: %w", err) + } + req.Header.Set("Authorization", "Bearer "+c.apiKey) + req.Header.Set("Content-Type", "application/json") + + resp, err := c.httpClient.Do(req) + if err != nil { + return fmt.Errorf("failed to update task: %w", err) + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusNoContent { + body, _ := io.ReadAll(resp.Body) + return fmt.Errorf("todoist API error (status %d): %s", resp.StatusCode, string(body)) + } + + return nil +} + // CompleteTask marks a task as complete in Todoist func (c *TodoistClient) CompleteTask(ctx context.Context, taskID string) error { // Create POST request to close endpoint |
