Class FriendshipService
java.lang.Object
fr.utc.miage.sporttrack.service.user.communication.FriendshipService
Service layer component responsible for managing
Friendship relationships
between athletes within the SportTrack application.
Provides business logic for sending, accepting, and rejecting friend requests, blocking and unblocking users, querying friends and blocked users, and determining the relationship status between two athletes.
- Author:
- SportTrack Team
-
Constructor Summary
ConstructorsConstructorDescriptionFriendshipService(FriendshipRepository friendshipRepository, AthleteRepository athleteRepository) Constructs aFriendshipServicewithout notification support.FriendshipService(FriendshipRepository friendshipRepository, AthleteRepository athleteRepository, NotificationService notificationService) Constructs aFriendshipServicewith full notification support. -
Method Summary
Modifier and TypeMethodDescriptionvoidacceptFriendRequest(Integer friendshipId, Integer currentUserId) Accept a pending friend request.voidBlocks a user.getBlockedUsers(Integer athleteId) Returns all users blocked by the given athlete.getFriendsOfAthlete(Integer athleteId) Returns a list of all accepted friends for a specific athlete.getPendingRequestsForAthlete(Integer athleteId) Returns all pending friend requests waiting for the athlete to accept.getRelationshipStatus(Integer viewerId, Integer targetId) Computes the relationship status from the perspective of viewerId looking at targetId.getSentPendingRequests(Integer athleteId) Returns all friend requests sent by the athlete that are still pending.voidrejectFriendRequest(Integer friendshipId, Integer currentUserId) Rejects a pending friend request.voidremoveFriend(Integer currentUserId, Integer otherUserId) Removes an established friendship between two users.searchVisibleAthletes(Integer currentUserId, String keyword) Searches for athletes visible to the current user.voidsendFriendRequest(Integer initiatorId, Integer recipientId) Sends a friend request from one user to another.voidunblockUser(Integer blockerId, Integer blockedId) Unblocks a previously blocked user.
-
Constructor Details
-
FriendshipService
public FriendshipService(FriendshipRepository friendshipRepository, AthleteRepository athleteRepository) Constructs aFriendshipServicewithout notification support.- Parameters:
friendshipRepository- the friendship repositoryathleteRepository- the athlete repository
-
FriendshipService
@Autowired public FriendshipService(FriendshipRepository friendshipRepository, AthleteRepository athleteRepository, NotificationService notificationService) Constructs aFriendshipServicewith full notification support.- Parameters:
friendshipRepository- the friendship repositoryathleteRepository- the athlete repositorynotificationService- the notification service for friendship events
-
-
Method Details
-
sendFriendRequest
Sends a friend request from one user to another. Checks for block relationships before allowing the request. -
acceptFriendRequest
Accept a pending friend request. -
rejectFriendRequest
Rejects a pending friend request. -
removeFriend
Removes an established friendship between two users. -
blockUser
Blocks a user. Handles all existing relationship states: - If already friends: removes friendship and blocks. - If pending request: cancels it and blocks. - If rejected: blocks. - If already blocked by blocker: throws exception. - If no relationship: creates a new BLOCKED record.- Parameters:
blockerId- the user performing the blockblockedId- the user being blocked
-
unblockUser
Unblocks a previously blocked user. Only the user who initiated the block can unblock.- Parameters:
blockerId- the user who performed the blockblockedId- the user to unblock
-
getFriendsOfAthlete
Returns a list of all accepted friends for a specific athlete. -
getPendingRequestsForAthlete
Returns all pending friend requests waiting for the athlete to accept. -
getSentPendingRequests
Returns all friend requests sent by the athlete that are still pending. -
getBlockedUsers
Returns all users blocked by the given athlete. -
getRelationshipStatus
Computes the relationship status from the perspective of viewerId looking at targetId. Returns a RelationshipStatusDTO that the frontend can use to determine button display.- Parameters:
viewerId- the current usertargetId- the user being viewed- Returns:
- the computed relationship status
-
searchVisibleAthletes
Searches for athletes visible to the current user. Filters out: - The current user themselves - Users the current user has blocked - Users who have blocked the current user- Parameters:
currentUserId- the ID of the user performing the searchkeyword- the search keyword (username)- Returns:
- list of visible athletes matching the keyword
-