Advanced Filtering Documentation
Overview
The task API now supports advanced filtering capabilities that match the frontend's requirements. This includes bracket notation filters, field-specific searches, and response field exclusion.
Filter Syntax
1. Multi-Value Filters
Use filters[field]=value1,value2 to filter by multiple values with OR logic:
filters[tags]=tasks:improvements,tasks:IOS
filters[priority]=low,medium
filters[status]=pending,in_progress2. Field-Specific Searches
Use searches[field]=term to search within specific fields:
searches[name]=task
searches[unique_code]=TSK-2024
searches[description]=important3. Field Exclusion
Use exclude=field1,field2 to remove fields from the response:
exclude=description,createdAt,updatedAt
exclude=participants.employee.departmentRole4. Combined Example
GET /api/v1/tasks/projects/PIPE/tasks?
filters[tags]=tasks:improvements,tasks:IOS&
filters[priority]=low,medium&
searches[unique_code]=abc&
searches[name]=abc&
exclude=description,createdAt,updatedAt&
page=1&
limit=20Implementation Details
Components
Query Parser (
/internal/utils/query_parser.go)- Parses bracket notation parameters
- Handles comma-separated values
- Supports URL encoding
Query Builder (
/internal/repository/query_builder.go)- Builds GORM queries from parsed filters
- Handles PostgreSQL array operations for tags
- Applies WHERE IN clauses for multi-value filters
Response Transformer (
/internal/utils/response_transformer.go)- Excludes specified fields from responses
- Handles nested field exclusion
- Uses reflection for dynamic field removal
Handler Updates (
/internal/handlers/task_handler.go)- Parses advanced filters from query string
- Applies field exclusion to responses
Service Updates (
/internal/services/task_service.go)- Accepts and applies advanced filters
- Maintains backward compatibility
Backward Compatibility
The implementation maintains full backward compatibility with the legacy filter format:
// Legacy format still works
GET /tasks/projects/PIPE/tasks?status=pending&priority=low
// New format
GET /tasks/projects/PIPE/tasks?filters[status]=pending&filters[priority]=lowSupported Fields for Filtering
tags- PostgreSQL array field (uses array overlap operator)priority- Enum field (low, medium, high, urgent)status- Enum field (pending, in_progress, completed, etc.)departmentId- String field- Any other field in snake_case format
Supported Fields for Searching
name- Task nameunique_code- Task unique codedescription- Task description- Any other text field
Testing
Unit tests are provided for all components:
tests/unit/query_parser_test.go- Query parser teststests/unit/response_transformer_test.go- Response transformer teststests/integration/task_filtering_test.go- End-to-end filtering tests
Run tests with:
go test ./tests/unit/query_parser_test.go ./tests/unit/response_transformer_test.go -v