Example #1
0
        public async Task <IActionResult> Delete([FromRoute] Guid postId)
        {
            bool userOwnsPost = await _postService.UserOwnsPostAsync(postId, HttpContext.GetUserId());

            if (!userOwnsPost)
            {
                return(BadRequest(new { error = "You do not own this post" }));
            }

            var deleted = await _postService.DeletePostAsync(postId);

            if (deleted)
            {
                return(NoContent());
            }

            return(NotFound());
        }