Interface FriendshipRepository

All Superinterfaces:
org.springframework.data.repository.CrudRepository<Friendship,Integer>, org.springframework.data.jpa.repository.JpaRepository<Friendship,Integer>, org.springframework.data.repository.ListCrudRepository<Friendship,Integer>, org.springframework.data.repository.ListPagingAndSortingRepository<Friendship,Integer>, org.springframework.data.repository.PagingAndSortingRepository<Friendship,Integer>, org.springframework.data.repository.query.QueryByExampleExecutor<Friendship>, org.springframework.data.repository.Repository<Friendship,Integer>

@Repository public interface FriendshipRepository extends org.springframework.data.jpa.repository.JpaRepository<Friendship,Integer>
Spring Data JPA repository for Friendship entities.

Provides standard CRUD operations as well as custom query methods for retrieving, checking, and managing friendship relationships between athletes, including blocking functionality.

Author:
SportTrack Team
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    existsBlock(Athlete blocker, Athlete blocked)
    Checks whether a specific athlete has blocked another athlete (one-directional).
    Finds a friendship between two athletes, regardless of direction.
    Returns the identifiers of all users who have blocked the specified user.
    Returns the identifiers of all users that the specified user has blocked.
    Finds all friendships for a given athlete and status, regardless of direction.
    Finds all friendships in which the specified athlete is the initiator and the relationship has the given status.
    Finds all friendships in which the specified athlete is the recipient and the relationship has the given status.

    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

    findAll, 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

    • findBetweenAthletes

      @Query("SELECT f FROM Friendship f WHERE (f.initiator = :a AND f.recipient = :b) OR (f.initiator = :b AND f.recipient = :a)") Optional<Friendship> findBetweenAthletes(@Param("a") Athlete a, @Param("b") Athlete b)
      Finds a friendship between two athletes, regardless of direction. Returns the record if a relationship exists in either direction (initiator→recipient or recipient→initiator).
      Parameters:
      a - the first athlete
      b - the second athlete
      Returns:
      an Optional containing the friendship if found, empty otherwise
    • findByRecipientAndStatus

      List<Friendship> findByRecipientAndStatus(Athlete recipient, FriendshipStatus status)
      Finds all friendships in which the specified athlete is the recipient and the relationship has the given status.
      Parameters:
      recipient - the athlete who received the friendship request
      status - the status to filter by
      Returns:
      a list of matching friendships
    • findByInitiatorAndStatus

      List<Friendship> findByInitiatorAndStatus(Athlete initiator, FriendshipStatus status)
      Finds all friendships in which the specified athlete is the initiator and the relationship has the given status.
      Parameters:
      initiator - the athlete who sent the friendship request
      status - the status to filter by
      Returns:
      a list of matching friendships
    • findByAthleteAndStatus

      @Query("SELECT f FROM Friendship f WHERE (f.initiator.id = :athleteId OR f.recipient.id = :athleteId) AND f.status = :status") List<Friendship> findByAthleteAndStatus(@Param("athleteId") Integer athleteId, @Param("status") FriendshipStatus status)
      Finds all friendships for a given athlete and status, regardless of direction. Returns records where the athlete acts as either the initiator or the recipient.
      Parameters:
      athleteId - the unique identifier of the athlete
      status - the friendship status to filter by
      Returns:
      a list of matching friendship records
    • existsBlock

      @Query("SELECT CASE WHEN COUNT(f) > 0 THEN true ELSE false END FROM Friendship f WHERE f.initiator = :blocker AND f.recipient = :blocked AND f.status = \'BLOCKED\'") boolean existsBlock(@Param("blocker") Athlete blocker, @Param("blocked") Athlete blocked)
      Checks whether a specific athlete has blocked another athlete (one-directional).
      Parameters:
      blocker - the athlete who initiated the block
      blocked - the athlete who was blocked
      Returns:
      true if a BLOCKED relationship exists from blocker to blocked
    • findBlockedByUserIds

      @Query("SELECT f.initiator.id FROM Friendship f WHERE f.recipient.id = :userId AND f.status = \'BLOCKED\'") List<Integer> findBlockedByUserIds(@Param("userId") Integer userId)
      Returns the identifiers of all users who have blocked the specified user.
      Parameters:
      userId - the unique identifier of the potentially blocked user
      Returns:
      a list of athlete identifiers who have blocked the given user
    • findBlockedUserIds

      @Query("SELECT f.recipient.id FROM Friendship f WHERE f.initiator.id = :userId AND f.status = \'BLOCKED\'") List<Integer> findBlockedUserIds(@Param("userId") Integer userId)
      Returns the identifiers of all users that the specified user has blocked.
      Parameters:
      userId - the unique identifier of the blocking user
      Returns:
      a list of athlete identifiers who have been blocked by the given user