Commit graph

24 commits

Author SHA1 Message Date
762b4daf8d Add tests documenting TaskBuilder parameters bug 2026-01-14 18:23:17 +01:00
c95825dc88 Fix Notes API parameter format for Create and Update
The Checkvist API expects nested JSON parameters in the format
{"comment": {"comment": "text"}} but the code was sending flat
{"comment": "text"}, causing 400 Bad Request errors.

Changes:
- Add noteCommentWrapper struct for nested JSON format
- Update createNoteRequest and updateNoteRequest to use wrapper
- Update Create and Update methods to use nested structure
- Update tests to verify nested format

Fixes: checkvist-api-awg
2026-01-14 18:18:31 +01:00
9145157ba7 Add tests documenting Notes API parameter format bug 2026-01-14 18:14:14 +01:00
e4862b8e9b Fix date parsing for Checkvist API format
Add custom APITime type with UnmarshalJSON to handle the non-standard
date format returned by the Checkvist API ("2026/01/14 16:07:31 +0000")
instead of the expected RFC3339 format.

Changes:
- Add APITime type with custom JSON marshaling/unmarshaling in models.go
- Replace time.Time with APITime for UpdatedAt/CreatedAt fields in
  Checklist, Task, and Note structs
- Add NewAPITime constructor for convenience
- Update test fixtures to use real API date format
- Add comprehensive unit tests for APITime in models_test.go

Fixes: checkvist-api-4qn
2026-01-14 18:10:02 +01:00
fa6b93e564 Add test documenting Checkvist API date format bug 2026-01-14 17:55:57 +01:00
3333b7808e Update CHANGELOG with Filter, Archive, WithRepeat, and examples 2026-01-14 14:41:04 +01:00
cb30b178be Add Filter builder, Archive/Unarchive, WithRepeat, and GoDoc examples
- Implement client-side Filter builder with tag, status, due date, and search filters
- Add unit tests for Filter with performance benchmark
- Add Archive/Unarchive methods to ChecklistService
- Add WithRepeat method to TaskBuilder for recurring tasks
- Create GoDoc examples for all major functionality
2026-01-14 14:39:27 +01:00
45e6b6eb18 Create README with quickstart guide
Add comprehensive README.md documentation:
- Project description
- Installation instructions (go get)
- Quick start example with client init, list checklists, create task
- API overview for Checklists, Tasks, Notes
- Due date helpers (DueToday, DueTomorrow, DueAt, DueInDays)
- TaskBuilder fluent interface examples
- Error handling with sentinel errors
- Configuration options (timeout, retry, logger)
- Authentication section (auto, 2FA, current user)
- Link to pkg.go.dev documentation
- MIT license reference

Closes checkvist-api-nrk
2026-01-14 13:48:37 +01:00
2f44308d42 Add unit tests for Notes
Create notes_test.go with tests:
- TestNotes_List: list all notes on a task
- TestNotes_Create: create new note
- TestNotes_Update: update note comment
- TestNotes_Delete: delete note

Add testdata/notes/ fixtures:
- list.json: sample notes list

All 4 tests pass using httptest.Server mocking.

Closes checkvist-api-bbx
2026-01-14 13:47:23 +01:00
e2d0f2299c Add unit tests for Tasks
Create tasks_test.go with comprehensive tests:
- TestTasks_List: list all tasks in checklist
- TestTasks_Get: get single task by ID
- TestTasks_Create: create basic task
- TestTasks_Create_WithBuilder: create task with all options
- TestTasks_Update: update task properties
- TestTasks_Delete: delete task
- TestTasks_Close: mark task as completed
- TestTasks_Reopen: reopen closed task
- TestTasks_Invalidate: invalidate task
- TestDueDate_Parsing: table-driven due date parsing tests
- TestTaskBuilder: builder pattern validation

Add testdata/tasks/ fixtures:
- list.json: sample task list
- single.json: single task response

All 11 tests pass using httptest.Server mocking.

