From c37f3bfdfd7910b8dcc21c5515ff426b702cbbb0 Mon Sep 17 00:00:00 2001 From: Amolith Date: Sun, 11 May 2025 15:08:12 -0600 Subject: [PATCH] refactor(tasks)!: add task DTOs, enforce UUIDs for IDs Introduces `Task` and `Source` data transfer objects (DTOs) for representing task-related data, primarily for API responses. Validation for `CreateTaskRequest` has been updated: - `AreaID` validation now enforces `uuid4` format if the field is present. - `GoalID` validation now enforces `uuid4` format if the field is present. BREAKING CHANGE: The `AreaID` and `GoalID` fields in the `CreateTaskRequest` must now be valid UUIDv4 strings if provided. Previously, these fields might have accepted non-UUID strings or had less strict validation. Clients sending requests to create tasks must ensure these IDs conform to the UUIDv4 format to avoid validation errors. --- lunatask/tasks.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/lunatask/tasks.go b/lunatask/tasks.go index 379007e2019ecf05838815c02601ac53f849fe0b..12fad020227b69d428790d46fb4224bd40a4de51 100644 --- a/lunatask/tasks.go +++ b/lunatask/tasks.go @@ -33,10 +33,35 @@ func NewClient(accessToken string) *Client { } } +// Source represents a task source like GitHub or other integrations +type Source struct { + Source string `json:"source"` + SourceID string `json:"source_id"` +} + +// Task is only ever used in responses +type Task struct { + ID string `json:"id,omitempty"` + AreaID string `json:"area_id,omitempty"` + GoalID string `json:"goal_id,omitempty"` + Status string `json:"status,omitempty"` + PreviousStatus string `json:"previous_status,omitempty"` + Estimate int `json:"estimate,omitempty"` + Priority int `json:"priority,omitempty"` + Progress int `json:"progress,omitempty"` + Motivation string `json:"motivation,omitempty"` + Eisenhower int `json:"eisenhower,omitempty"` + Sources []Source `json:"sources,omitempty"` + ScheduledOn string `json:"scheduled_on,omitempty"` + CompletedAt string `json:"completed_at,omitempty"` + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` +} + // CreateTaskRequest represents the request to create a task in Lunatask type CreateTaskRequest struct { - AreaID string `json:"area_id"` - GoalID string `json:"goal_id,omitempty" validate:"omitempty"` + AreaID string `json:"area_id" validate:"omitempty,uuid4"` + GoalID string `json:"goal_id,omitempty" validate:"omitempty,uuid4"` Name string `json:"name" validate:"max=100"` Note string `json:"note,omitempty" validate:"omitempty"` Status string `json:"status,omitempty" validate:"omitempty,oneof=later next started waiting completed"`