Data Transfer Objects
Relevant source files
The following files were used as context for generating this wiki page:
- src/main/java/com/example/demo/dto/request/TaskRequest.java
- src/main/java/com/example/demo/services/TaskService.java
- src/main/java/com/example/demo/services/AttachmentService.java
- src/main/java/com/example/demo/services/AdminService.java
- src/main/java/com/example/demo/services/SubtaskService.java
- src/main/java/com/example/demo/controllers/AdminController.java
Data Transfer Objects (DTOs) in the Dashboard Task Management system serve as the primary contract for data exchange between the client-side Vue.js application and the Spring Boot backend. They decouple the internal database entities from the external API representation, allowing for validation, security, and structured communication.
The project utilizes DTOs for various purposes: capturing user input through request objects (e.g., TaskRequest), providing structured data through response objects (e.g., AttachmentResponse), and utilizing Java 21 Records for concise data structures in administrative services.
Request DTOs
Request DTOs are used to encapsulate data sent from the client to the server during creation or update operations. These objects often include Jakarta Validation constraints to ensure data integrity before reaching the service layer.
Task Management Requests
The TaskRequest class is a central DTO used for creating tasks. It includes fields for basic task information, associations with projects and users, and nested subtask data.
| Field | Type | Validation/Default | Description |
|---|---|---|---|
title | String | @NotBlank | The title of the task. |
description | String | - | Detailed task description. |
projectId | Long | @NotNull | ID of the parent project. |
priority | Priority | MEDIUM | Task priority level. |
status | TaskStatus | NEW | Initial status of the task. |
dueDate | LocalDate | @NotNull | The deadline for the task. |
assigneeIds | List<Long> | @NotNull | List of user IDs assigned to the task. |
Sources: src/main/java/com/example/demo/dto/request/TaskRequest.java:15-44, src/main/java/com/example/demo/services/TaskService.java:316-328
Administrative Requests
Administrative services use specialized DTOs (implemented as Java Records) for managing users, projects, and departments.
- UserCreateDto: Captures full name, email, password, role, and department ID for new user creation.
- ProjectCreateDto: Used by the
AdminServiceto initialize new projects with a specific PM and department. - DepartmentDto: Represents a department along with its manager's details.
Sources: src/main/java/com/example/demo/services/AdminService.java:101-112, src/main/java/com/example/demo/services/AdminService.java:144-162
Response DTOs
Response DTOs are used by services to return data to the controllers and ultimately to the client. These objects sanitize the data by removing sensitive information like passwords.
File and Attachment Handling
The AttachmentService utilizes AttachmentResponse to communicate file metadata and a specialized record for file downloads.
The diagram above illustrates the structures used to handle file metadata and downloads.
Sources: src/main/java/com/example/demo/services/AttachmentService.java:136-146, src/main/java/com/example/demo/services/AttachmentService.java:291-314
User Identity (MeDto)
The MeDto is a specific DTO returned by the /api/admin/auth/me endpoint to provide the current user's profile information, including their role and department.
Sources: src/main/java/com/example/demo/controllers/AdminController.java:36-47
Data Flow and Mapping
The system follows a strict flow where entities are converted to DTOs in the service layer before being returned to the controller.
This diagram shows the standard path of data as it transforms from a Request DTO to a Database Entity and back to a Response DTO.
Sources: src/main/java/com/example/demo/services/TaskService.java:342-384, src/main/java/com/example/demo/services/AdminService.java:55-100
Mapping Logic Example
The TaskService uses a toResponse method to manually map Task entities to TaskResponse objects. This process includes:
- Mapping basic fields (id, title, status).
- Resolving project and PM names.
- Collecting assignee IDs and names.
- Calculating subtask completion counts.
Sources: src/main/java/com/example/demo/services/TaskService.java:342-384
Summary
The DTO layer in the Dashboard application ensures that the API is robust, validated, and efficient. By separating the input (Request) and output (Response) structures, the system maintains security and provides the frontend with exactly the data required for rendering the Kanban board and task details. This architecture is consistently applied across Task, Subtask, Attachment, and Administrative modules.