Issue Description
The current GET /tasks endpoint does not support filtering tasks by assignee. To support the new frontend requirement of filtering the team todo list by one or multiple assignees, the backend needs to be updated to accept and process assignee-based filtering parameters.
Expected Behaviour
- The
GET /tasks endpoint should accept a new query parameter, e.g., assigneeId (which can be repeated for multiple values, e.g., ?assigneeId=123&assigneeId=456).
- The
TaskListView in todo/views/task.py should parse this parameter.
- The
TaskService.get_tasks method should accept this list of assignee IDs.
- The
TaskRepository.list method should filter the returned tasks to include only those where the assignee matches one of the provided IDs.
- Database Context: The application uses a dual-write system (
MongoDB + PostgreSQL), but reads are exclusively performed against MongoDB (TaskRepository). The new filtering logic must be implemented in TaskRepository (MongoDB) to maintain consistency.
- Sorting Context: Sorting is already implemented in
TaskRepository.list for fields like priority and updatedAt. Assignee sorting is currently disabled (SORT_FIELD_ASSIGNEE), which is acceptable as the requirement is only for filtering.
- Since assignees are stored in the
task_assignments collection, the repository logic needs to query this collection to find matching task IDs, or we should use an aggregation pipeline to filter effectively.
- The filter should work in combination with existing filters like
teamId and status.
Current Behaviour
- The
TaskListView (todo/views/task.py) accepts teamId, status, page, limit, sort_by, and order.
- The
TaskRepository.list (todo/repositories/task_repository.py) builds a MongoDB query based on these parameters.
- There is no logic to handle
assigneeId filtering.
TaskRepository has a helper _get_assigned_task_ids_for_user which gets tasks for a specific user (the requester), but this is for permission/visibility, not for an arbitrary filter.
Screenshots
N/A
Reproducibility
Steps to Reproduce
-
Send a `GET` request to `/tasks?assigneeId=`.
-
Observe that the `assigneeId` parameter is ignored, and tasks are not filtered by the assignee.
Additional Information
- Files to modify:
todo/views/task.py: Update TaskListView and extend_schema parameters.
todo/services/task_service.py: Update get_tasks signature and logic.
todo/repositories/task_repository.py: Update list and count methods.
- Since
TaskAssignmentRepository holds the mapping, we might need to first query TaskAssignmentRepository for all task IDs assigned to the provided assigneeIds (and filtered by teamId if present).
- Then, use this list of task IDs in the
$in clause of the main TaskRepository query.
- We should be mindful of performance if the number of tasks is large; however, for a team's to-do list, I think it should be manageable.
Checklist
Issue Description
The current
GET /tasksendpoint does not support filtering tasks by assignee. To support the new frontend requirement of filtering the team todo list by one or multiple assignees, the backend needs to be updated to accept and process assignee-based filtering parameters.Expected Behaviour
GET /tasksendpoint should accept a new query parameter, e.g.,assigneeId(which can be repeated for multiple values, e.g.,?assigneeId=123&assigneeId=456).TaskListViewintodo/views/task.pyshould parse this parameter.TaskService.get_tasksmethod should accept this list of assignee IDs.TaskRepository.listmethod should filter the returned tasks to include only those where the assignee matches one of the provided IDs.MongoDB + PostgreSQL), but reads are exclusively performed againstMongoDB(TaskRepository). The new filtering logic must be implemented inTaskRepository(MongoDB) to maintain consistency.TaskRepository.listfor fields likepriorityandupdatedAt. Assignee sorting is currently disabled (SORT_FIELD_ASSIGNEE), which is acceptable as the requirement is only for filtering.task_assignmentscollection, the repository logic needs to query this collection to find matching task IDs, or we should use an aggregation pipeline to filter effectively.teamIdandstatus.Current Behaviour
TaskListView(todo/views/task.py) acceptsteamId,status,page,limit,sort_by, andorder.TaskRepository.list(todo/repositories/task_repository.py) builds aMongoDBquery based on these parameters.assigneeIdfiltering.TaskRepositoryhas a helper_get_assigned_task_ids_for_userwhich gets tasks for a specific user (the requester), but this is for permission/visibility, not for an arbitrary filter.Screenshots
N/A
Reproducibility
Steps to Reproduce
Additional Information
todo/views/task.py: UpdateTaskListViewandextend_schemaparameters.todo/services/task_service.py: Updateget_taskssignature and logic.todo/repositories/task_repository.py: Updatelistandcountmethods.TaskAssignmentRepositoryholds the mapping, we might need to first queryTaskAssignmentRepositoryfor all task IDs assigned to the providedassigneeIds(and filtered byteamIdif present).$inclause of the mainTaskRepositoryquery.Checklist