public async Task <IActionResult> UserTimeline(string username) { try { var author = await _userService.GetUserFromUsername(username); if (author == null) { return(NotFound()); } var includeFlaggedMessages = User.IsInRole(AuthRoles.Administrator); var messages = await _timelineService.GetMessagesForUser(author.Username, ResultsPerPage, includeFlaggedMessages); var isUserFollowing = await _userService.IsUserFollowing(User.GetUserID(), username); var mapped = messages.Select(message => new TimelineMessageVM( message.ID, new UserVM( message.Author.ID, message.Author.Username, message.Author.Email ), message.Text, message.PublishDate, message.IsFlagged )).ToList(); var vm = new UserTimelineVM( new UserVM( author.ID, author.Username, author.Email), isUserFollowing, mapped ); ViewData["title"] = $"{author.Username}'s Timeline"; return(View(nameof(UserTimeline), vm)); } catch (UnknownUserException e) { return(BadRequest(new ErrorResponse(e))); } }
public async Task <ActionResult <List <MessageResponse> > > GetMessagesFromUser(string username, [FromQuery] int no = 20) { try { var messages = await _timelineService.GetMessagesForUser(username, no, includeFlaggedMessages : false); return(Ok(messages.Select(msg => new MessageResponse { Content = msg.Text, PublishDate = msg.PublishDate, Author = msg.Author.Username }))); } catch (UnknownUserException e) { return(BadRequest(new ErrorResponse(e))); } }