public async Task <IActionResult> DeclineRequest(Guid receiverId, Guid senderId, byte requestTypeId) { var tkn = Request.Headers["Authorization"]; if (!_authService.AuthorizeSelf(tkn, receiverId)) { return(Unauthorized()); } var request = await _requestsRepository.GetRequestByUserIdsAndType(receiverId, senderId, (RequestType)requestTypeId); if (request == null) { return(BadRequest(new Error("invalid_request", "There is no pending request."))); } await _requestsService.DeclineRequest(request); return(Ok()); }
public async Task <IList <Error> > ValidateAcceptRequest(Request request) { var errors = new List <Error>(); var req = await _requestsRepository.GetRequestByUserIdsAndType(request); if (req == null) { errors.Add(new Error("invalid_request", "There is no pending request.")); } switch (request.RequestType) { case RequestType.Friend: if (await _relationshipsService.AreAlreadyFriends(request.SenderId, request.ReceiverId)) { errors.Add(new Error("invalid_request", "You are already connected.")); } break; } return(errors); }
public async Task <bool> IsRequestAlreadySent(Request request) => await _requestsRepository.GetRequestByUserIdsAndType(request) != null;