Closes checkvist-api-v2f
2026-01-14 13:46:08 +01:00
0bb7d2d735 Add unit tests for Checklists
Create checklists_test.go with comprehensive tests:
- TestChecklists_List: list all checklists
- TestChecklists_ListArchived: list with archived filter
- TestChecklists_Get: get single checklist by ID
- TestChecklists_Get_NotFound: handle 404 error
- TestChecklists_Create: create new checklist
- TestChecklists_Update: update checklist name
- TestChecklists_Delete: delete checklist

Add testdata/checklists/ fixtures:
- list.json: sample checklist list
- list_archived.json: archived checklists
- single.json: single checklist response

All 7 tests pass using httptest.Server mocking.

Closes checkvist-api-347
2026-01-14 13:42:05 +01:00
5f71f40077 Implement Note operations
Add notes.go with NoteService for task comment CRUD:
- client.Notes(checklistID, taskID) returns NoteService
- List(ctx) - get all notes on a task (GET /comments.json)
- Create(ctx, comment) - add new note (POST /comments.json)
- Update(ctx, noteID, comment) - update note text (PUT /comments/{id}.json)
- Delete(ctx, noteID) - remove note (DELETE /comments/{id}.json)

All methods support context for cancellation and timeouts.

Closes checkvist-api-5ab
2026-01-14 13:40:37 +01:00
3aa2a284de Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)

TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags

Automatic DueDate parsing from DueDateRaw (ISO 8601 format).

Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
e5ee947fa4 Implement Checklist operations
Add checklists.go with ChecklistService for CRUD operations:
- client.Checklists() returns ChecklistService
- List(ctx) - get all checklists (GET /checklists.json)
- ListWithOptions(ctx, opts) - with archived filter support
- Get(ctx, id) - get single checklist (GET /checklists/{id}.json)
- Create(ctx, name) - create new checklist (POST /checklists.json)
- Update(ctx, id, name) - update checklist name (PUT /checklists/{id}.json)
- Delete(ctx, id) - delete checklist (DELETE /checklists/{id}.json)

All methods support context for cancellation and timeouts.

Closes checkvist-api-c2k
2026-01-14 13:38:13 +01:00
3bb006e33d Create CHANGELOG following Keep a Changelog format
Add CHANGELOG.md documenting all implemented features:
- Client with functional options pattern
- Authentication with 2FA and auto token renewal
- HTTP request helper with retry logic
- Data models (Checklist, Task, Note, User, DueDate)
- Error handling with sentinel errors
- Mage build targets
- Comprehensive unit test suite

Follows Keep a Changelog 1.1.0 and Semantic Versioning.

Closes checkvist-api-93m
2026-01-14 13:37:05 +01:00
15cf18e2d8 Add unit tests for Client and Auth
Create client_test.go with comprehensive tests using httptest.Server:
- TestNewClient_Defaults: verify default configuration
- TestNewClient_WithOptions: test functional options
- TestAuthenticate_Success: successful authentication flow
- TestAuthenticate_InvalidCredentials: 401 error handling
- TestAuthenticate_2FA: 2FA token support
- TestTokenRefresh_Auto: automatic token refresh on expiry
- TestTokenRefresh_Manual: manual token refresh
- TestCurrentUser: get current user information
- TestRetryLogic_429: retry on rate limiting
- TestRetryLogic_5xx: retry on server errors
- TestRetryLogic_ExhaustedRetries: max retries exceeded
- TestRetryLogic_ContextCancellation: respect context cancellation
- TestCalculateRetryDelay: exponential backoff calculation
- TestDefaultRetryConfig: verify default retry settings

Add testdata/auth/ fixtures:
- login_success.json
- current_user.json

All 14 tests pass.

Closes checkvist-api-8bn
2026-01-14 13:35:44 +01:00
bf4d899eb8 Set up Mage build targets
Add magefiles/magefile.go with build automation targets:
- Test() - runs go test -v ./...
- Coverage() - runs tests with coverage profile output
- Lint() - runs staticcheck for static analysis
- Fmt() - formats all Go source files with gofmt
- Vet() - runs go vet for code analysis
- Check() - runs all quality checks in sequence (fmt, vet, lint, test)
- Clean() - removes build artifacts

Update magefiles/go.mod with github.com/magefile/mage dependency.

