public async Task <IActionResult> AddToPostAsync(int postId, IFormFile file) { ServiceResponse <PostDto> post = await _postService.GetPostByIdAsync(postId); if (post.Data is null) { return(NotFound()); } ServiceResponse <PictureDto> response = await _pictureService.AddPictureToPostAsync(postId, file); return(Ok(response)); }
public async Task <IActionResult> AddToPostAsync(int postId, IFormFile file) { var post = await _postService.GetPostByIdAsync(postId); if (post == null) { return(BadRequest(new Response(false, $"Post with id {postId} does not exist."))); } var userOwnsPost = await _postService.UserOwnsPostAsync(postId, User.FindFirstValue(ClaimTypes.NameIdentifier)); if (!userOwnsPost) { return(BadRequest(new Response(false, "You do not own this post."))); } var picture = await _pictureService.AddPictureToPostAsync(postId, file); return(Created($"api/pictures/{picture.ID}", new Response <PictureDto>(picture))); }