java.lang.Object
no.ntnu.principes.repository.AbstractRepository<TaskAssignment,Long>
no.ntnu.principes.repository.TaskAssignmentRepository
- All Implemented Interfaces:
BaseRepository<TaskAssignment,Long>
Repository for managing the assignment of tasks to household members.
Provides methods for tracking task assignments, due dates, completion status,
and querying assignments by various criteria.
-
Field Summary
Fields inherited from class no.ntnu.principes.repository.AbstractRepository
dataSource, tableName -
Constructor Summary
ConstructorsConstructorDescriptionTaskAssignmentRepository(DataSource dataSource) Creates a new TaskAssignmentRepository with the specified data source. -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteById(Long id) Deletes a task assignment by its ID.intdeleteByMemberId(Long memberId) Deletes all task assignments for a specific member.intdeleteByTaskId(Long taskId) Deletes all assignments for a specific task.findAll()Retrieves all task assignments.Finds a task assignment by its ID.findByMemberId(Long memberId) Finds all task assignments for a specific member, ordered by due date.findByMemberIdAndDueAt(Long memberId, LocalDate dueDate) Finds task assignments for a specific member with a specific due date.findByMemberIdAndStatus(Long memberId, TaskStatus status) Finds task assignments for a member with a specific status, ordered by due date.findByStatus(TaskStatus status) Finds all task assignments with a specific status.findByTaskAndMember(Long taskId, Long memberId) Finds a task assignment by both task and member IDs.findByTaskIds(List<Long> taskIds) Finds task assignments for multiple tasks.findByUnassignedTask(Long taskId) Finds unassigned task assignments for a specific task.findImmediateTasksForMember(Long memberId) Finds immediate tasks for a member (due within 2 days or with no due date).Finds the most recently completed assignment for a task.findPendingByTaskId(Long taskId) Finds pending task assignments for a specific task.doublegetCompletionRateForMember(Long memberId) Calculates the completion rate for a member's task assignments.protected TaskAssignmentMaps a database result set row to a TaskAssignment object.save(TaskAssignment assignment) Saves a task assignment, creating a new record or updating an existing one.Methods inherited from class no.ntnu.principes.repository.AbstractRepository
executeInsert, executeUpdate, queryList, queryListRaw, queryListRaw, queryOne, queryOneRaw, queryOneRaw
-
Constructor Details
-
TaskAssignmentRepository
Creates a new TaskAssignmentRepository with the specified data source.- Parameters:
dataSource- The JDBC data source for database connections
-
-
Method Details
-
findById
Finds a task assignment by its ID.- Parameters:
id- The task assignment ID- Returns:
- An Optional containing the found task assignment or empty if not found
-
findAll
Retrieves all task assignments.- Returns:
- A list of all task assignments
-
save
Saves a task assignment, creating a new record or updating an existing one. Handles date formatting for database storage.- Parameters:
assignment- The task assignment to save- Returns:
- The saved task assignment with ID populated
-
deleteById
Deletes a task assignment by its ID.- Parameters:
id- The ID of the task assignment to delete
-
mapRow
Maps a database result set row to a TaskAssignment object. Handles nullable date fields.- Specified by:
mapRowin classAbstractRepository<TaskAssignment,Long> - Parameters:
rs- The result set positioned at the row to map- Returns:
- The mapped TaskAssignment object
- Throws:
SQLException- If a database error occurs during mapping
-
findByMemberId
Finds all task assignments for a specific member, ordered by due date.- Parameters:
memberId- The ID of the member to find assignments for- Returns:
- A list of the member's task assignments
-
findByMemberIdAndStatus
Finds task assignments for a member with a specific status, ordered by due date.- Parameters:
memberId- The ID of the member to find assignments forstatus- The status to filter by (e.g., TODO, DONE)- Returns:
- A list of matching task assignments
-
findByStatus
Finds all task assignments with a specific status.- Parameters:
status- The status to filter by (e.g., TODO, DONE)- Returns:
- A list of matching task assignments
-
findPendingByTaskId
Finds pending task assignments for a specific task.- Parameters:
taskId- The ID of the task to find pending assignments for- Returns:
- A list of pending (TODO status) task assignments
-
findByTaskIds
Finds task assignments for multiple tasks.- Parameters:
taskIds- A list of task IDs to find assignments for- Returns:
- A list of matching task assignments, or all assignments if taskIds is empty
-
getCompletionRateForMember
Calculates the completion rate for a member's task assignments. The rate is the number of completed tasks divided by the total number of tasks. Returns 0.0 if the member has no tasks or if an error occurs.- Parameters:
memberId- The ID of the member to calculate the completion rate for- Returns:
- The completion rate as a value between 0.0 and 1.0
-
findByTaskAndMember
Finds a task assignment by both task and member IDs.- Parameters:
taskId- The ID of the taskmemberId- The ID of the member- Returns:
- An Optional containing the matching assignment or empty if not found
-
findByUnassignedTask
Finds unassigned task assignments for a specific task.- Parameters:
taskId- The ID of the task to find unassigned assignments for- Returns:
- A list of task assignments with null member IDs
-
findLastCompletedAssignment
Finds the most recently completed assignment for a task.- Parameters:
id- The ID of the task- Returns:
- An Optional containing the most recently completed assignment or empty if none
-
findImmediateTasksForMember
Finds immediate tasks for a member (due within 2 days or with no due date). Results are ordered by status, completion date, and due date.- Parameters:
memberId- The ID of the member to find immediate tasks for- Returns:
- A list of immediate task assignments
-
deleteByMemberId
Deletes all task assignments for a specific member.- Parameters:
memberId- The ID of the member whose assignments should be deleted- Returns:
- The number of assignments deleted
-
deleteByTaskId
Deletes all assignments for a specific task.- Parameters:
taskId- The ID of the task whose assignments should be deleted- Returns:
- The number of assignments deleted
-
findByMemberIdAndDueAt
Finds task assignments for a specific member with a specific due date.- Parameters:
memberId- The ID of the member to find assignments fordueDate- The due date to filter by- Returns:
- A list of matching task assignments
-