public async Task <IActionResult> StartPost([FromBody] NewPostViewModel postViewModel) { var startPostCommand = new StartPostCommand(postViewModel.Author, postViewModel.Title); await _mediator.Publish(startPostCommand, CancellationToken.None); return(Ok()); }
public void Given_BlogWithCategoriesWithTags_When_StartPostCommand_With_InvalidCategoryUrl_Then_CategoryDoesNotExistException(string host, string url, string title, string body, string publishAt, string categoryUrl, string categoryTitle, string tagUrl, string tagTitle, bool infobar, bool hidden, bool comments) { var command = new StartPostCommand(host, url, title, body, DateTime.Parse(publishAt), categoryUrl, new HashSet <string> { tagUrl }, infobar, hidden, comments); Given.DefaultBlog().WithCategories().WithTags() .Begin() .When(command) .ThenException <CategoryDoesNotExistException>() .End(); }
public async Task CreatePostAsync(PostDto post) { var cmd = new StartPostCommand(post.BlogId, post.Url, post.Title, post.Content, post.Publish, post.Category, new HashSet <string>(post.Tags), post.Infobar, post.Hidden, true); await _bus.SendAsync(cmd); }
public void Given_BlogWithCategoriesWithTags_When_StartPostCommand_With_ValidParams_Then_PostStartedEvent(string host, string url, string title, string body, string publishAt, string categoryUrl, string categoryTitle, string tagUrl, string tagTitle, bool inforbar, bool hidden, bool comments) { var command = new StartPostCommand(host, url, title, body, DateTime.Parse(publishAt), categoryUrl, new HashSet <string> { tagUrl }, inforbar, hidden, comments); var expectedEvent = new PostStartedEvent(host, url, title, body, DateTime.Parse(publishAt), categoryTitle, categoryUrl, new List <PostStartedEvent.PostStartedEventTag> { new PostStartedEvent.PostStartedEventTag(tagUrl, tagTitle) }, inforbar, hidden, comments); Given.DefaultBlog().WithCategories().WithTags() .Begin() .When(command) .Then(expectedEvent) .End(); }
public IEnumerable <Event> Handle(StartPostCommand message) { if (string.IsNullOrEmpty(message.Url)) { throw new InvalidPostUrlException($"The post's '{nameof(Post.Url)}' can not be null or empty string."); } if (string.IsNullOrEmpty(message.Title)) { throw new InvalidPostTitleException($"The post's '{nameof(Post.Title)}' can not be null or empty string."); } var category = _categories.GetCategory(message.CategoryUrl); if (category == null) { throw new CategoryDoesNotExistException($"Category '{message.CategoryUrl}' doesn't exist"); } if (category.Posts.Any(_ => string.Equals(_.Url, message.Url))) { throw new PostAlreadyExistsException($"The post '{message.Url}' you are trying to create already exists."); } Func <Tag, bool> tagsComparator = tag => message.TagUrls.Any(url => string.Equals(url, tag.Url)); var tags = _tags .Where(tagsComparator) .Select(_ => new PostStartedEvent.PostStartedEventTag(_.Url, _.Title)) .ToList(); yield return(new PostStartedEvent(message.AggregateId, message.Url, message.Title, message.Body, message.PublishAt, category.Title, message.CategoryUrl, tags, message.Infobar, message.Hidden, message.Comments)); }