public async Task <IActionResult> GetMessagesForUser(int userId, [FromQuery] MessageParams messageParams) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } messageParams.UserId = userId; var messagesFromRepo = await _repo.GetMessagesForUser(messageParams); var messages = _mapper.Map <IEnumerable <MessageToReturnDto> >(messagesFromRepo); Response.AddPagination(messagesFromRepo.CurrentPage, messagesFromRepo.PageSize, messagesFromRepo.TotalCount, messagesFromRepo.TotalPages); return(Ok(messages)); }