Interface ChallengeRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<Challenge,,Integer> org.springframework.data.jpa.repository.JpaRepository<Challenge,,Integer> org.springframework.data.repository.ListCrudRepository<Challenge,,Integer> org.springframework.data.repository.ListPagingAndSortingRepository<Challenge,,Integer> org.springframework.data.repository.PagingAndSortingRepository<Challenge,,Integer> org.springframework.data.repository.query.QueryByExampleExecutor<Challenge>,org.springframework.data.repository.Repository<Challenge,Integer>
@Repository
public interface ChallengeRepository
extends org.springframework.data.jpa.repository.JpaRepository<Challenge,Integer>
Spring Data JPA repository for
Challenge entities.
Provides standard CRUD operations as well as custom query methods for retrieving challenges by organiser, participant, date range, and sport.
- Author:
- SportTrack Team
-
Method Summary
Modifier and TypeMethodDescriptionfindAll()Returns all challenges in the database.Finds all challenges whose end date is on or before the given date and for which no end notification has yet been sent.findById(int id) Finds a challenge by its identifier.findChallengesImpactedByActivity(Integer athleteId, Integer sportId, LocalDate activityDate) Finds all active challenges that are impacted by a newly created activity.findDistinctByOrganizer_IdOrParticipants_Id(int organizerId, int participantId) Finds all distinct challenges in which the given athlete is either the organiser or a participant.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne
-
Method Details
-
findDistinctByOrganizer_IdOrParticipants_Id
Finds all distinct challenges in which the given athlete is either the organiser or a participant.- Parameters:
organizerId- the identifier of the potential organiserparticipantId- the identifier of the potential participant- Returns:
- a list of matching challenges
-
findByEndDateLessThanEqualAndEndedNotifiedAtIsNull
Finds all challenges whose end date is on or before the given date and for which no end notification has yet been sent.- Parameters:
currentDate- the date to compare against challenge end dates- Returns:
- a list of ended but unnotified challenges
-
findChallengesImpactedByActivity
@Query("SELECT DISTINCT c\nFROM Challenge c\nJOIN c.participants p\nWHERE p.id = :athleteId\n AND c.sport.id = :sportId\n AND :activityDate BETWEEN c.startDate AND c.endDate\n") List<Challenge> findChallengesImpactedByActivity(@Param("athleteId") Integer athleteId, @Param("sportId") Integer sportId, @Param("activityDate") LocalDate activityDate) Finds all active challenges that are impacted by a newly created activity. A challenge is impacted if the athlete is a participant, the sport matches, and the activity date falls within the challenge date range.- Parameters:
athleteId- the identifier of the athlete who created the activitysportId- the identifier of the sport associated with the activityactivityDate- the date of the activity- Returns:
- a list of challenges affected by the new activity
-
findAll
Returns all challenges in the database. -
findById
Finds a challenge by its identifier.- Parameters:
id- the unique identifier of the challenge- Returns:
- an
Optionalcontaining the challenge if found, empty otherwise
-