java.lang.Object
no.ntnu.principes.repository.AbstractRepository<Points,Long>
no.ntnu.principes.repository.PointsRepository
- All Implemented Interfaces:
BaseRepository<Points,Long>
Repository for managing household member points.
Stores and retrieves points earned by members for completing tasks,
with methods for calculating totals, generating leaderboards, and filtering by time periods.
-
Field Summary
Fields inherited from class no.ntnu.principes.repository.AbstractRepository
dataSource, tableName -
Constructor Summary
ConstructorsConstructorDescriptionPointsRepository(DataSource dataSource) Creates a new PointsRepository with the specified data source. -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateIfNotExist(Points awardedPoints) Creates a points record if one doesn't exist for the member-task combination, or adds to the existing value if it does exist.voiddeleteById(Long id) Deletes points by their ID.intdeleteByMemberId(Long memberId) Deletes all points associated with a specific member.intdeleteByTaskId(Long taskId) Deletes all points associated with a specific task's assignments.findAll()Retrieves all points records.Finds points by their ID.findByMemberId(Long memberId) Finds all points earned by a specific member, ordered by most recent first.intgetTotalPointsForMember(Long memberId) Calculates the total points earned by a specific member.protected PointsMaps a database result set row to a Points object.Saves points, creating a new record if it doesn't exist.Methods inherited from class no.ntnu.principes.repository.AbstractRepository
executeInsert, executeUpdate, queryList, queryListRaw, queryListRaw, queryOne, queryOneRaw, queryOneRaw
-
Constructor Details
-
PointsRepository
Creates a new PointsRepository with the specified data source.- Parameters:
dataSource- The JDBC data source for database connections
-
-
Method Details
-
findById
Finds points by their ID.- Parameters:
id- The points ID- Returns:
- An Optional containing the found points or empty if not found
-
findAll
Retrieves all points records.- Returns:
- A list of all points records
-
save
Saves points, creating a new record if it doesn't exist. Update functionality is not implemented as points are typically immutable once created.- Parameters:
points- The points to save- Returns:
- The saved points with ID populated
-
deleteById
Deletes points by their ID.- Parameters:
id- The ID of the points to delete
-
mapRow
Maps a database result set row to a Points object.- Specified by:
mapRowin classAbstractRepository<Points,Long> - Parameters:
rs- The result set positioned at the row to map- Returns:
- The mapped Points object
- Throws:
SQLException- If a database error occurs during mapping
-
getTotalPointsForMember
Calculates the total points earned by a specific member. Returns 0 if the member has no points or if an error occurs.- Parameters:
memberId- The ID of the member to total points for- Returns:
- The sum of all points earned by the member
-
findByMemberId
Finds all points earned by a specific member, ordered by most recent first.- Parameters:
memberId- The ID of the member to find points for- Returns:
- A list of points earned by the member
-
createIfNotExist
Creates a points record if one doesn't exist for the member-task combination, or adds to the existing value if it does exist. Uses the database's ON CONFLICT clause for atomic upsert.- Parameters:
awardedPoints- The points to create or update
-
deleteByMemberId
Deletes all points associated with a specific member.- Parameters:
memberId- The ID of the member whose points should be deleted- Returns:
- The number of points records deleted
-
deleteByTaskId
Deletes all points associated with a specific task's assignments.- Parameters:
taskId- The ID of the task whose points should be deleted- Returns:
- The number of points records deleted
-