Esempio n. 1
0
        public IActionResult EditDraftBlogPost(string name, Guid id, [FromBody] EditDraftBlogPostRequest editDraftBlogPostRequest)
        {
            var blog = BlogRepository.GetBlog(name);

            if (!Exists(blog))
            {
                return(NotFound());
            }

            var draftBlogPost = blog.DraftBlogPosts.FirstOrDefault(dp => dp.Id == id);

            if (!Exists(draftBlogPost))
            {
                return(NotFound());
            }

            if (!draftBlogPost.CanEditDraftBlogPost(editDraftBlogPostRequest.BloggerId))
            {
                return(Unauthorized());
            }

            draftBlogPost.Edit(editDraftBlogPostRequest.Title, editDraftBlogPostRequest.Content);
            //emit event

            return(Ok());
        }
Esempio n. 2
0
        public IActionResult GetBlog(string name)
        {
            var blog = BlogRepository.GetBlog(name);

            return(!Exists(blog)
                ? NotFound() as IActionResult
                : Ok(new { blogPosts = blog.BlogPosts, draftBlogPosts = blog.DraftBlogPosts }));
        }
Esempio n. 3
0
        public IActionResult PublishDraftBlogPost(string name, Guid id)
        {
            var blog = BlogRepository.GetBlog(name);

            if (!blog.CanPublishDraftBlogPost(id))
            {
                throw new DomainException($"Cannot publish draft blog post with id {id}");
            }

            blog.PublishDraftBlogPost(id);

            return(Ok());
        }
Esempio n. 4
0
        public IActionResult GetPost(string name, Guid id)
        {
            var blog = BlogRepository.GetBlog(name);

            if (!Exists(blog))
            {
                return(NotFound());
            }

            var blogPost = blog.BlogPosts.FirstOrDefault(bp => bp.Id == id);

            return(!Exists(blogPost)
                ? NotFound() as IActionResult
                : Ok(blogPost));
        }
Esempio n. 5
0
        public IActionResult CreateDraftBlogPost(string name, [FromBody] CreateBlogPostRequest createBlogPostRequest)
        {
            var blog = BlogRepository.GetBlog(name);

            if (!Exists(blog))
            {
                return(NotFound());
            }

            var draftBlogPost = new DraftBlogPost(Guid.NewGuid(), createBlogPostRequest.Title, createBlogPostRequest.Content, createBlogPostRequest.BloggerId, DateTimeOffset.Now);

            blog.AddDraftBlogPost(draftBlogPost);
            //emit event

            return(Ok());
        }