Class TaskRepository

java.lang.Object
no.ntnu.principes.repository.AbstractRepository<Task,Long>
no.ntnu.principes.repository.TaskRepository
All Implemented Interfaces:
BaseRepository<Task,Long>

public class TaskRepository extends AbstractRepository<Task,Long>
Repository for managing household tasks. Handles task creation, updates, and queries with support for recurring tasks, difficulty weighting, and time estimates.
  • Constructor Details

    • TaskRepository

      public TaskRepository(DataSource dataSource)
      Creates a new TaskRepository with the specified data source.
      Parameters:
      dataSource - The JDBC data source for database connections
  • Method Details

    • findById

      public Optional<Task> findById(Long id)
      Finds a task by its ID.
      Parameters:
      id - The task ID
      Returns:
      An Optional containing the found task or empty if not found
    • findAll

      public List<Task> findAll()
      Retrieves all tasks.
      Returns:
      A list of all tasks
    • save

      public Task save(Task task)
      Saves a task, creating a new record or updating an existing one. Converts enum values (WorkWeight, TimeWeight) to their numeric representations.
      Parameters:
      task - The task to save
      Returns:
      The saved task with ID populated
    • deleteById

      public void deleteById(Long id)
      Deletes a task by its ID.
      Parameters:
      id - The ID of the task to delete
    • mapRow

      protected Task mapRow(ResultSet rs) throws SQLException
      Maps a database result set row to a Task object. Converts numeric weight values to their enum representations.
      Specified by:
      mapRow in class AbstractRepository<Task,Long>
      Parameters:
      rs - The result set positioned at the row to map
      Returns:
      The mapped Task object
      Throws:
      SQLException - If a database error occurs during mapping
    • findTasksByMember

      public List<Task> findTasksByMember(Long memberId)
      Finds all tasks assigned to a specific member.
      Parameters:
      memberId - The ID of the member to find tasks for
      Returns:
      A list of tasks assigned to the member
    • findRecurringTasks

      public List<Task> findRecurringTasks()
      Finds all recurring tasks.
      Returns:
      A list of tasks with recurring flag set to true
    • findByIds

      public List<Task> findByIds(List<Long> list)
      Finds tasks by multiple IDs in a single query.
      Parameters:
      list - A list of task IDs to find
      Returns:
      A list of tasks matching the provided IDs
    • findUnassignedTasks

      public List<Task> findUnassignedTasks()
    • count

      public int count()