Subtask Tracking
Relevant source files
The following files were used as context for generating this wiki page:
- src/main/java/com/example/demo/controllers/SubtaskController.java
- src/main/java/com/example/demo/services/SubtaskService.java
- src/main/java/com/example/demo/entity/Subtask.java
- src/main/java/com/example/demo/entity/Task.java
- src/main/java/com/example/demo/services/TaskService.java
- src/main/resources/static/js/task-detail.js
- README.md
Subtask Tracking is a core functional block of the Dashboard Task Management system that allows users to break down main Tasks into smaller, manageable units of work. Each subtask includes its own title, assignee, status, and due date, enabling granular progress monitoring within a parent task.
The system implements automated synchronization between subtasks and their parent tasks: if all subtasks are completed, the parent task status automatically transitions to DONE. Conversely, if a subtask is reopened, the parent task reverts to IN_PROGRESS.
Sources: README.md:58-63, src/main/java/com/example/demo/services/SubtaskService.java:142-156
Data Model and Relationships
Subtasks are represented by the Subtask entity, which maintains a many-to-one relationship with a parent Task. Each subtask is assigned to exactly one User and tracks lifecycle timestamps via JPA lifecycle hooks.
Entity Schema
| Field | Type | Constraints | Description |
|---|---|---|---|
id | Long | Primary Key, Identity | Unique identifier for the subtask. |
task | Task | Not Null, Lazy Fetch | Reference to the parent task. |
title | String | Not Null, Length 200 | Descriptive title of the subtask. |
assignee | User | Lazy Fetch | The user responsible for the subtask. |
status | TaskStatus | Enum (String) | Current state (e.g., NEW, DONE). Defaults to NEW. |
dueDate | LocalDate | - | Deadline for subtask completion. |
createdAt | LocalDateTime | Updatable=false | Timestamp of creation. |
updatedAt | LocalDateTime | - | Timestamp of the last update. |
Sources: src/main/java/com/example/demo/entity/Subtask.java:14-49, src/main/java/com/example/demo/entity/Task.java:55-56
ER Diagram: Task and Subtask Relationship
The following diagram illustrates how Subtasks are contained within the Task entity.
Architecture and Service Logic
Subtask management is handled by the SubtaskService, which enforces business rules regarding role-based access control and state synchronization.
Automated Status Recalculation
When a subtask's status is updated, created, or deleted, the service triggers recalculateParentTaskStatus. This logic ensures the parent task reflects the aggregate progress of its components.
Access Control Matrix
Permission to track and manage subtasks is strictly tied to user roles and their relationship to the project or department.
| Action | ADMIN | MANAGER | PM | TEAM |
|---|---|---|---|---|
| Create | Allowed | Own Dept Projects | Own Projects | Denied |
| Update Status | Allowed | Denied | Own Projects | Denied |
| Delete | Allowed | Only if Task Creator | Denied | Denied |
| View | Allowed | Own Dept | Own Project | Only if Assigned |
Sources: src/main/java/com/example/demo/services/SubtaskService.java:159-216, README.md:18-35
API Endpoints
The SubtaskController provides RESTful endpoints for managing subtasks. All endpoints require a JWT Bearer token.
| Method | Endpoint | Description | Required Role |
|---|---|---|---|
GET | /api/tasks/{taskId}/subtasks | Retrieve all subtasks for a task. | ADMIN, MANAGER, PM, TEAM |
POST | /api/tasks/{taskId}/subtasks | Create a new subtask. | ADMIN, MANAGER, PM |
PATCH | /api/subtasks/{subtaskId} | Update subtask details (title, assignee). | ADMIN, MANAGER, PM |
PATCH | /api/subtasks/{subtaskId}/status | Specifically update status. | ADMIN, PM |
DELETE | /api/subtasks/{subtaskId} | Remove a subtask. | ADMIN, MANAGER |
Sources: src/main/java/com/example/demo/controllers/SubtaskController.java:28-70
Frontend Implementation
The user interface for subtask tracking is integrated into the task detail view. It provides real-time progress bars and interactive checkboxes for status toggling.
Subtask Interaction Flow
The frontend uses an asynchronous API utility to communicate with the backend without refreshing the page.
Key Frontend Functions
loadSubtasks(): Fetches subtasks and calculates progress percentages for the UI bar.toggleSubtask(id, currentStatus): Toggles betweenDONEandIN_PROGRESS.openAddSubtask(): Prompts user for a title and creates a subtask via the API.
Sources: src/main/resources/static/js/task-detail.js:40-88
Conclusion
Subtask Tracking provides the necessary granularity for complex project management within the Dashboard system. By enforcing strict role-based access and automating parent-task status updates, the system ensures data integrity and reduces manual overhead for Project Managers and Administrators.