diff --git a/docs/DDD/1010287.jpeg b/docs/DDD/1010287.jpeg deleted file mode 100644 index 50767e4..0000000 Binary files a/docs/DDD/1010287.jpeg and /dev/null differ diff --git a/docs/DDD/4aab5983bfbfabbcfcd3bb81566f19a6.jpg b/docs/DDD/4aab5983bfbfabbcfcd3bb81566f19a6.jpg deleted file mode 100644 index 33274e9..0000000 Binary files a/docs/DDD/4aab5983bfbfabbcfcd3bb81566f19a6.jpg and /dev/null differ diff --git a/docs/DDD/5146azDZjmL._SX358_BO1,204,203,200_.jpg b/docs/DDD/5146azDZjmL._SX358_BO1,204,203,200_.jpg deleted file mode 100644 index fb020ee..0000000 Binary files a/docs/DDD/5146azDZjmL._SX358_BO1,204,203,200_.jpg and /dev/null differ diff --git a/docs/DDD/51eO0EhGY3L._SX387_BO1,204,203,200_.jpg b/docs/DDD/51eO0EhGY3L._SX387_BO1,204,203,200_.jpg deleted file mode 100644 index 1457b85..0000000 Binary files a/docs/DDD/51eO0EhGY3L._SX387_BO1,204,203,200_.jpg and /dev/null differ diff --git a/docs/DDD/51sZW87slRL._SX375_BO1,204,203,200_.jpg b/docs/DDD/51sZW87slRL._SX375_BO1,204,203,200_.jpg deleted file mode 100644 index d0963b4..0000000 Binary files a/docs/DDD/51sZW87slRL._SX375_BO1,204,203,200_.jpg and /dev/null differ diff --git a/docs/DDD/93fedb8843bfba9058dcf0451c7b6640.jpg b/docs/DDD/93fedb8843bfba9058dcf0451c7b6640.jpg deleted file mode 100644 index bf2e549..0000000 Binary files a/docs/DDD/93fedb8843bfba9058dcf0451c7b6640.jpg and /dev/null differ diff --git a/docs/DDD/DEV-B211.pptx b/docs/DDD/DEV-B211.pptx deleted file mode 100644 index db36494..0000000 Binary files a/docs/DDD/DEV-B211.pptx and /dev/null differ diff --git a/docs/DDD/SpringOne2016-ChrisRichardson-Developingmicroserviceswithaggregates.pdf b/docs/DDD/SpringOne2016-ChrisRichardson-Developingmicroserviceswithaggregates.pdf deleted file mode 100644 index a47322b..0000000 Binary files a/docs/DDD/SpringOne2016-ChrisRichardson-Developingmicroserviceswithaggregates.pdf and /dev/null differ diff --git a/docs/DDD/boundex-context.png b/docs/DDD/boundex-context.png deleted file mode 100644 index 0f28186..0000000 Binary files a/docs/DDD/boundex-context.png and /dev/null differ diff --git a/docs/DDD/brick_wall-wallpaper-1920x1080.jpg b/docs/DDD/brick_wall-wallpaper-1920x1080.jpg deleted file mode 100644 index 955349b..0000000 Binary files a/docs/DDD/brick_wall-wallpaper-1920x1080.jpg and /dev/null differ diff --git a/docs/DDD/ebook_arch_dev_microservices_containers_cover.png b/docs/DDD/ebook_arch_dev_microservices_containers_cover.png deleted file mode 100644 index 3677daf..0000000 Binary files a/docs/DDD/ebook_arch_dev_microservices_containers_cover.png and /dev/null differ diff --git a/docs/DDD/eshop-webspa-app-screenshot.png b/docs/DDD/eshop-webspa-app-screenshot.png deleted file mode 100644 index 854c5e8..0000000 Binary files a/docs/DDD/eshop-webspa-app-screenshot.png and /dev/null differ diff --git a/docs/Microserviços/colmeia.jpeg b/docs/Microserviços/colmeia.jpeg deleted file mode 100644 index 029940d..0000000 Binary files a/docs/Microserviços/colmeia.jpeg and /dev/null differ diff --git a/docs/SOLID/196ocp.pdf b/docs/SOLID/196ocp.pdf deleted file mode 100644 index aebd897..0000000 Binary files a/docs/SOLID/196ocp.pdf and /dev/null differ diff --git a/docs/SOLID/396lsp.pdf b/docs/SOLID/396lsp.pdf deleted file mode 100644 index 18ce1fd..0000000 Binary files a/docs/SOLID/396lsp.pdf and /dev/null differ diff --git a/docs/SOLID/496991d1590f2434aa11275c5a78a0fd.jpg b/docs/SOLID/496991d1590f2434aa11275c5a78a0fd.jpg deleted file mode 100644 index ac3d31f..0000000 Binary files a/docs/SOLID/496991d1590f2434aa11275c5a78a0fd.jpg and /dev/null differ diff --git a/docs/SOLID/596dip.pdf b/docs/SOLID/596dip.pdf deleted file mode 100644 index 6fd8a1f..0000000 Binary files a/docs/SOLID/596dip.pdf and /dev/null differ diff --git a/docs/SOLID/896isp.pdf b/docs/SOLID/896isp.pdf deleted file mode 100644 index f4c986d..0000000 Binary files a/docs/SOLID/896isp.pdf and /dev/null differ diff --git a/docs/SOLID/Artist-Hangout-Steel-03-by-wallpaperbeta.com_.jpg b/docs/SOLID/Artist-Hangout-Steel-03-by-wallpaperbeta.com_.jpg deleted file mode 100644 index 37da7ec..0000000 Binary files a/docs/SOLID/Artist-Hangout-Steel-03-by-wallpaperbeta.com_.jpg and /dev/null differ diff --git a/docs/SOLID/Black-Grated-iron-background.jpg b/docs/SOLID/Black-Grated-iron-background.jpg deleted file mode 100644 index ea3cf92..0000000 Binary files a/docs/SOLID/Black-Grated-iron-background.jpg and /dev/null differ diff --git a/docs/SOLID/DIP.cs b/docs/SOLID/DIP.cs deleted file mode 100644 index 0afe19f..0000000 --- a/docs/SOLID/DIP.cs +++ /dev/null @@ -1,45 +0,0 @@ -public void CheckOut() -{ - MailMessage myMessage = new MailMessage( - "loja@minhaloja.com", - "usuario@minhaloja.com", - "Seu pedido foi recebido.", - "Obrigado!"); - - SmtpClient smptClient = new SmtpClient("localhost"); - smtpClient.Send(myMessage); -} - -public interface ISendEmail -{ - void SendMail(string to, string from, string subject, string body); -} - -public class LiveSmtpMailer : ISendEmail -{ - void SendMail(string to, string from, string subject, string body) - { - MailMessage myMessage = new MailMessage(from, to, subject, body); - SmtpClient smptClient = new SmtpClient("localhost"); - smtpClient.Send(myMessage); - } -} - -public class Cart -{ - private ISendEmail _emailProvider; - - public Cart(ISendEmail emailProvider) - { - _emailProvider = emailProvider; - } - - public void Checkout() - { - this.emailProvider.SendMail( - "loja@minhaloja.com", - "usuario@minhaloja.com", - "Seu pedido foi recebido.", - "Obrigado!"); - } -} \ No newline at end of file diff --git a/docs/SOLID/Download Black Metal Steel Texture Resolution Wallpaper 1400x1050 ....jpg b/docs/SOLID/Download Black Metal Steel Texture Resolution Wallpaper 1400x1050 ....jpg deleted file mode 100644 index e8c69a2..0000000 Binary files a/docs/SOLID/Download Black Metal Steel Texture Resolution Wallpaper 1400x1050 ....jpg and /dev/null differ diff --git a/docs/SOLID/ISP.cs b/docs/SOLID/ISP.cs deleted file mode 100644 index cae1de5..0000000 --- a/docs/SOLID/ISP.cs +++ /dev/null @@ -1,8 +0,0 @@ -public IRepository -{ - T GetById(int id); - IEnumerable List(); - void Create(T item); - void Update(T item); - void Delete(T item); -} \ No newline at end of file diff --git a/docs/SOLID/LSPSmell.cs b/docs/SOLID/LSPSmell.cs deleted file mode 100644 index e69de29..0000000 diff --git a/docs/SOLID/Metal-and-Iron-Background-51.jpg b/docs/SOLID/Metal-and-Iron-Background-51.jpg deleted file mode 100644 index 7f6452b..0000000 Binary files a/docs/SOLID/Metal-and-Iron-Background-51.jpg and /dev/null differ diff --git a/docs/SOLID/Modem.cs b/docs/SOLID/Modem.cs deleted file mode 100644 index 6952573..0000000 --- a/docs/SOLID/Modem.cs +++ /dev/null @@ -1,7 +0,0 @@ -public interface Modem -{ - public void Dial(string pno); - public void Hangup(); - public void Send(char c); - public char Recv(); -} \ No newline at end of file diff --git a/docs/SOLID/SRP.pdf b/docs/SOLID/SRP.pdf deleted file mode 100644 index 300da87..0000000 Binary files a/docs/SOLID/SRP.pdf and /dev/null differ diff --git a/docs/SOLID/SRP.vsdx b/docs/SOLID/SRP.vsdx deleted file mode 100644 index 2b6c893..0000000 Binary files a/docs/SOLID/SRP.vsdx and /dev/null differ diff --git a/docs/SOLID/SsBlBVu.jpg b/docs/SOLID/SsBlBVu.jpg deleted file mode 100644 index b3e2e85..0000000 Binary files a/docs/SOLID/SsBlBVu.jpg and /dev/null differ diff --git a/docs/SOLID/Steel-Background.jpg b/docs/SOLID/Steel-Background.jpg deleted file mode 100644 index 10be345..0000000 Binary files a/docs/SOLID/Steel-Background.jpg and /dev/null differ diff --git a/docs/SOLID/black_background_metal-wallpaper-1920x1080.jpg b/docs/SOLID/black_background_metal-wallpaper-1920x1080.jpg deleted file mode 100644 index 789ef8f..0000000 Binary files a/docs/SOLID/black_background_metal-wallpaper-1920x1080.jpg and /dev/null differ diff --git a/docs/SOLID/dark brushed metal texture steel black stock photo scratch wallpaper.jpg b/docs/SOLID/dark brushed metal texture steel black stock photo scratch wallpaper.jpg deleted file mode 100644 index 70046df..0000000 Binary files a/docs/SOLID/dark brushed metal texture steel black stock photo scratch wallpaper.jpg and /dev/null differ diff --git a/docs/SOLID/designStaminaGraph.gif b/docs/SOLID/designStaminaGraph.gif deleted file mode 100644 index 8c7231b..0000000 Binary files a/docs/SOLID/designStaminaGraph.gif and /dev/null differ diff --git a/docs/SOLID/welcome to parsons steel company profile steel fabrication steel ....jpg b/docs/SOLID/welcome to parsons steel company profile steel fabrication steel ....jpg deleted file mode 100644 index 596204d..0000000 Binary files a/docs/SOLID/welcome to parsons steel company profile steel fabrication steel ....jpg and /dev/null differ diff --git a/source/Jambo.API.IoC/ApplicationModule.cs b/source/Jambo.API.IoC/ApplicationModule.cs index b0c4896..e28c9cc 100644 --- a/source/Jambo.API.IoC/ApplicationModule.cs +++ b/source/Jambo.API.IoC/ApplicationModule.cs @@ -26,7 +26,7 @@ namespace Jambo.API.IoC .As().SingleInstance(); builder.RegisterType() - .As() + .As() .InstancePerLifetimeScope(); builder.RegisterType() diff --git a/source/Jambo.API/Controllers/BlogsController.cs b/source/Jambo.API/Controllers/BlogsController.cs index c143eba..58ff618 100644 --- a/source/Jambo.API/Controllers/BlogsController.cs +++ b/source/Jambo.API/Controllers/BlogsController.cs @@ -56,7 +56,7 @@ namespace Jambo.API.Controllers } [HttpPatch("Enable")] - public async Task Enable([FromBody]UpdateBlogUrlCommand command) + public async Task Enable([FromBody]EnableBlogCommand command) { await _mediator.Send(command); return (IActionResult)Ok(); diff --git a/source/Jambo.API/Controllers/PostsController.cs b/source/Jambo.API/Controllers/PostsController.cs index b556ca3..cd6cb1f 100644 --- a/source/Jambo.API/Controllers/PostsController.cs +++ b/source/Jambo.API/Controllers/PostsController.cs @@ -32,7 +32,7 @@ namespace Jambo.API.Controllers return Ok(blogs); } - [HttpGet("{id}")] + [HttpGet("{id}", Name = "GetPost")] public async Task Get(Guid id) { try @@ -52,9 +52,22 @@ namespace Jambo.API.Controllers { Guid id = await _mediator.Send(command); - return CreatedAtRoute("Get", new { id = id }, id); + return CreatedAtRoute("GetPost", new { id = id }, id); } + [HttpPatch("Enable")] + public async Task Enable([FromBody]EnablePostCommand command) + { + await _mediator.Send(command); + return (IActionResult)Ok(); + } + + [HttpPatch("Disable")] + public async Task Disable([FromBody]DisablePostCommand command) + { + await _mediator.Send(command); + return (IActionResult)Ok(); + } [HttpPatch("Publish")] public async Task Publish([FromBody]PublishPostCommand command) @@ -71,7 +84,7 @@ namespace Jambo.API.Controllers } [HttpPatch("UpdateContent")] - public async Task UpdateContent([FromBody]UpdateContentCommand command) + public async Task UpdateContent([FromBody]UpdatePostContentCommand command) { await _mediator.Send(command); return (IActionResult)Ok(); diff --git a/source/Jambo.Application/CommandHandlers/CriarBlogCommandHandler.cs b/source/Jambo.Application/CommandHandlers/Blogs/CreateBlogCommandHandler.cs similarity index 76% rename from source/Jambo.Application/CommandHandlers/CriarBlogCommandHandler.cs rename to source/Jambo.Application/CommandHandlers/Blogs/CreateBlogCommandHandler.cs index f6fceb5..d860b74 100644 --- a/source/Jambo.Application/CommandHandlers/CriarBlogCommandHandler.cs +++ b/source/Jambo.Application/CommandHandlers/Blogs/CreateBlogCommandHandler.cs @@ -6,13 +6,13 @@ using MediatR; using System; using System.Threading.Tasks; -namespace Jambo.Application.CommandHandlers +namespace Jambo.Application.CommandHandlers.Blogs { - public class CriarBlogCommandHandler : IAsyncRequestHandler + public class CreatePostCommandHandler : IAsyncRequestHandler { private readonly IServiceBus _serviceBus; - public CriarBlogCommandHandler(IServiceBus serviceBus) + public CreatePostCommandHandler(IServiceBus serviceBus) { _serviceBus = serviceBus ?? throw new ArgumentNullException(nameof(serviceBus)); diff --git a/source/Jambo.Application/CommandHandlers/ExcluirBlogCommandHandler.cs b/source/Jambo.Application/CommandHandlers/Blogs/DisableBlogCommandHandler.cs similarity index 83% rename from source/Jambo.Application/CommandHandlers/ExcluirBlogCommandHandler.cs rename to source/Jambo.Application/CommandHandlers/Blogs/DisableBlogCommandHandler.cs index 8ffbb53..1501410 100644 --- a/source/Jambo.Application/CommandHandlers/ExcluirBlogCommandHandler.cs +++ b/source/Jambo.Application/CommandHandlers/Blogs/DisableBlogCommandHandler.cs @@ -1,19 +1,20 @@ using Jambo.Application.Commands; using Jambo.Application.Commands.Blogs; using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Posts; using Jambo.Domain.ServiceBus; using MediatR; using System; using System.Threading.Tasks; -namespace Jambo.Application.CommandHandlers +namespace Jambo.Application.CommandHandlers.Blogs { - public class ExcluirBlogCommandHandler : IAsyncRequestHandler + public class DisableBlogCommandHandler : IAsyncRequestHandler { private readonly IServiceBus _serviceBus; private readonly IBlogReadOnlyRepository _blogReadOnlyRepository; - public ExcluirBlogCommandHandler( + public DisableBlogCommandHandler( IServiceBus serviceBus, IBlogReadOnlyRepository blogReadOnlyRepository) { @@ -26,7 +27,6 @@ namespace Jambo.Application.CommandHandlers public async Task Handle(DisableBlogCommand message) { Blog blog = await _blogReadOnlyRepository.GetBlog(message.Id); - blog.Disable(); await _serviceBus.Publish(blog.GetEvents()); diff --git a/source/Jambo.Application/CommandHandlers/Blogs/EnableBlogCommandHandler.cs b/source/Jambo.Application/CommandHandlers/Blogs/EnableBlogCommandHandler.cs new file mode 100644 index 0000000..026742c --- /dev/null +++ b/source/Jambo.Application/CommandHandlers/Blogs/EnableBlogCommandHandler.cs @@ -0,0 +1,36 @@ +using MediatR; +using System; +using System.Threading.Tasks; +using Jambo.Application.Commands; +using Jambo.Domain.ServiceBus; +using Jambo.Domain.Aggregates.Blogs; +using Jambo.Application.Commands.Blogs; +using Jambo.Domain.Aggregates.Posts; +using Jambo.Application.Commands.Posts; + +namespace Jambo.Application.CommandHandlers.Blogs +{ + public class EnableBlogCommandHandler : IAsyncRequestHandler + { + private readonly IServiceBus _serviceBus; + private readonly IBlogReadOnlyRepository _blogReadOnlyRepository; + + public EnableBlogCommandHandler( + IServiceBus serviceBus, + IBlogReadOnlyRepository blogReadOnlyRepository) + { + _serviceBus = serviceBus ?? + throw new ArgumentNullException(nameof(serviceBus)); + _blogReadOnlyRepository = blogReadOnlyRepository ?? + throw new ArgumentNullException(nameof(blogReadOnlyRepository)); + } + + public async Task Handle(HidePostCommand message) + { + Blog blog = await _blogReadOnlyRepository.GetBlog(message.Id); + blog.Enable(); + + await _serviceBus.Publish(blog.GetEvents()); + } + } +} diff --git a/source/Jambo.Application/CommandHandlers/AtualizarBlogCommandHandler.cs b/source/Jambo.Application/CommandHandlers/Blogs/UpdateBlogUrlCommandHandler.cs similarity index 86% rename from source/Jambo.Application/CommandHandlers/AtualizarBlogCommandHandler.cs rename to source/Jambo.Application/CommandHandlers/Blogs/UpdateBlogUrlCommandHandler.cs index e9a212f..8db3fa9 100644 --- a/source/Jambo.Application/CommandHandlers/AtualizarBlogCommandHandler.cs +++ b/source/Jambo.Application/CommandHandlers/Blogs/UpdateBlogUrlCommandHandler.cs @@ -6,14 +6,14 @@ using Jambo.Domain.ServiceBus; using Jambo.Domain.Aggregates.Blogs; using Jambo.Application.Commands.Blogs; -namespace Jambo.Application.CommandHandlers +namespace Jambo.Application.CommandHandlers.Blogs { - public class AtualizarBlogCommandHandler : IAsyncRequestHandler + public class UpdateBlogUrlCommandHandler : IAsyncRequestHandler { private readonly IServiceBus _serviceBus; private readonly IBlogReadOnlyRepository _blogReadOnlyRepository; - public AtualizarBlogCommandHandler( + public UpdateBlogUrlCommandHandler( IServiceBus serviceBus, IBlogReadOnlyRepository blogReadOnlyRepository) { diff --git a/source/Jambo.Application/CommandHandlers/Posts/CreatePostCommandHandler.cs b/source/Jambo.Application/CommandHandlers/Posts/CreatePostCommandHandler.cs new file mode 100644 index 0000000..c173eaf --- /dev/null +++ b/source/Jambo.Application/CommandHandlers/Posts/CreatePostCommandHandler.cs @@ -0,0 +1,39 @@ +using Jambo.Application.Commands; +using Jambo.Application.Commands.Blogs; +using Jambo.Application.Commands.Posts; +using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Posts; +using Jambo.Domain.ServiceBus; +using MediatR; +using System; +using System.Threading.Tasks; + +namespace Jambo.Application.CommandHandlers.Posts +{ + public class CreatePostCommandHandler : IAsyncRequestHandler + { + private readonly IServiceBus _serviceBus; + private readonly IPostReadOnlyRepository _blogReadOnlyRepository; + + public CreatePostCommandHandler( + IServiceBus serviceBus, + IPostReadOnlyRepository blogReadOnlyRepository) + { + _serviceBus = serviceBus ?? + throw new ArgumentNullException(nameof(serviceBus)); + _blogReadOnlyRepository = blogReadOnlyRepository ?? + throw new ArgumentNullException(nameof(blogReadOnlyRepository)); + } + + public async Task Handle(CreatePostCommand message) + { + Post post = new Post(); + post.SetBlogId(message.BlogId); + post.UpdateContent(message.Title, message.Content); + + await _serviceBus.Publish(post.GetEvents()); + + return post.Id; + } + } +} diff --git a/source/Jambo.Application/CommandHandlers/Posts/DisablePostCommandHandler.cs b/source/Jambo.Application/CommandHandlers/Posts/DisablePostCommandHandler.cs new file mode 100644 index 0000000..0aa7c0f --- /dev/null +++ b/source/Jambo.Application/CommandHandlers/Posts/DisablePostCommandHandler.cs @@ -0,0 +1,36 @@ +using Jambo.Application.Commands; +using Jambo.Application.Commands.Blogs; +using Jambo.Application.Commands.Posts; +using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Posts; +using Jambo.Domain.ServiceBus; +using MediatR; +using System; +using System.Threading.Tasks; + +namespace Jambo.Application.CommandHandlers.Posts +{ + public class DisablePostCommandHandler : IAsyncRequestHandler + { + private readonly IServiceBus _serviceBus; + private readonly IPostReadOnlyRepository _postReadOnlyRepository; + + public DisablePostCommandHandler( + IServiceBus serviceBus, + IPostReadOnlyRepository postReadOnlyRepository) + { + _serviceBus = serviceBus ?? + throw new ArgumentNullException(nameof(serviceBus)); + _postReadOnlyRepository = postReadOnlyRepository ?? + throw new ArgumentNullException(nameof(postReadOnlyRepository)); + } + + public async Task Handle(DisablePostCommand message) + { + Post post = await _postReadOnlyRepository.GetPost(message.Id); + post.Disable(); + + await _serviceBus.Publish(post.GetEvents()); + } + } +} diff --git a/source/Jambo.Application/CommandHandlers/Posts/EnablePostCommandHandler.cs b/source/Jambo.Application/CommandHandlers/Posts/EnablePostCommandHandler.cs new file mode 100644 index 0000000..178848d --- /dev/null +++ b/source/Jambo.Application/CommandHandlers/Posts/EnablePostCommandHandler.cs @@ -0,0 +1,36 @@ +using Jambo.Application.Commands; +using Jambo.Application.Commands.Blogs; +using Jambo.Application.Commands.Posts; +using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Posts; +using Jambo.Domain.ServiceBus; +using MediatR; +using System; +using System.Threading.Tasks; + +namespace Jambo.Application.CommandHandlers.Posts +{ + public class EnablePostCommandHandler : IAsyncRequestHandler + { + private readonly IServiceBus _serviceBus; + private readonly IPostReadOnlyRepository _postReadOnlyRepository; + + public EnablePostCommandHandler( + IServiceBus serviceBus, + IPostReadOnlyRepository postReadOnlyRepository) + { + _serviceBus = serviceBus ?? + throw new ArgumentNullException(nameof(serviceBus)); + _postReadOnlyRepository = postReadOnlyRepository ?? + throw new ArgumentNullException(nameof(postReadOnlyRepository)); + } + + public async Task Handle(EnablePostCommand message) + { + Post post = await _postReadOnlyRepository.GetPost(message.Id); + post.Enable(); + + await _serviceBus.Publish(post.GetEvents()); + } + } +} diff --git a/source/Jambo.Application/CommandHandlers/Posts/HidePostCommandHandler.cs b/source/Jambo.Application/CommandHandlers/Posts/HidePostCommandHandler.cs new file mode 100644 index 0000000..03d6993 --- /dev/null +++ b/source/Jambo.Application/CommandHandlers/Posts/HidePostCommandHandler.cs @@ -0,0 +1,36 @@ +using Jambo.Application.Commands; +using Jambo.Application.Commands.Blogs; +using Jambo.Application.Commands.Posts; +using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Posts; +using Jambo.Domain.ServiceBus; +using MediatR; +using System; +using System.Threading.Tasks; + +namespace Jambo.Application.CommandHandlers.Posts +{ + public class HidePostCommandHandler : IAsyncRequestHandler + { + private readonly IServiceBus _serviceBus; + private readonly IPostReadOnlyRepository _postReadOnlyRepository; + + public HidePostCommandHandler( + IServiceBus serviceBus, + IPostReadOnlyRepository postReadOnlyRepository) + { + _serviceBus = serviceBus ?? + throw new ArgumentNullException(nameof(serviceBus)); + _postReadOnlyRepository = postReadOnlyRepository ?? + throw new ArgumentNullException(nameof(postReadOnlyRepository)); + } + + public async Task Handle(HidePostCommand message) + { + Post post = await _postReadOnlyRepository.GetPost(message.Id); + post.Hide(); + + await _serviceBus.Publish(post.GetEvents()); + } + } +} diff --git a/source/Jambo.Application/CommandHandlers/Posts/PublishPostCommandHandler.cs b/source/Jambo.Application/CommandHandlers/Posts/PublishPostCommandHandler.cs new file mode 100644 index 0000000..20555ec --- /dev/null +++ b/source/Jambo.Application/CommandHandlers/Posts/PublishPostCommandHandler.cs @@ -0,0 +1,36 @@ +using Jambo.Application.Commands; +using Jambo.Application.Commands.Blogs; +using Jambo.Application.Commands.Posts; +using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Posts; +using Jambo.Domain.ServiceBus; +using MediatR; +using System; +using System.Threading.Tasks; + +namespace Jambo.Application.CommandHandlers.Posts +{ + public class PublishPostCommandHandler : IAsyncRequestHandler + { + private readonly IServiceBus _serviceBus; + private readonly IPostReadOnlyRepository _postReadOnlyRepository; + + public PublishPostCommandHandler( + IServiceBus serviceBus, + IPostReadOnlyRepository postReadOnlyRepository) + { + _serviceBus = serviceBus ?? + throw new ArgumentNullException(nameof(serviceBus)); + _postReadOnlyRepository = postReadOnlyRepository ?? + throw new ArgumentNullException(nameof(postReadOnlyRepository)); + } + + public async Task Handle(PublishPostCommand message) + { + Post post = await _postReadOnlyRepository.GetPost(message.Id); + post.Publish(); + + await _serviceBus.Publish(post.GetEvents()); + } + } +} diff --git a/source/Jambo.Application/CommandHandlers/Posts/UpdateContentCommandHandler.cs b/source/Jambo.Application/CommandHandlers/Posts/UpdateContentCommandHandler.cs new file mode 100644 index 0000000..545bb08 --- /dev/null +++ b/source/Jambo.Application/CommandHandlers/Posts/UpdateContentCommandHandler.cs @@ -0,0 +1,36 @@ +using Jambo.Application.Commands; +using Jambo.Application.Commands.Blogs; +using Jambo.Application.Commands.Posts; +using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Posts; +using Jambo.Domain.ServiceBus; +using MediatR; +using System; +using System.Threading.Tasks; + +namespace Jambo.Application.CommandHandlers.Posts +{ + public class UpdateContentCommandHandler : IAsyncRequestHandler + { + private readonly IServiceBus _serviceBus; + private readonly IPostReadOnlyRepository _postReadOnlyRepository; + + public UpdateContentCommandHandler( + IServiceBus serviceBus, + IPostReadOnlyRepository postReadOnlyRepository) + { + _serviceBus = serviceBus ?? + throw new ArgumentNullException(nameof(serviceBus)); + _postReadOnlyRepository = postReadOnlyRepository ?? + throw new ArgumentNullException(nameof(postReadOnlyRepository)); + } + + public async Task Handle(UpdatePostContentCommand message) + { + Post post = await _postReadOnlyRepository.GetPost(message.Id); + post.UpdateContent(message.Title, message.Content); + + await _serviceBus.Publish(post.GetEvents()); + } + } +} diff --git a/source/Jambo.Application/Commands/Blogs/UpdateBlogUrlCommand.cs b/source/Jambo.Application/Commands/Blogs/UpdateBlogUrlCommand.cs index 8fe6f08..411ce48 100644 --- a/source/Jambo.Application/Commands/Blogs/UpdateBlogUrlCommand.cs +++ b/source/Jambo.Application/Commands/Blogs/UpdateBlogUrlCommand.cs @@ -13,19 +13,15 @@ namespace Jambo.Application.Commands.Blogs [DataMember] public string Url { get; private set; } - [DataMember] - public int Rating { get; private set; } - public UpdateBlogUrlCommand() { } - public UpdateBlogUrlCommand(Guid id, string url, int rating) : this() + public UpdateBlogUrlCommand(Guid id, string url) : this() { Id = id; Url = url; - Rating = rating; } } } \ No newline at end of file diff --git a/source/Jambo.Application/Commands/Posts/CreatePostCommand.cs b/source/Jambo.Application/Commands/Posts/CreatePostCommand.cs index a91a1e1..6c2b123 100644 --- a/source/Jambo.Application/Commands/Posts/CreatePostCommand.cs +++ b/source/Jambo.Application/Commands/Posts/CreatePostCommand.cs @@ -1,6 +1,5 @@ using MediatR; using System.Runtime.Serialization; -using Jambo.Application.Commands; using System; namespace Jambo.Application.Commands.Posts @@ -9,16 +8,24 @@ namespace Jambo.Application.Commands.Posts public class CreatePostCommand : IRequest { [DataMember] - public string Url { get; private set; } + public Guid BlogId { get; private set; } + + [DataMember] + public string Title { get; private set; } + + [DataMember] + public string Content { get; private set; } public CreatePostCommand() { } - public CreatePostCommand(string url) : this() + public CreatePostCommand(Guid blogId, string title, string content) : this() { - Url = url; + BlogId = blogId; + Title = title; + Content = content; } } } diff --git a/source/Jambo.Application/Commands/Posts/DisablePostCommand.cs b/source/Jambo.Application/Commands/Posts/DisablePostCommand.cs index 250f090..128420e 100644 --- a/source/Jambo.Application/Commands/Posts/DisablePostCommand.cs +++ b/source/Jambo.Application/Commands/Posts/DisablePostCommand.cs @@ -1,6 +1,7 @@ using MediatR; using System.Runtime.Serialization; using Jambo.Application.Commands; +using System; namespace Jambo.Application.Commands.Posts { @@ -8,16 +9,16 @@ namespace Jambo.Application.Commands.Posts public class DisablePostCommand : IRequest { [DataMember] - public string Url { get; private set; } + public Guid Id { get; private set; } public DisablePostCommand() { } - public DisablePostCommand(string url) : this() + public DisablePostCommand(Guid id) : this() { - Url = url; + Id = id; } } } diff --git a/source/Jambo.Application/Commands/Posts/UpdateContentCommand.cs b/source/Jambo.Application/Commands/Posts/EnablePostCommand.cs similarity index 51% rename from source/Jambo.Application/Commands/Posts/UpdateContentCommand.cs rename to source/Jambo.Application/Commands/Posts/EnablePostCommand.cs index 39338e1..060fd35 100644 --- a/source/Jambo.Application/Commands/Posts/UpdateContentCommand.cs +++ b/source/Jambo.Application/Commands/Posts/EnablePostCommand.cs @@ -1,23 +1,24 @@ using MediatR; using System.Runtime.Serialization; using Jambo.Application.Commands; +using System; namespace Jambo.Application.Commands.Posts { [DataContract] - public class UpdateContentCommand : IRequest + public class EnablePostCommand : IRequest { [DataMember] - public string Url { get; private set; } + public Guid Id { get; private set; } - public UpdateContentCommand() + public EnablePostCommand() { } - public UpdateContentCommand(string url) : this() + public EnablePostCommand(Guid id) : this() { - Url = url; + Id = id; } } } diff --git a/source/Jambo.Application/Commands/Posts/HidePostCommand.cs b/source/Jambo.Application/Commands/Posts/HidePostCommand.cs index d5839fa..b41773c 100644 --- a/source/Jambo.Application/Commands/Posts/HidePostCommand.cs +++ b/source/Jambo.Application/Commands/Posts/HidePostCommand.cs @@ -1,6 +1,7 @@ using MediatR; using System.Runtime.Serialization; using Jambo.Application.Commands; +using System; namespace Jambo.Application.Commands.Posts { @@ -8,16 +9,16 @@ namespace Jambo.Application.Commands.Posts public class HidePostCommand : IRequest { [DataMember] - public string Url { get; private set; } + public Guid Id { get; private set; } public HidePostCommand() { } - public HidePostCommand(string url) : this() + public HidePostCommand(Guid id) : this() { - Url = url; + Id = id; } } } diff --git a/source/Jambo.Application/Commands/Posts/PublishPostCommand.cs b/source/Jambo.Application/Commands/Posts/PublishPostCommand.cs index a33a016..ffb3bd8 100644 --- a/source/Jambo.Application/Commands/Posts/PublishPostCommand.cs +++ b/source/Jambo.Application/Commands/Posts/PublishPostCommand.cs @@ -1,6 +1,7 @@ using MediatR; using System.Runtime.Serialization; using Jambo.Application.Commands; +using System; namespace Jambo.Application.Commands.Posts { @@ -8,16 +9,16 @@ namespace Jambo.Application.Commands.Posts public class PublishPostCommand : IRequest { [DataMember] - public string Url { get; private set; } + public Guid Id { get; private set; } public PublishPostCommand() { } - public PublishPostCommand(string url) : this() + public PublishPostCommand(Guid id) : this() { - Url = url; + Id = id; } } } diff --git a/source/Jambo.Application/Commands/Posts/UpdatePostContentCommand.cs b/source/Jambo.Application/Commands/Posts/UpdatePostContentCommand.cs new file mode 100644 index 0000000..be41369 --- /dev/null +++ b/source/Jambo.Application/Commands/Posts/UpdatePostContentCommand.cs @@ -0,0 +1,32 @@ +using MediatR; +using System.Runtime.Serialization; +using Jambo.Application.Commands; +using System; + +namespace Jambo.Application.Commands.Posts +{ + [DataContract] + public class UpdatePostContentCommand : IRequest + { + [DataMember] + public Guid Id { get; private set; } + + [DataMember] + public string Title { get; private set; } + + [DataMember] + public string Content { get; private set; } + + public UpdatePostContentCommand() + { + + } + + public UpdatePostContentCommand(Guid id, string title, string content) : this() + { + Id = id; + Title = title; + Content = content; + } + } +} diff --git a/source/Jambo.Application/DomainEventHandlers/BlogCriadoEventHandler.cs b/source/Jambo.Application/DomainEventHandlers/Blogs/BlogCreatedEventHandler.cs similarity index 77% rename from source/Jambo.Application/DomainEventHandlers/BlogCriadoEventHandler.cs rename to source/Jambo.Application/DomainEventHandlers/Blogs/BlogCreatedEventHandler.cs index 38a16d0..4ea5839 100644 --- a/source/Jambo.Application/DomainEventHandlers/BlogCriadoEventHandler.cs +++ b/source/Jambo.Application/DomainEventHandlers/Blogs/BlogCreatedEventHandler.cs @@ -4,14 +4,14 @@ using MediatR; using System; using System.Threading.Tasks; -namespace Jambo.Application.DomainEventHandlers +namespace Jambo.Application.DomainEventHandlers.Blogs { - public class BlogCriadoEventHandler : IAsyncNotificationHandler + public class BlogCreatedEventHandler : IAsyncNotificationHandler { private readonly IBlogReadOnlyRepository _blogReadOnlyRepository; private readonly IBlogWriteOnlyRepository _blogWriteOnlyRepository; - public BlogCriadoEventHandler( + public BlogCreatedEventHandler( IBlogReadOnlyRepository blogReadOnlyRepository, IBlogWriteOnlyRepository blogWriteOnlyRepository) { @@ -20,7 +20,7 @@ namespace Jambo.Application.DomainEventHandlers _blogWriteOnlyRepository = blogWriteOnlyRepository ?? throw new ArgumentNullException(nameof(blogWriteOnlyRepository)); } - public async Task Handle(CreatedBlogDomainEvent message) + public async Task Handle(BlogCreatedDomainEvent message) { Blog blog = new Blog(message.AggregateRootId); diff --git a/source/Jambo.Application/DomainEventHandlers/Blogs/BlogDisabledEventHandler.cs b/source/Jambo.Application/DomainEventHandlers/Blogs/BlogDisabledEventHandler.cs new file mode 100644 index 0000000..930a4e7 --- /dev/null +++ b/source/Jambo.Application/DomainEventHandlers/Blogs/BlogDisabledEventHandler.cs @@ -0,0 +1,34 @@ +using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Blogs.Events; +using MediatR; +using System; +using System.Threading.Tasks; + +namespace Jambo.Application.DomainEventHandlers.Blogs +{ + public class BlogDisabledEventHandler : IAsyncNotificationHandler + { + private readonly IBlogReadOnlyRepository _blogReadOnlyRepository; + private readonly IBlogWriteOnlyRepository _blogWriteOnlyRepository; + + public BlogDisabledEventHandler( + IBlogReadOnlyRepository blogReadOnlyRepository, + IBlogWriteOnlyRepository blogWriteOnlyRepository) + { + _blogReadOnlyRepository = blogReadOnlyRepository ?? + throw new ArgumentNullException(nameof(blogReadOnlyRepository)); + _blogWriteOnlyRepository = blogWriteOnlyRepository ?? + throw new ArgumentNullException(nameof(blogWriteOnlyRepository)); + } + public async Task Handle(BlogUrlUpdatedDomainEvent message) + { + Blog blog = await _blogReadOnlyRepository.GetBlog(message.AggregateRootId); + + if (blog.Version == message.Version) + { + blog.Disable(); + await _blogWriteOnlyRepository.UpdateBlog(blog); + } + } + } +} diff --git a/source/Jambo.Application/DomainEventHandlers/Blogs/BlogEnabledEventHandler.cs b/source/Jambo.Application/DomainEventHandlers/Blogs/BlogEnabledEventHandler.cs new file mode 100644 index 0000000..b2b4181 --- /dev/null +++ b/source/Jambo.Application/DomainEventHandlers/Blogs/BlogEnabledEventHandler.cs @@ -0,0 +1,34 @@ +using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Blogs.Events; +using MediatR; +using System; +using System.Threading.Tasks; + +namespace Jambo.Application.DomainEventHandlers.Blogs +{ + public class BlogEnabledEventHandler : IAsyncNotificationHandler + { + private readonly IBlogReadOnlyRepository _blogReadOnlyRepository; + private readonly IBlogWriteOnlyRepository _blogWriteOnlyRepository; + + public BlogEnabledEventHandler( + IBlogReadOnlyRepository blogReadOnlyRepository, + IBlogWriteOnlyRepository blogWriteOnlyRepository) + { + _blogReadOnlyRepository = blogReadOnlyRepository ?? + throw new ArgumentNullException(nameof(blogReadOnlyRepository)); + _blogWriteOnlyRepository = blogWriteOnlyRepository ?? + throw new ArgumentNullException(nameof(blogWriteOnlyRepository)); + } + public async Task Handle(BlogUrlUpdatedDomainEvent message) + { + Blog blog = await _blogReadOnlyRepository.GetBlog(message.AggregateRootId); + + if (blog.Version == message.Version) + { + blog.Enable(); + await _blogWriteOnlyRepository.UpdateBlog(blog); + } + } + } +} diff --git a/source/Jambo.Application/DomainEventHandlers/UrlDefinidaEventHandler.cs b/source/Jambo.Application/DomainEventHandlers/Blogs/BlogUrlUpdatedEventHandler.cs similarity index 84% rename from source/Jambo.Application/DomainEventHandlers/UrlDefinidaEventHandler.cs rename to source/Jambo.Application/DomainEventHandlers/Blogs/BlogUrlUpdatedEventHandler.cs index a2ebc90..2fb3b43 100644 --- a/source/Jambo.Application/DomainEventHandlers/UrlDefinidaEventHandler.cs +++ b/source/Jambo.Application/DomainEventHandlers/Blogs/BlogUrlUpdatedEventHandler.cs @@ -4,14 +4,14 @@ using MediatR; using System; using System.Threading.Tasks; -namespace Jambo.Application.DomainEventHandlers +namespace Jambo.Application.DomainEventHandlers.Blogs { - public class UrlDefinidaEventHandler : IAsyncNotificationHandler + public class BlogUrlUpdatedEventHandler : IAsyncNotificationHandler { private readonly IBlogReadOnlyRepository _blogReadOnlyRepository; private readonly IBlogWriteOnlyRepository _blogWriteOnlyRepository; - public UrlDefinidaEventHandler( + public BlogUrlUpdatedEventHandler( IBlogReadOnlyRepository blogReadOnlyRepository, IBlogWriteOnlyRepository blogWriteOnlyRepository) { diff --git a/source/Jambo.Application/DomainEventHandlers/Posts/PostContentUpdatedEventHandler.cs b/source/Jambo.Application/DomainEventHandlers/Posts/PostContentUpdatedEventHandler.cs new file mode 100644 index 0000000..a4c44b9 --- /dev/null +++ b/source/Jambo.Application/DomainEventHandlers/Posts/PostContentUpdatedEventHandler.cs @@ -0,0 +1,35 @@ +using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Blogs.Events; +using Jambo.Domain.Aggregates.Posts; +using MediatR; +using System; +using System.Threading.Tasks; + +namespace Jambo.Application.DomainEventHandlers.Posts +{ + public class PostContentUpdatedEventHandler : IAsyncNotificationHandler + { + private readonly IPostReadOnlyRepository _postReadOnlyRepository; + private readonly IPostWriteOnlyRepository _postWriteOnlyRepository; + + public PostContentUpdatedEventHandler( + IPostReadOnlyRepository postReadOnlyRepository, + IPostWriteOnlyRepository postWriteOnlyRepository) + { + _postReadOnlyRepository = postReadOnlyRepository ?? + throw new ArgumentNullException(nameof(postReadOnlyRepository)); + _postWriteOnlyRepository = postWriteOnlyRepository ?? + throw new ArgumentNullException(nameof(postWriteOnlyRepository)); + } + public async Task Handle(PostContentUpdatedDomainEvent message) + { + Post post = await _postReadOnlyRepository.GetPost(message.AggregateRootId); + + if (post.Version == message.Version) + { + post.UpdateContent(message.Title, message.Content); + await _postWriteOnlyRepository.UpdatePost(post); + } + } + } +} diff --git a/source/Jambo.Application/DomainEventHandlers/Posts/PostCreatedEventHandler.cs b/source/Jambo.Application/DomainEventHandlers/Posts/PostCreatedEventHandler.cs new file mode 100644 index 0000000..2e7596d --- /dev/null +++ b/source/Jambo.Application/DomainEventHandlers/Posts/PostCreatedEventHandler.cs @@ -0,0 +1,31 @@ +using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Blogs.Events; +using Jambo.Domain.Aggregates.Posts; +using MediatR; +using System; +using System.Threading.Tasks; + +namespace Jambo.Application.DomainEventHandlers.Posts +{ + public class PostCreatedEventHandler : IAsyncNotificationHandler + { + private readonly IPostReadOnlyRepository _postReadOnlyRepository; + private readonly IPostWriteOnlyRepository _postWriteOnlyRepository; + + public PostCreatedEventHandler( + IPostReadOnlyRepository postReadOnlyRepository, + IPostWriteOnlyRepository postWriteOnlyRepository) + { + _postReadOnlyRepository = postReadOnlyRepository ?? + throw new ArgumentNullException(nameof(postReadOnlyRepository)); + _postWriteOnlyRepository = postWriteOnlyRepository ?? + throw new ArgumentNullException(nameof(postWriteOnlyRepository)); + } + public async Task Handle(BlogCreatedDomainEvent message) + { + Post post = new Post(message.AggregateRootId); + + await _postWriteOnlyRepository.AddPost(post); + } + } +} diff --git a/source/Jambo.Application/DomainEventHandlers/Posts/PostDisabledEventHandler.cs b/source/Jambo.Application/DomainEventHandlers/Posts/PostDisabledEventHandler.cs new file mode 100644 index 0000000..dfd40a5 --- /dev/null +++ b/source/Jambo.Application/DomainEventHandlers/Posts/PostDisabledEventHandler.cs @@ -0,0 +1,35 @@ +using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Blogs.Events; +using Jambo.Domain.Aggregates.Posts; +using MediatR; +using System; +using System.Threading.Tasks; + +namespace Jambo.Application.DomainEventHandlers.Posts +{ + public class PostDisabledEventHandler : IAsyncNotificationHandler + { + private readonly IPostReadOnlyRepository _postReadOnlyRepository; + private readonly IPostWriteOnlyRepository _postWriteOnlyRepository; + + public PostDisabledEventHandler( + IPostReadOnlyRepository postReadOnlyRepository, + IPostWriteOnlyRepository postWriteOnlyRepository) + { + _postReadOnlyRepository = postReadOnlyRepository ?? + throw new ArgumentNullException(nameof(postReadOnlyRepository)); + _postWriteOnlyRepository = postWriteOnlyRepository ?? + throw new ArgumentNullException(nameof(postWriteOnlyRepository)); + } + public async Task Handle(PostDisabledDomainEvent message) + { + Post post = await _postReadOnlyRepository.GetPost(message.AggregateRootId); + + if (post.Version == message.Version) + { + post.Disable(); + await _postWriteOnlyRepository.UpdatePost(post); + } + } + } +} diff --git a/source/Jambo.Application/DomainEventHandlers/Posts/PostEnabledEventHandler.cs b/source/Jambo.Application/DomainEventHandlers/Posts/PostEnabledEventHandler.cs new file mode 100644 index 0000000..330320e --- /dev/null +++ b/source/Jambo.Application/DomainEventHandlers/Posts/PostEnabledEventHandler.cs @@ -0,0 +1,36 @@ +using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Blogs.Events; +using Jambo.Domain.Aggregates.Posts; +using MediatR; +using System; +using System.Threading.Tasks; + +namespace Jambo.Application.DomainEventHandlers.Posts +{ + public class PostEnabledEventHandler : IAsyncNotificationHandler + { + private readonly IPostReadOnlyRepository _postReadOnlyRepository; + private readonly IPostWriteOnlyRepository _postWriteOnlyRepository; + + public PostEnabledEventHandler( + IPostReadOnlyRepository postReadOnlyRepository, + IPostWriteOnlyRepository postWriteOnlyRepository) + { + _postReadOnlyRepository = postReadOnlyRepository ?? + throw new ArgumentNullException(nameof(postReadOnlyRepository)); + _postWriteOnlyRepository = postWriteOnlyRepository ?? + throw new ArgumentNullException(nameof(postWriteOnlyRepository)); + } + + public async Task Handle(PostEnabledDomainEvent message) + { + Post post = await _postReadOnlyRepository.GetPost(message.AggregateRootId); + + if (post.Version == message.Version) + { + post.Enable(); + await _postWriteOnlyRepository.UpdatePost(post); + } + } + } +} diff --git a/source/Jambo.Application/DomainEventHandlers/Posts/PostHiddenDomainEventHandler.cs b/source/Jambo.Application/DomainEventHandlers/Posts/PostHiddenDomainEventHandler.cs new file mode 100644 index 0000000..786330d --- /dev/null +++ b/source/Jambo.Application/DomainEventHandlers/Posts/PostHiddenDomainEventHandler.cs @@ -0,0 +1,35 @@ +using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Blogs.Events; +using Jambo.Domain.Aggregates.Posts; +using MediatR; +using System; +using System.Threading.Tasks; + +namespace Jambo.Application.DomainEventHandlers.Posts +{ + public class PostHiddenDomainEventHandler : IAsyncNotificationHandler + { + private readonly IPostReadOnlyRepository _postReadOnlyRepository; + private readonly IPostWriteOnlyRepository _postWriteOnlyRepository; + + public PostHiddenDomainEventHandler( + IPostReadOnlyRepository postReadOnlyRepository, + IPostWriteOnlyRepository postWriteOnlyRepository) + { + _postReadOnlyRepository = postReadOnlyRepository ?? + throw new ArgumentNullException(nameof(postReadOnlyRepository)); + _postWriteOnlyRepository = postWriteOnlyRepository ?? + throw new ArgumentNullException(nameof(postWriteOnlyRepository)); + } + public async Task Handle(PostHiddenDomainEvent message) + { + Post post = await _postReadOnlyRepository.GetPost(message.AggregateRootId); + + if (post.Version == message.Version) + { + post.Hide(); + await _postWriteOnlyRepository.UpdatePost(post); + } + } + } +} diff --git a/source/Jambo.Application/DomainEventHandlers/Posts/PostPublishedDomainEventHandler.cs b/source/Jambo.Application/DomainEventHandlers/Posts/PostPublishedDomainEventHandler.cs new file mode 100644 index 0000000..e480a10 --- /dev/null +++ b/source/Jambo.Application/DomainEventHandlers/Posts/PostPublishedDomainEventHandler.cs @@ -0,0 +1,35 @@ +using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Blogs.Events; +using Jambo.Domain.Aggregates.Posts; +using MediatR; +using System; +using System.Threading.Tasks; + +namespace Jambo.Application.DomainEventHandlers.Posts +{ + public class PostPublishedDomainEventHandler : IAsyncNotificationHandler + { + private readonly IPostReadOnlyRepository _postReadOnlyRepository; + private readonly IPostWriteOnlyRepository _postWriteOnlyRepository; + + public PostPublishedDomainEventHandler( + IPostReadOnlyRepository postReadOnlyRepository, + IPostWriteOnlyRepository postWriteOnlyRepository) + { + _postReadOnlyRepository = postReadOnlyRepository ?? + throw new ArgumentNullException(nameof(postReadOnlyRepository)); + _postWriteOnlyRepository = postWriteOnlyRepository ?? + throw new ArgumentNullException(nameof(postWriteOnlyRepository)); + } + public async Task Handle(PostPublishedDomainEvent message) + { + Post post = await _postReadOnlyRepository.GetPost(message.AggregateRootId); + + if (post.Version == message.Version) + { + post.Publish(); + await _postWriteOnlyRepository.UpdatePost(post); + } + } + } +} diff --git a/source/Jambo.Application/Queries/BlogQueries.cs b/source/Jambo.Application/Queries/BlogQueries.cs index b63bd6d..8ac59bc 100644 --- a/source/Jambo.Application/Queries/BlogQueries.cs +++ b/source/Jambo.Application/Queries/BlogQueries.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using MongoDB.Driver; using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Posts; namespace Jambo.Application.Queries { diff --git a/source/Jambo.Domain/Aggregates/Blogs/Blog.cs b/source/Jambo.Domain/Aggregates/Blogs/Blog.cs index 26dbee6..25a2594 100644 --- a/source/Jambo.Domain/Aggregates/Blogs/Blog.cs +++ b/source/Jambo.Domain/Aggregates/Blogs/Blog.cs @@ -1,4 +1,5 @@ using Jambo.Domain.Aggregates.Blogs.Events; +using Jambo.Domain.Aggregates.Posts; using System; using System.Collections.Generic; @@ -8,11 +9,10 @@ namespace Jambo.Domain.Aggregates.Blogs { public string Url { get; private set; } public int Rating { get; private set; } - public List Posts { get; private set; } public Blog() { - AddEvent(new CreatedBlogDomainEvent(Id)); + AddEvent(new BlogCreatedDomainEvent(Id)); } public Blog(Guid id) @@ -28,12 +28,12 @@ namespace Jambo.Domain.Aggregates.Blogs public void Disable() { - AddEvent(new DisabledBlogDomainEvent(Id, Version)); + AddEvent(new BlogDisabledDomainEvent(Id, Version)); } public void Enable() { - AddEvent(new EnabledBlogDomainEvent(Id, Version)); + AddEvent(new BlogEnabledDomainEvent(Id, Version)); } } } diff --git a/source/Jambo.Domain/Aggregates/Blogs/Events/CreatedBlogDomainEvent.cs b/source/Jambo.Domain/Aggregates/Blogs/Events/BlogCreatedDomainEvent.cs similarity index 59% rename from source/Jambo.Domain/Aggregates/Blogs/Events/CreatedBlogDomainEvent.cs rename to source/Jambo.Domain/Aggregates/Blogs/Events/BlogCreatedDomainEvent.cs index 4434270..1bfdf7c 100644 --- a/source/Jambo.Domain/Aggregates/Blogs/Events/CreatedBlogDomainEvent.cs +++ b/source/Jambo.Domain/Aggregates/Blogs/Events/BlogCreatedDomainEvent.cs @@ -3,9 +3,9 @@ using System; namespace Jambo.Domain.Aggregates.Blogs.Events { - public class CreatedBlogDomainEvent : DomainEvent + public class BlogCreatedDomainEvent : DomainEvent { - public CreatedBlogDomainEvent(Guid aggregateRootId) + public BlogCreatedDomainEvent(Guid aggregateRootId) :base(aggregateRootId, 0) { } diff --git a/source/Jambo.Domain/Aggregates/Blogs/Events/DisabledBlogDomainEvent.cs b/source/Jambo.Domain/Aggregates/Blogs/Events/BlogDisabledDomainEvent.cs similarity index 60% rename from source/Jambo.Domain/Aggregates/Blogs/Events/DisabledBlogDomainEvent.cs rename to source/Jambo.Domain/Aggregates/Blogs/Events/BlogDisabledDomainEvent.cs index 685abcd..8dc6acb 100644 --- a/source/Jambo.Domain/Aggregates/Blogs/Events/DisabledBlogDomainEvent.cs +++ b/source/Jambo.Domain/Aggregates/Blogs/Events/BlogDisabledDomainEvent.cs @@ -3,9 +3,9 @@ using System; namespace Jambo.Domain.Aggregates.Blogs.Events { - public class DisabledBlogDomainEvent : DomainEvent + public class BlogDisabledDomainEvent : DomainEvent { - public DisabledBlogDomainEvent(Guid aggregateRootId, int version) + public BlogDisabledDomainEvent(Guid aggregateRootId, int version) :base(aggregateRootId, version) { } diff --git a/source/Jambo.Domain/Aggregates/Blogs/Events/EnabledBlogDomainEvent.cs b/source/Jambo.Domain/Aggregates/Blogs/Events/BlogEnabledDomainEvent.cs similarity index 61% rename from source/Jambo.Domain/Aggregates/Blogs/Events/EnabledBlogDomainEvent.cs rename to source/Jambo.Domain/Aggregates/Blogs/Events/BlogEnabledDomainEvent.cs index c5d4303..e682ca9 100644 --- a/source/Jambo.Domain/Aggregates/Blogs/Events/EnabledBlogDomainEvent.cs +++ b/source/Jambo.Domain/Aggregates/Blogs/Events/BlogEnabledDomainEvent.cs @@ -3,9 +3,9 @@ using System; namespace Jambo.Domain.Aggregates.Blogs.Events { - public class EnabledBlogDomainEvent : DomainEvent + public class BlogEnabledDomainEvent : DomainEvent { - public EnabledBlogDomainEvent(Guid aggregateRootId, int version) + public BlogEnabledDomainEvent(Guid aggregateRootId, int version) :base(aggregateRootId, version) { } diff --git a/source/Jambo.Domain/Aggregates/Blogs/Post.cs b/source/Jambo.Domain/Aggregates/Blogs/Post.cs deleted file mode 100644 index a6c3d0f..0000000 --- a/source/Jambo.Domain/Aggregates/Blogs/Post.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Jambo.Domain.Aggregates.Blogs -{ - public class Post : Entity - { - public string Title { get; private set; } - public string Content { get; private set; } - public int BlogId { get; private set; } - public Blog Blog { get; private set; } - } -} diff --git a/source/Jambo.Domain/Aggregates/Blogs/Events/CreatedPostDomainEvent.cs b/source/Jambo.Domain/Aggregates/Posts/Events/PostContentUpdatedDomainEvent.cs similarity index 67% rename from source/Jambo.Domain/Aggregates/Blogs/Events/CreatedPostDomainEvent.cs rename to source/Jambo.Domain/Aggregates/Posts/Events/PostContentUpdatedDomainEvent.cs index 783e591..3bf57bb 100644 --- a/source/Jambo.Domain/Aggregates/Blogs/Events/CreatedPostDomainEvent.cs +++ b/source/Jambo.Domain/Aggregates/Posts/Events/PostContentUpdatedDomainEvent.cs @@ -3,16 +3,15 @@ using System; namespace Jambo.Domain.Aggregates.Blogs.Events { - public class CreatedPostDomainEvent: DomainEvent + public class PostContentUpdatedDomainEvent : DomainEvent { public string Title { get; set; } public string Content { get; set; } - public CreatedPostDomainEvent(Guid aggregateRootId, int version, + public PostContentUpdatedDomainEvent(Guid aggregateRootId, int version, string title, string content) : base(aggregateRootId, version) { - AggregateRootId = aggregateRootId; Title = title; Content = content; } diff --git a/source/Jambo.Domain/Aggregates/Posts/Events/PostCreatedDomainEvent.cs b/source/Jambo.Domain/Aggregates/Posts/Events/PostCreatedDomainEvent.cs new file mode 100644 index 0000000..3af3cb6 --- /dev/null +++ b/source/Jambo.Domain/Aggregates/Posts/Events/PostCreatedDomainEvent.cs @@ -0,0 +1,13 @@ +using Jambo.Domain.ServiceBus; +using System; + +namespace Jambo.Domain.Aggregates.Blogs.Events +{ + public class PostCreatedDomainEvent : DomainEvent + { + public PostCreatedDomainEvent(Guid aggregateRootId) + :base(aggregateRootId, 0) + { + } + } +} diff --git a/source/Jambo.Domain/Aggregates/Posts/Events/PostDisabledDomainEvent.cs b/source/Jambo.Domain/Aggregates/Posts/Events/PostDisabledDomainEvent.cs new file mode 100644 index 0000000..601772f --- /dev/null +++ b/source/Jambo.Domain/Aggregates/Posts/Events/PostDisabledDomainEvent.cs @@ -0,0 +1,14 @@ +using Jambo.Domain.ServiceBus; +using System; + +namespace Jambo.Domain.Aggregates.Blogs.Events +{ + public class PostDisabledDomainEvent : DomainEvent + { + public PostDisabledDomainEvent(Guid aggregateRootId, int version) + : base(aggregateRootId, version) + { + + } + } +} diff --git a/source/Jambo.Domain/Aggregates/Posts/Events/PostEnabledDomainEvent.cs b/source/Jambo.Domain/Aggregates/Posts/Events/PostEnabledDomainEvent.cs new file mode 100644 index 0000000..8c85c2e --- /dev/null +++ b/source/Jambo.Domain/Aggregates/Posts/Events/PostEnabledDomainEvent.cs @@ -0,0 +1,14 @@ +using Jambo.Domain.ServiceBus; +using System; + +namespace Jambo.Domain.Aggregates.Blogs.Events +{ + public class PostEnabledDomainEvent : DomainEvent + { + public PostEnabledDomainEvent(Guid aggregateRootId, int version) + : base(aggregateRootId, version) + { + + } + } +} diff --git a/source/Jambo.Domain/Aggregates/Posts/Events/PostHiddenDomainEvent.cs b/source/Jambo.Domain/Aggregates/Posts/Events/PostHiddenDomainEvent.cs new file mode 100644 index 0000000..e91c79e --- /dev/null +++ b/source/Jambo.Domain/Aggregates/Posts/Events/PostHiddenDomainEvent.cs @@ -0,0 +1,13 @@ +using Jambo.Domain.ServiceBus; +using System; + +namespace Jambo.Domain.Aggregates.Blogs.Events +{ + public class PostHiddenDomainEvent : DomainEvent + { + public PostHiddenDomainEvent(Guid aggregateRootId, int version) + : base(aggregateRootId, version) + { + } + } +} diff --git a/source/Jambo.Domain/Aggregates/Posts/Events/PostPublishedDomainEvent.cs b/source/Jambo.Domain/Aggregates/Posts/Events/PostPublishedDomainEvent.cs new file mode 100644 index 0000000..e228fba --- /dev/null +++ b/source/Jambo.Domain/Aggregates/Posts/Events/PostPublishedDomainEvent.cs @@ -0,0 +1,13 @@ +using Jambo.Domain.ServiceBus; +using System; + +namespace Jambo.Domain.Aggregates.Blogs.Events +{ + public class PostPublishedDomainEvent : DomainEvent + { + public PostPublishedDomainEvent(Guid aggregateRootId, int version) + : base(aggregateRootId, version) + { + } + } +} diff --git a/source/Jambo.Domain/Aggregates/Posts/IPostReadOnlyRepository.cs b/source/Jambo.Domain/Aggregates/Posts/IPostReadOnlyRepository.cs new file mode 100644 index 0000000..6a65246 --- /dev/null +++ b/source/Jambo.Domain/Aggregates/Posts/IPostReadOnlyRepository.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Jambo.Domain.Aggregates.Posts +{ + public interface IPostReadOnlyRepository + { + Task> GetBlogPosts(Guid blogId); + Task GetPost(Guid id); + } +} diff --git a/source/Jambo.Domain/Aggregates/Posts/IPostWriteOnlyRepository.cs b/source/Jambo.Domain/Aggregates/Posts/IPostWriteOnlyRepository.cs new file mode 100644 index 0000000..849cf72 --- /dev/null +++ b/source/Jambo.Domain/Aggregates/Posts/IPostWriteOnlyRepository.cs @@ -0,0 +1,10 @@ +using System.Threading.Tasks; + +namespace Jambo.Domain.Aggregates.Posts +{ + public interface IPostWriteOnlyRepository + { + Task AddPost(Post post); + Task UpdatePost(Post post); + } +} diff --git a/source/Jambo.Domain/Aggregates/Posts/Post.cs b/source/Jambo.Domain/Aggregates/Posts/Post.cs new file mode 100644 index 0000000..b0fc7c8 --- /dev/null +++ b/source/Jambo.Domain/Aggregates/Posts/Post.cs @@ -0,0 +1,55 @@ +using Jambo.Domain.Aggregates.Blogs.Events; +using System; + +namespace Jambo.Domain.Aggregates.Posts +{ + public class Post : AggregateRoot + { + public string Title { get; private set; } + public string Content { get; private set; } + public int BlogId { get; private set; } + + public Post() + { + AddEvent(new PostCreatedDomainEvent(Id)); + } + + public Post(Guid id) + :base(id) + { + } + + public void Disable() + { + AddEvent(new PostDisabledDomainEvent(Id, Version)); + } + + public void Hide() + { + AddEvent(new PostHiddenDomainEvent(Id, Version)); + } + + public void Enable() + { + AddEvent(new PostEnabledDomainEvent(Id, Version)); + } + + public void UpdateContent(string title, string content) + { + Title = title; + Content = content; + + AddEvent(new PostContentUpdatedDomainEvent(Id, Version, Title, Content)); + } + + public void Publish() + { + AddEvent(new PostPublishedDomainEvent(Id, Version)); + } + + public void SetBlogId(Guid blogId) + { + throw new NotImplementedException(); + } + } +} diff --git a/source/Jambo.Infrastructure/MongoContext.cs b/source/Jambo.Infrastructure/MongoContext.cs index cadfaad..3f7ea4a 100644 --- a/source/Jambo.Infrastructure/MongoContext.cs +++ b/source/Jambo.Infrastructure/MongoContext.cs @@ -1,4 +1,5 @@ using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Posts; using MongoDB.Driver; namespace Jambo.Infrastructure diff --git a/source/Jambo.Infrastructure/Repositories/BlogReadOnlyRepository.cs b/source/Jambo.Infrastructure/Repositories/Blogs/BlogReadOnlyRepository.cs similarity index 89% rename from source/Jambo.Infrastructure/Repositories/BlogReadOnlyRepository.cs rename to source/Jambo.Infrastructure/Repositories/Blogs/BlogReadOnlyRepository.cs index cec2fff..b2edc3e 100644 --- a/source/Jambo.Infrastructure/Repositories/BlogReadOnlyRepository.cs +++ b/source/Jambo.Infrastructure/Repositories/Blogs/BlogReadOnlyRepository.cs @@ -1,10 +1,11 @@ using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Posts; using MongoDB.Driver; using System; using System.Collections.Generic; using System.Threading.Tasks; -namespace Jambo.Infrastructure.Repositories +namespace Jambo.Infrastructure.Repositories.Blogs { public class BlogReadOnlyRepository : IBlogReadOnlyRepository { diff --git a/source/Jambo.Infrastructure/Repositories/BlogWriteOnlyRepository.cs b/source/Jambo.Infrastructure/Repositories/Blogs/BlogWriteOnlyRepository.cs similarity index 93% rename from source/Jambo.Infrastructure/Repositories/BlogWriteOnlyRepository.cs rename to source/Jambo.Infrastructure/Repositories/Blogs/BlogWriteOnlyRepository.cs index d67f591..a7e9183 100644 --- a/source/Jambo.Infrastructure/Repositories/BlogWriteOnlyRepository.cs +++ b/source/Jambo.Infrastructure/Repositories/Blogs/BlogWriteOnlyRepository.cs @@ -3,7 +3,7 @@ using MongoDB.Driver; using System; using System.Threading.Tasks; -namespace Jambo.Infrastructure.Repositories +namespace Jambo.Infrastructure.Repositories.Blogs { public class BlogWriteOnlyRepository : IBlogWriteOnlyRepository { diff --git a/source/Jambo.Infrastructure/Repositories/Posts/PostReadOnlyRepository.cs b/source/Jambo.Infrastructure/Repositories/Posts/PostReadOnlyRepository.cs new file mode 100644 index 0000000..a664c04 --- /dev/null +++ b/source/Jambo.Infrastructure/Repositories/Posts/PostReadOnlyRepository.cs @@ -0,0 +1,29 @@ +using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Posts; +using MongoDB.Driver; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Jambo.Infrastructure.Repositories.Posts +{ + public class PostReadOnlyRepository : IPostReadOnlyRepository + { + private readonly MongoContext _mongoContext; + + public PostReadOnlyRepository(MongoContext mongoContext) + { + _mongoContext = mongoContext; + } + + public async Task> GetBlogPosts(Guid blogId) + { + throw new NotImplementedException(); + } + + public async Task GetPost(Guid id) + { + return await _mongoContext.Posts.Find(e => e.Id == id).SingleOrDefaultAsync(); + } + } +} diff --git a/source/Jambo.Infrastructure/Repositories/Posts/PostWriteOnlyRepository.cs b/source/Jambo.Infrastructure/Repositories/Posts/PostWriteOnlyRepository.cs new file mode 100644 index 0000000..6274a4f --- /dev/null +++ b/source/Jambo.Infrastructure/Repositories/Posts/PostWriteOnlyRepository.cs @@ -0,0 +1,28 @@ +using Jambo.Domain.Aggregates.Blogs; +using Jambo.Domain.Aggregates.Posts; +using MongoDB.Driver; +using System; +using System.Threading.Tasks; + +namespace Jambo.Infrastructure.Repositories.Posts +{ + public class PostWriteOnlyRepository : IPostWriteOnlyRepository + { + private readonly MongoContext _mongoContext; + public PostWriteOnlyRepository(MongoContext mongoContext) + { + _mongoContext = mongoContext; + } + + public async Task AddPost(Post post) + { + await _mongoContext.Posts.InsertOneAsync(post); + } + + public async Task UpdatePost(Post post) + { + post.Version += 1; + await _mongoContext.Posts.ReplaceOneAsync(e => e.Id == post.Id, post); + } + } +}