java.lang.Object
no.ntnu.principes.service.TaskAssignmentService
Manages task assignments and their lifecycle in the household system.
Handles task completion, assignment to members, points calculation,
and recurring task management.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new TaskAssignmentService with all required repositories. -
Method Summary
Modifier and TypeMethodDescriptionassignTask(Long taskId, Long memberId) Assigns a task to a specific household member.assignTask(Long taskId, Long memberId, boolean publishEvent) Assigns a task to a specific household member.autoAssignTask(Long taskId) Automatically assigns a task to the member with the lowest current workload.autoAssignTask(Long taskId, boolean publishEvent) Automatically assigns a task to the member with the lowest current workload.intcalculateTotalWeightForUser(Long memberId) cancelTask(Long assignmentId) Marks a task assignment as cancelled.completeTask(Long assignmentId) Marks a task assignment as completed, awards points, and handles recurring tasks.Gets all task assignments.getImmediateTasksForMember(Long memberId) Gets immediate tasks (due within 2 days) for a specific member.getTasksByStatus(TaskStatus status) Gets all task assignments with a specific status.getTasksForMember(Long memberId) Gets all task assignments for a specific member.getTasksForMemberDueAt(Long memberId, LocalDate dueDate) Gets all tasks due at a specific date for a specific member.voiduncompleteTask(Long id) Marks a completed task as incomplete.
-
Constructor Details
-
TaskAssignmentService
public TaskAssignmentService()Creates a new TaskAssignmentService with all required repositories. Repositories are obtained from the central DatabaseManager.
-
-
Method Details
-
completeTask
Marks a task assignment as completed, awards points, and handles recurring tasks.- Parameters:
assignmentId- The ID of the assignment to complete- Returns:
- The updated task assignment with completed status
- Throws:
IllegalArgumentException- if the assignment or task is not found
-
assignTask
Assigns a task to a specific household member. If the task is already assigned to someone else or unassigned, updates the assignment.- Parameters:
taskId- The ID of the task to assignmemberId- The ID of the member to assign the task topublishEvent- Whether to publish an event after assignment- Returns:
- The created or updated task assignment
- Throws:
IllegalArgumentException- if the task or member is not found
-
assignTask
Assigns a task to a specific household member. If the task is already assigned to someone else or unassigned, updates the assignment.- Parameters:
taskId- The ID of the task to assignmemberId- The ID of the member to assign the task to- Returns:
- The created or updated task assignment
- Throws:
IllegalArgumentException- if the task or member is not found
-
getTasksForMember
Gets all task assignments for a specific member.- Parameters:
memberId- The ID of the member- Returns:
- A list of task assignment DTOs
-
getImmediateTasksForMember
Gets immediate tasks (due within 2 days) for a specific member.- Parameters:
memberId- The ID of the member- Returns:
- A list of immediate task assignment DTOs
-
getTasksForMemberDueAt
Gets all tasks due at a specific date for a specific member.- Parameters:
memberId- The ID of the memberdueDate- The due date to filter by- Returns:
- A list of task assignment DTOs
-
cancelTask
Marks a task assignment as cancelled.- Parameters:
assignmentId- The ID of the assignment to cancel- Returns:
- The updated task assignment with cancelled status
- Throws:
IllegalArgumentException- if the assignment is not found
-
autoAssignTask
Automatically assigns a task to the member with the lowest current workload. Workload is calculated based on the total weight of a member's pending tasks.- Parameters:
taskId- The ID of the task to assignpublishEvent- Whether to publish an event after assignment- Returns:
- The created task assignment
- Throws:
IllegalArgumentException- if the task is not foundIllegalStateException- if no members are available or selection fails
-
autoAssignTask
Automatically assigns a task to the member with the lowest current workload. Workload is calculated based on the total weight of a member's pending tasks.- Parameters:
taskId- The ID of the task to assign- Returns:
- The created task assignment
- Throws:
IllegalArgumentException- if the task is not foundIllegalStateException- if no members are available or selection fails
-
calculateTotalWeightForUser
-
getTasksByStatus
Gets all task assignments with a specific status.- Parameters:
status- The status to filter by- Returns:
- A list of task assignment DTOs
-
getAllTasks
Gets all task assignments.- Returns:
- A list of all task assignment DTOs
-
uncompleteTask
Marks a completed task as incomplete. Resets the task status to TODO and clears the completion date.- Parameters:
id- The ID of the assignment to uncomplete- Throws:
IllegalArgumentException- if the assignment is not found
-