Service Layer Objects
The create task method uses an object to capture all the information needed to create a task.
Let's do the same for the task update feature. Let's create the update task request class.
Create the Update Task Request Class
Let's create the UpdateTaskRequest in com.devtiro.task.domain:
/**
* Models a request to update an existing task.
* This class is owned by the service layer.
*
* @param title The title of the task.
* @param description The description of the task.
* @param dueDate The date the task is due.
* @param status The status of the task. Can be null.
* @param priority The priority of the task.
*/
public record UpdateTaskRequest(
String title,
String description,
LocalDate dueDate,
TaskStatus status,
TaskPriority priority) {}This class differs from the CreateTaskRequest class in one important way.
This class has a status field. This is how the user is able to update
the status of their task.
With the class created, we're almost ready to start the business logic, but first we must create a custom exception.
Summary
- Created the
UpdateTaskRequestclass.