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 messageFromRepo = await _repo.GetMessagesForUser(messageParams); var messages = _mapper.Map <IEnumerable <MessageToReturnDto> >(messageFromRepo); Response.AddPagination(messageFromRepo.CurrentPage, messageFromRepo.PageSize, messageFromRepo.TotalCount, messageFromRepo.TotalPages); return(Ok(messages)); }