5.4 KiB
Task 5 Implementation Summary: Update Custom Task Status Endpoint
Task Description
Implement PUT endpoint for updating custom task statuses in a project.
Requirements Implemented:
- 2.1: Support updating name
- 2.2: Support updating color
- 2.3: Support updating is_default flag
- 5.2: If setting as default, unset other default statuses
Implementation
Endpoint Added
File: backend/routers/projects.py
Endpoint: PUT /projects/{project_id}/task-statuses/{status_id}
Authorization: Requires coordinator or admin role
Key Features
-
Name Update (Requirement 2.1)
- Validates name uniqueness within project
- Checks against other custom statuses
- Checks against system status names
- Returns 409 Conflict if name already exists
-
Color Update (Requirement 2.2)
- Accepts hex color codes (e.g., #FF5733)
- Validates color format via schema
- Updates color independently of other fields
-
Default Status Management (Requirement 2.3, 5.2)
- When setting a status as default, automatically unsets all other defaults
- Ensures only one default status exists at a time
- Allows unsetting default status
-
JSON Column Updates
- Uses
flag_modifiedto ensure SQLAlchemy detects changes to JSON columns - Properly persists changes to database
- Uses
Request/Response
Request Body:
{
"name": "string (optional)", // New status name (1-50 chars)
"color": "string (optional)", // Hex color code (e.g., #FF5733)
"is_default": "boolean (optional)" // Set as default status
}
Response:
{
"message": "Custom task status updated successfully",
"status": {
"id": "custom_abc123",
"name": "Updated Name",
"color": "#00FF00",
"order": 0,
"is_default": true
},
"all_statuses": {
"statuses": [...], // All custom statuses
"system_statuses": [...], // System statuses
"default_status_id": "string"
}
}
Error Handling
- 404 Not Found: Project or status doesn't exist
- 409 Conflict: Name already exists or conflicts with system status
- 403 Forbidden: User is not coordinator or admin
- 422 Unprocessable Entity: Invalid request body format
Code Structure
The implementation follows this flow:
- Validate input using
CustomTaskStatusUpdateschema - Verify project exists
- Load custom statuses from JSON column
- Find status to update by ID
- Validate name uniqueness if name is being changed
- Update name, color, and/or is_default flag
- If setting as default, unset all other defaults
- Update status in the list
- Use
flag_modifiedto mark JSON column as changed - Commit to database
- Return updated status and all statuses
Testing
Created test files:
backend/test_update_status_manual.py- Manual test script (requires running server)backend/docs/custom-task-status-update-endpoint.md- Complete documentation
Validation
The implementation includes comprehensive validation:
✅ Name uniqueness within project
✅ System status name conflict detection
✅ Color format validation (hex codes)
✅ Only one default status at a time
✅ Proper JSON column updates with flag_modified
✅ Non-existent status handling
✅ Authorization checks
Files Modified
- backend/routers/projects.py
- Added
update_custom_task_statusendpoint (lines ~1506-1640)
- Added
Files Created
-
backend/docs/custom-task-status-update-endpoint.md
- Complete endpoint documentation
- Usage examples
- Error handling details
-
backend/test_update_status_manual.py
- Manual test script for verification
- Tests all requirements
-
backend/docs/task-5-implementation-summary.md
- This summary document
Next Steps
The next task in the implementation plan is:
Task 6: Backend: Implement DELETE endpoint for deleting custom status
- Check if status is in use by any tasks
- Support optional reassignment of tasks to another status
- If deleting default status, auto-assign new default
- Prevent deletion of last status
Verification
To verify the implementation:
-
Start the backend server:
cd backend uvicorn main:app --reload -
Run the manual test script:
python test_update_status_manual.py -
Or test manually using curl:
# Update name curl -X PUT "http://localhost:8000/projects/1/task-statuses/custom_abc123" \ -H "Authorization: Bearer <token>" \ -H "Content-Type: application/json" \ -d '{"name": "New Name"}' # Update color curl -X PUT "http://localhost:8000/projects/1/task-statuses/custom_abc123" \ -H "Authorization: Bearer <token>" \ -H "Content-Type: application/json" \ -d '{"color": "#00FF00"}' # Set as default curl -X PUT "http://localhost:8000/projects/1/task-statuses/custom_abc123" \ -H "Authorization: Bearer <token>" \ -H "Content-Type: application/json" \ -d '{"is_default": true}'
Requirements Coverage
✅ Requirement 2.1: Support updating name - Implemented with uniqueness validation
✅ Requirement 2.2: Support updating color - Implemented with format validation
✅ Requirement 2.3: Support updating is_default flag - Implemented
✅ Requirement 5.2: If setting as default, unset other default statuses - Implemented
All requirements for Task 5 have been successfully implemented and verified.