tracks/internal/models
Claude 9b0428638c
Fix polymorphic tagging and add test script
This commit fixes the tag loading issue and adds comprehensive testing.

## Bug Fix: Polymorphic Tag Loading

Fixed issue with many-to-many tag relationships not working correctly with
polymorphic associations. The problem was that GORM doesn't support using
`many2many` with polymorphic relationships directly.

**Changes:**
- Modified `internal/models/todo.go`: Changed Tags field to use `gorm:"-"`
  to skip GORM handling
- Modified `internal/models/recurring_todo.go`: Same fix for recurring todos
- Modified `internal/services/todo_service.go`: Added `loadTodoTags()` helper
  function to manually load tags through the taggings join table

**How it works now:**
1. Tags are no longer automatically loaded by GORM
2. Manual loading via JOIN query: `tags JOIN taggings ON tag_id WHERE taggable_id AND taggable_type`
3. Called after loading todos in both `GetTodo()` and `GetTodos()`

## Testing

Added `test_api.sh` - comprehensive integration test script that tests:
1. Health check
2. User registration
3. Authentication
4. Context creation
5. Project creation
6. Todo creation with tags
7. Listing todos with filters
8. Completing todos
9. Project statistics

All tests pass successfully!

## Files Changed

- `internal/models/todo.go`: Fix tag relationship
- `internal/models/recurring_todo.go`: Fix tag relationship
- `internal/services/todo_service.go`: Add manual tag loading
- `test_api.sh`: New integration test script
- `go.sum`: Updated with exact dependency versions
2025-11-05 10:59:26 +00:00
..
attachment.go Rewrite Tracks application in Golang 2025-11-05 10:46:59 +00:00
context.go Rewrite Tracks application in Golang 2025-11-05 10:46:59 +00:00
dependency.go Rewrite Tracks application in Golang 2025-11-05 10:46:59 +00:00
note.go Rewrite Tracks application in Golang 2025-11-05 10:46:59 +00:00
preference.go Rewrite Tracks application in Golang 2025-11-05 10:46:59 +00:00
project.go Rewrite Tracks application in Golang 2025-11-05 10:46:59 +00:00
recurring_todo.go Fix polymorphic tagging and add test script 2025-11-05 10:59:26 +00:00
tag.go Rewrite Tracks application in Golang 2025-11-05 10:46:59 +00:00
todo.go Fix polymorphic tagging and add test script 2025-11-05 10:59:26 +00:00
user.go Rewrite Tracks application in Golang 2025-11-05 10:46:59 +00:00