Class MemberRepository

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

public class MemberRepository extends AbstractRepository<Profile,Long>
Repository for managing household members/user profiles. Provides methods for basic CRUD operations and specialized queries for finding members by name or task status.
  • Constructor Details

    • MemberRepository

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

    • findById

      public Optional<Profile> findById(Long id)
      Finds a member by their ID.
      Parameters:
      id - The member ID
      Returns:
      An Optional containing the found member or empty if not found
    • findByName

      public Optional<Profile> findByName(String name)
      Finds a member by their name.
      Parameters:
      name - The member name to search for
      Returns:
      An Optional containing the found member or empty if not found
    • findAll

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

      public Profile save(Profile member)
      Saves a member, updating if it exists or creating if it doesn't.
      Parameters:
      member - The member to save
      Returns:
      The saved member with ID populated
    • deleteById

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

      protected Profile mapRow(ResultSet rs) throws SQLException
      Maps a database result set row to a Profile object.
      Specified by:
      mapRow in class AbstractRepository<Profile,Long>
      Parameters:
      rs - The result set positioned at the row to map
      Returns:
      The mapped Profile object
      Throws:
      SQLException - If a database error occurs during mapping
    • findMembersWithPendingTasks

      public List<Profile> findMembersWithPendingTasks()
      Finds all members who have pending tasks (status = TODO).
      Returns:
      A list of members with pending tasks
    • findMembersWithCompletedTasks

      public List<Profile> findMembersWithCompletedTasks()
      Finds all members who have completed tasks (status = DONE).
      Returns:
      A list of members with completed tasks
    • findAllById

      public List<Profile> findAllById(List<Long> list)
      Finds members by multiple IDs in a single query. Optimized for bulk loading of member data.
      Parameters:
      list - A list of member IDs to find
      Returns:
      A list of members matching the provided IDs