Package restapi.services
Class MatchRequestService
java.lang.Object
restapi.services.MatchRequestService
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate @NonNull DateService
private @NonNull MatchRequestRepository
private @NonNull UserService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionacceptMatchRequest
(long matchId, long userId) Accepts match request if userId is receivervoid
addNewMatchRequest
(long userId, MatchEntity matchEntity) Creates new MatchRequestEntity with sender userId, receiver other user in matchEntity, and matchEntity's id and saves it to database.cancelMatchRequest
(long matchId, long userId) Cancels match request if userId is senderprivate List<MatchRequestEntity>
filterOld
(List<MatchRequestEntity> matches) Returns a list with all the matches more recent than 60 min from the lis passed by parametergetAcceptedMatchRequests
(long userId) Returns list of accepted matches for user whit userIdgetByMatchId
(long matchId) Get MatchRequestEntity By Match IdgetDtoFromEntityAndSenderId
(MatchRequestEntity matchRequest, long userId) Translates MatchRequestEntity to MatchRequestDTO with userId as contact (not user)getDtoFromEntityAndUserId
(MatchRequestEntity matchRequest, long userId) Translates MatchRequestEntity to MatchRequestDTO with userId as user (not contact)getDtoFromMatchEntityAndSenderId
(MatchEntity match, long userId, String state) Constructs MatchRequestDTO with matchId from match, contact = user in match with id == userId, and state == stategetDtoFromMatchEntityAndUserId
(MatchEntity match, long userId, String state) Constructs MatchRequestDTO with matchId from match, contact = user in match id !Translates MatchRequestEntity into MatchRequestDTO with user == receiver and contact == sendergetIamSenderActiveMatchRequests
(long userId) Returns a list of matches that have user as sender and are activeTranslates MatchRequestEntity into MatchRequestDTO with user == sender and contact == receivergetIamSenderMatchRequests
(long userId) Returns a list of matches that have user as sendergetMatchRequests
(long userId) Get match request the user is in (as sender or receiver)getReceivedActiveMatchRequests
(long userId) Returns a list of matches that have user as receiver and are activegetReceivedMatchRequests
(long userId) Returns a list of matches that have user as receiver
-
Field Details
-
dateService
-
matchRequestRepository
-
userService
-
-
Constructor Details
-
MatchRequestService
public MatchRequestService()
-
-
Method Details
-
addNewMatchRequest
Creates new MatchRequestEntity with sender userId, receiver other user in matchEntity, and matchEntity's id and saves it to database.- Parameters:
userId
- sendermatchEntity
- match info related to connection- Throws:
CustomConflictException
- when there is already an ongoing request with this match
-
getMatchRequests
Get match request the user is in (as sender or receiver)- Parameters:
userId
-- Returns:
-
filterOld
Returns a list with all the matches more recent than 60 min from the lis passed by parameter- Parameters:
matches
-- Returns:
-
getIamSenderMatchRequests
Returns a list of matches that have user as sender- Parameters:
userId
-- Returns:
-
getReceivedMatchRequests
Returns a list of matches that have user as receiver- Parameters:
userId
-- Returns:
-
getIamSenderActiveMatchRequests
Returns a list of matches that have user as sender and are active- Parameters:
userId
-- Returns:
-
getReceivedActiveMatchRequests
Returns a list of matches that have user as receiver and are active- Parameters:
userId
-- Returns:
-
getIamSenderDtoFromEntity
public MatchRequestDTO getIamSenderDtoFromEntity(MatchRequestEntity entity) throws CustomNotFoundException Translates MatchRequestEntity into MatchRequestDTO with user == sender and contact == receiver- Parameters:
entity
-- Returns:
- Throws:
CustomNotFoundException
-
getIamReceiverDtoFromEntity
public MatchRequestDTO getIamReceiverDtoFromEntity(MatchRequestEntity entity) throws CustomNotFoundException Translates MatchRequestEntity into MatchRequestDTO with user == receiver and contact == sender- Parameters:
entity
-- Returns:
- Throws:
CustomNotFoundException
-
getDtoFromMatchEntityAndUserId
public MatchRequestDTO getDtoFromMatchEntityAndUserId(MatchEntity match, long userId, String state) throws CustomNotFoundException Constructs MatchRequestDTO with matchId from match, contact = user in match id != userId, and state == state- Parameters:
match
-userId
-state
-- Returns:
- Throws:
CustomNotFoundException
-
getDtoFromMatchEntityAndSenderId
public MatchRequestDTO getDtoFromMatchEntityAndSenderId(MatchEntity match, long userId, String state) throws CustomNotFoundException Constructs MatchRequestDTO with matchId from match, contact = user in match with id == userId, and state == state- Parameters:
match
-userId
-state
-- Returns:
- Throws:
CustomNotFoundException
-
getDtoFromEntityAndUserId
public MatchRequestDTO getDtoFromEntityAndUserId(MatchRequestEntity matchRequest, long userId) throws CustomNotFoundException Translates MatchRequestEntity to MatchRequestDTO with userId as user (not contact)- Parameters:
matchRequest
-userId
-- Returns:
- Throws:
CustomNotFoundException
-
getDtoFromEntityAndSenderId
public MatchRequestDTO getDtoFromEntityAndSenderId(MatchRequestEntity matchRequest, long userId) throws CustomNotFoundException Translates MatchRequestEntity to MatchRequestDTO with userId as contact (not user)- Parameters:
matchRequest
-userId
-- Returns:
- Throws:
CustomNotFoundException
-
getAcceptedMatchRequests
Returns list of accepted matches for user whit userId- Parameters:
userId
-- Returns:
-
getByMatchId
Get MatchRequestEntity By Match Id- Parameters:
matchId
-- Returns:
- Throws:
CustomNotFoundException
-
acceptMatchRequest
public MatchRequestEntity acceptMatchRequest(long matchId, long userId) throws CustomNotFoundException, CustomConflictException Accepts match request if userId is receiver- Parameters:
matchId
-userId
-- Returns:
- Throws:
CustomNotFoundException
CustomConflictException
-
cancelMatchRequest
public MatchRequestEntity cancelMatchRequest(long matchId, long userId) throws CustomNotFoundException, CustomConflictException Cancels match request if userId is sender- Parameters:
matchId
-userId
-- Returns:
- Throws:
CustomNotFoundException
CustomConflictException
-