Service Layer Objects
Let's create a class to represent the create task request.
Create the Create Task Request Class
We know we need certain information to create a new task:
- Title
- Description (optional)
- Due date (optional)
- Priority
Let's create a class to capture all of this information.
As this class is just a data structure, we'll use a Java record.
Let's create the CreateTaskRequest record in the com.devtiro.task.domain
package:
/**
* Models a request to create a new task.
* This class is owned by the service layer.
*
* @param title The title of the task to create.
* @param description The description of the task to create.
* @param dueDate The date the task is due. Can be null.
* @param priority The priority of the task.
*/
public record CreateTaskRequest(
String title,
String description,
LocalDate dueDate,
TaskPriority priority
) {}Now that we have a class to model the create task request, let's move on to the business logic in our service layer.
Summary
- Created the
CreateTaskRequestclass.