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 Type
    Method
    Description
    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, save

    Methods inherited from interface org.springframework.data.jpa.repository.JpaRepository

    deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlush

    Methods inherited from interface org.springframework.data.repository.ListCrudRepository

    findAllById, saveAll

    Methods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor

    count, exists, findAll, findBy, findOne
  • Method Details

    • findDistinctByOrganizer_IdOrParticipants_Id

      List<Challenge> findDistinctByOrganizer_IdOrParticipants_Id(int organizerId, int participantId)
      Finds all distinct challenges in which the given athlete is either the organiser or a participant.
      Parameters:
      organizerId - the identifier of the potential organiser
      participantId - the identifier of the potential participant
      Returns:
      a list of matching challenges
    • findByEndDateLessThanEqualAndEndedNotifiedAtIsNull

      List<Challenge> findByEndDateLessThanEqualAndEndedNotifiedAtIsNull(LocalDate currentDate)
      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 activity
      sportId - the identifier of the sport associated with the activity
      activityDate - the date of the activity
      Returns:
      a list of challenges affected by the new activity
    • findAll

      List<Challenge> findAll()
      Returns all challenges in the database.
      Specified by:
      findAll in interface org.springframework.data.repository.CrudRepository<Challenge,Integer>
      Specified by:
      findAll in interface org.springframework.data.repository.ListCrudRepository<Challenge,Integer>
      Returns:
      a list of all challenges
    • findById

      Optional<Challenge> findById(int id)
      Finds a challenge by its identifier.
      Parameters:
      id - the unique identifier of the challenge
      Returns:
      an Optional containing the challenge if found, empty otherwise