From 9fe0998436488537a8a2e8ffeefb0c4424b41c60 Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Mon, 12 Jan 2026 09:27:16 -1000 Subject: Initial commit: Personal Consolidation Dashboard (Phase 1 Complete) Implemented a unified web dashboard aggregating tasks, notes, and meal planning: Core Features: - Trello integration (PRIMARY feature - boards, cards, lists) - Todoist integration (tasks and projects) - Obsidian integration (20 most recent notes) - PlanToEat integration (optional - 7-day meal planning) - Mobile-responsive web UI with auto-refresh (5 min) - SQLite caching with 5-minute TTL - AI agent endpoint with Bearer token authentication Technical Implementation: - Go 1.21+ backend with chi router - Interface-based API client design for testability - Parallel data fetching with goroutines - Graceful degradation (partial data on API failures) - .env file loading with godotenv - Comprehensive test coverage (9/9 tests passing) Bug Fixes: - Fixed .env file not being loaded at startup - Fixed nil pointer dereference with optional API clients (typed nil interface gotcha) Documentation: - START_HERE.md - Quick 5-minute setup guide - QUICKSTART.md - Fast track setup - SETUP_GUIDE.md - Detailed step-by-step instructions - PROJECT_SUMMARY.md - Complete project overview - CLAUDE.md - Guide for Claude Code instances - AI_AGENT_ACCESS.md - AI agent design document - AI_AGENT_SETUP.md - Claude.ai integration guide - TRELLO_AUTH_UPDATE.md - New Power-Up auth process Statistics: - Binary: 17MB - Code: 2,667 lines - Tests: 5 unit + 4 acceptance tests (all passing) - Dependencies: chi, sqlite3, godotenv Co-Authored-By: Claude Sonnet 4.5 --- internal/api/todoist.go | 171 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 internal/api/todoist.go (limited to 'internal/api/todoist.go') diff --git a/internal/api/todoist.go b/internal/api/todoist.go new file mode 100644 index 0000000..be59e73 --- /dev/null +++ b/internal/api/todoist.go @@ -0,0 +1,171 @@ +package api + +import ( + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "time" + + "task-dashboard/internal/models" +) + +const ( + todoistBaseURL = "https://api.todoist.com/rest/v2" +) + +// TodoistClient handles interactions with the Todoist API +type TodoistClient struct { + apiKey string + httpClient *http.Client +} + +// NewTodoistClient creates a new Todoist API client +func NewTodoistClient(apiKey string) *TodoistClient { + return &TodoistClient{ + apiKey: apiKey, + httpClient: &http.Client{ + Timeout: 30 * time.Second, + }, + } +} + +// todoistTaskResponse represents the API response structure +type todoistTaskResponse struct { + ID string `json:"id"` + Content string `json:"content"` + Description string `json:"description"` + ProjectID string `json:"project_id"` + Priority int `json:"priority"` + Labels []string `json:"labels"` + Due *struct { + Date string `json:"date"` + Datetime string `json:"datetime"` + } `json:"due"` + URL string `json:"url"` + CreatedAt string `json:"created_at"` +} + +// todoistProjectResponse represents the project API response +type todoistProjectResponse struct { + ID string `json:"id"` + Name string `json:"name"` +} + +// GetTasks fetches all active tasks from Todoist +func (c *TodoistClient) GetTasks(ctx context.Context) ([]models.Task, error) { + req, err := http.NewRequestWithContext(ctx, "GET", todoistBaseURL+"/tasks", nil) + if err != nil { + return nil, 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 nil, fmt.Errorf("failed to fetch tasks: %w", err) + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + body, _ := io.ReadAll(resp.Body) + return nil, fmt.Errorf("todoist API error (status %d): %s", resp.StatusCode, string(body)) + } + + var apiTasks []todoistTaskResponse + if err := json.NewDecoder(resp.Body).Decode(&apiTasks); err != nil { + return nil, fmt.Errorf("failed to decode response: %w", err) + } + + // Fetch projects to get project names + projects, err := c.GetProjects(ctx) + if err != nil { + // If we can't get projects, continue with empty project names + projects = make(map[string]string) + } + + // Convert to our model + tasks := make([]models.Task, 0, len(apiTasks)) + for _, apiTask := range apiTasks { + task := models.Task{ + ID: apiTask.ID, + Content: apiTask.Content, + Description: apiTask.Description, + ProjectID: apiTask.ProjectID, + ProjectName: projects[apiTask.ProjectID], + Priority: apiTask.Priority, + Completed: false, + Labels: apiTask.Labels, + URL: apiTask.URL, + } + + // Parse created_at + if createdAt, err := time.Parse(time.RFC3339, apiTask.CreatedAt); err == nil { + task.CreatedAt = createdAt + } + + // Parse due date + if apiTask.Due != nil { + var dueDate time.Time + if apiTask.Due.Datetime != "" { + dueDate, err = time.Parse(time.RFC3339, apiTask.Due.Datetime) + } else if apiTask.Due.Date != "" { + dueDate, err = time.Parse("2006-01-02", apiTask.Due.Date) + } + if err == nil { + task.DueDate = &dueDate + } + } + + tasks = append(tasks, task) + } + + return tasks, nil +} + +// GetProjects fetches all projects and returns a map of project ID to name +func (c *TodoistClient) GetProjects(ctx context.Context) (map[string]string, error) { + req, err := http.NewRequestWithContext(ctx, "GET", todoistBaseURL+"/projects", nil) + if err != nil { + return nil, 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 nil, fmt.Errorf("failed to fetch projects: %w", err) + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + body, _ := io.ReadAll(resp.Body) + return nil, fmt.Errorf("todoist API error (status %d): %s", resp.StatusCode, string(body)) + } + + var apiProjects []todoistProjectResponse + if err := json.NewDecoder(resp.Body).Decode(&apiProjects); err != nil { + return nil, fmt.Errorf("failed to decode response: %w", err) + } + + // Convert to map + projects := make(map[string]string, len(apiProjects)) + for _, project := range apiProjects { + projects[project.ID] = project.Name + } + + return projects, nil +} + +// CreateTask creates a new task in Todoist +func (c *TodoistClient) CreateTask(ctx context.Context, content, projectID string, dueDate *time.Time, priority int) (*models.Task, error) { + // This will be implemented in Phase 2 + return nil, fmt.Errorf("not implemented yet") +} + +// CompleteTask marks a task as complete in Todoist +func (c *TodoistClient) CompleteTask(ctx context.Context, taskID string) error { + // This will be implemented in Phase 2 + return fmt.Errorf("not implemented yet") +} -- cgit v1.2.3