public async Task <ActionResult <PostImageDTO> > GetImage(int imageId) { var image = await _postImage.GetASpecificImage(imageId); if (image != null) { return(image); } return(BadRequest()); }
/// <summary> /// Gets a specific post from the database /// </summary> /// <param name="postId">The Id of the post</param> /// <returns>A single PostDTO</returns> public async Task <UserPostDTO> GetASpecificPost(int postId) { var post = await _context.UserPosts.Where(x => x.ID == postId) .FirstOrDefaultAsync(); var comments = new List <PostCommentDTO>(); if (post.PostComments != null) { foreach (var item in post.PostComments) { comments.Add(await _postComment.GetASpecificComment(item.CommentId)); } } var images = new List <PostImageDTO>(); if (post.PostImages != null) { foreach (var item in post.PostImages) { images.Add(await _postImage.GetASpecificImage(item.ImageId)); } } var postDTO = new UserPostDTO() { Id = post.ID, UserId = post.UserId, Caption = post.Caption, Created = post.Created, Modified = post.Modified, PostComments = comments, PostImages = images, PostLikes = await GetPostLikes(postId, post.UserId) }; return(postDTO); }