Closes checkvist-api-8q3
2026-01-14 13:33:14 +01:00
04258f1e27 Implement HTTP request helper with retry logic
Add internal HTTP helpers to client.go:
- doRequest(ctx, method, path, body, result) for all API calls
- doGet, doPost, doPut, doDelete convenience methods
- Automatic authentication check before each request
- JSON marshaling of request body and unmarshaling of response

Retry logic with exponential backoff:
- Retries on HTTP 429 (Too Many Requests)
- Retries on HTTP 5xx (Server Errors)
- Retries on network errors (timeout, connection reset)
- Respects context cancellation during retry delays
- Configurable via RetryConfig (MaxRetries, BaseDelay, MaxDelay, Jitter)

Debug logging via slog for request/response tracking.

Closes checkvist-api-8u6
2026-01-14 13:28:03 +01:00
b91e35a684 Implement authentication with auto token renewal
Add authentication methods to client.go:
- Authenticate(ctx) for explicit login
- AuthenticateWith2FA(ctx, token) for 2FA support
- refreshToken(ctx) for token renewal
- ensureAuthenticated(ctx) for auto-auth before requests
- CurrentUser(ctx) to get logged-in user info
- getToken() for thread-safe token access

Features:
- Token stored with expiry time (23h for safety margin)
- Auto-refresh when token expires within 1 hour
- Falls back to full authentication if refresh fails
- Thread-safe token access using RWMutex
- Sends token via X-Client-Token header

API endpoints used:
- POST /auth/login.json?version=2
- POST /auth/refresh_token.json?version=2
- GET /auth/curr_user.json

Closes checkvist-api-lpn
2026-01-14 13:26:39 +01:00
90c48d9323 Implement Client struct with functional options
Add client.go with:
- Client struct with baseURL, username, remoteKey, token, tokenExp,
  httpClient, retryConf, logger, and sync.RWMutex for thread safety
- NewClient constructor accepting username, remoteKey, and variadic options
- Default values: 30s timeout, Checkvist base URL

Add options.go with:
- RetryConfig struct (MaxRetries, BaseDelay, MaxDelay, Jitter)
- DefaultRetryConfig() with 3 retries, 1s base, 30s max, jitter enabled
- Option type for functional options pattern
- WithHTTPClient, WithTimeout, WithRetryConfig, WithLogger, WithBaseURL

Closes checkvist-api-ymg
2026-01-14 13:25:03 +01:00
832364a06f Implement error types and sentinel errors
Add errors.go with:
- APIError struct with StatusCode, Message, RequestID, and Err fields
- Error() method for human-readable error messages
- Unwrap() method for errors.Is() and errors.As() compatibility
- Sentinel errors: ErrUnauthorized, ErrNotFound, ErrRateLimited,
  ErrBadRequest, ErrServerError
- NewAPIError helper function to create APIError from HTTP response
  with automatic status code mapping to sentinel errors

Closes checkvist-api-mnh
2026-01-14 13:23:48 +01:00
61431dfaeb Implement data models for Checkvist API entities
Add models.go with all data structures:
- Checklist struct with fields for ID, Name, Public, Archived, etc.
- Task struct with full task data including status, priority, due dates
- TaskStatus enum (StatusOpen, StatusClosed, StatusInvalidated)
- Note struct for task comments
- User struct for user information
- Tags type as map[string]bool for efficient lookup
- DueDate struct with smart syntax support and constructors
  (DueAt, DueString, DueInDays) and constants (DueToday, DueTomorrow,
  DueNextWeek, DueNextMonth)

Closes checkvist-api-e9p
2026-01-14 13:22:29 +01:00
7af39edcd1 Close ticket checkvist-api-5wr: Initialize Go module and project structure
Mark ticket as closed after successful implementation of:
- go.mod with module path code.beautifulmachines.dev/jakoubek/checkvist-api
- Placeholder Go files (client, checklists, tasks, notes, filter, models, errors, options)
- magefiles/ directory with separate Mage module
- testdata/ directory for test fixtures
- MIT LICENSE
2026-01-14 12:44:01 +01:00
3b076836d3 Initial commit 2026-01-14 12:42:00 +01:00