-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing polly in mongo context and finishing the main flow
- Loading branch information
1 parent
6bbcbc5
commit b2c1283
Showing
36 changed files
with
499 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 44 additions & 2 deletions
46
...fication.Worker/Application/Commands/Send/Handlers/SendNotificationEmailCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,54 @@ | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Notification.Core.Common.Domain; | ||
using Notification.Core.Domain.Enums; | ||
using Notification.Worker.Data.Repositories.Interfaces; | ||
using Notification.Worker.Domain.Entities; | ||
using Notification.Worker.Domain.Services.Interfaces; | ||
using RabbitMQ.Client.Exceptions; | ||
|
||
namespace Notification.Worker.Application.Commands.Handlers; | ||
|
||
public class SendNotificationEmailCommandHandler : IRequestHandler<SendNotificationEmailCommand, IActionResult> | ||
{ | ||
public Task<IActionResult> Handle(SendNotificationEmailCommand request, CancellationToken cancellationToken) | ||
public SendNotificationEmailCommandHandler(INotificationRepository notificationRepository, IEmailServices emailServices) | ||
{ | ||
throw new NotImplementedException(); | ||
_notificationRepository = notificationRepository; | ||
_emailServices = emailServices; | ||
} | ||
|
||
private readonly INotificationRepository _notificationRepository; | ||
private readonly IEmailServices _emailServices; | ||
|
||
public async Task<IActionResult> Handle(SendNotificationEmailCommand request, CancellationToken cancellationToken) | ||
{ | ||
bool create = false; | ||
Domain.Notification notification = await _notificationRepository.GetByCorrelationId(request.AggregateId); | ||
|
||
if (notification != null && notification.Sent.Any(c => !c.Success)) | ||
throw new DomainException("Already processed"); | ||
|
||
if (notification is null) | ||
{ | ||
create = true; | ||
notification = Create(request); | ||
} | ||
|
||
await notification.Send(_emailServices); | ||
|
||
if(create) | ||
_notificationRepository.Add(notification); | ||
else | ||
_notificationRepository.Update(notification); | ||
|
||
await _notificationRepository.unitOfWork.Commit(); | ||
|
||
return new OkResult(); | ||
} | ||
|
||
private Domain.Notification Create(SendNotificationEmailCommand request) | ||
{ | ||
var parameters = request.Params.Select(c => new Parameter(c.Key, c.Value)).ToList(); | ||
return new Domain.Notification(request.AggregateId.ToString(), request.Recipient, ENotificationType.Email , parameters); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...ication.Worker/Application/Commands/Send/Handlers/SendNotificationLetterCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Notification.Core.Common.Domain; | ||
using Notification.Core.Domain.Enums; | ||
using Notification.Worker.Data.Repositories.Interfaces; | ||
using Notification.Worker.Domain.Entities; | ||
using Notification.Worker.Domain.Services.Interfaces; | ||
|
||
namespace Notification.Worker.Application.Commands.Handlers; | ||
|
||
public class SendNotificationLetterCommandHandler : IRequestHandler<SendNotificationLetterCommand, IActionResult> | ||
{ | ||
public SendNotificationLetterCommandHandler(INotificationRepository notificationRepository, ILetterServices letterServices) | ||
{ | ||
_notificationRepository = notificationRepository; | ||
_letterServices = letterServices; | ||
} | ||
|
||
private readonly INotificationRepository _notificationRepository; | ||
private readonly ILetterServices _letterServices; | ||
|
||
public async Task<IActionResult> Handle(SendNotificationLetterCommand request, CancellationToken cancellationToken) | ||
{ | ||
bool create = false; | ||
Domain.Notification notification = await _notificationRepository.GetByCorrelationId(request.AggregateId); | ||
|
||
if (notification != null && notification.Sent.Any(c => !c.Success)) | ||
throw new DomainException("Already processed"); | ||
|
||
if (notification is null) | ||
{ | ||
create = true; | ||
notification = Create(request); | ||
} | ||
|
||
await notification.Send(_letterServices); | ||
|
||
if(create) | ||
_notificationRepository.Add(notification); | ||
else | ||
_notificationRepository.Update(notification); | ||
|
||
await _notificationRepository.unitOfWork.Commit(); | ||
|
||
return new OkResult(); | ||
} | ||
|
||
private Domain.Notification Create(SendNotificationLetterCommand request) | ||
{ | ||
var parameters = request.Params.Select(c => new Parameter(c.Key, c.Value)).ToList(); | ||
return new Domain.Notification(request.AggregateId.ToString(), request.Recipient, ENotificationType.Email , parameters); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...ification.Worker/Application/Commands/Send/Handlers/SendNotificationPushCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Notification.Core.Common.Domain; | ||
using Notification.Core.Domain.Enums; | ||
using Notification.Worker.Data.Repositories.Interfaces; | ||
using Notification.Worker.Domain.Entities; | ||
using Notification.Worker.Domain.Services.Interfaces; | ||
|
||
namespace Notification.Worker.Application.Commands.Handlers; | ||
|
||
public class SendNotificationPushCommandHandler : IRequestHandler<SendNotificationPushCommand, IActionResult> | ||
{ | ||
public SendNotificationPushCommandHandler(INotificationRepository notificationRepository, IPushServices pushServices) | ||
{ | ||
_notificationRepository = notificationRepository; | ||
_pushServices = pushServices; | ||
} | ||
|
||
private readonly INotificationRepository _notificationRepository; | ||
private readonly IPushServices _pushServices; | ||
|
||
public async Task<IActionResult> Handle(SendNotificationPushCommand request, CancellationToken cancellationToken) | ||
{ | ||
bool create = false; | ||
Domain.Notification notification = await _notificationRepository.GetByCorrelationId(request.AggregateId); | ||
|
||
if (notification != null && notification.Sent.Any(c => !c.Success)) | ||
throw new DomainException("Already processed"); | ||
|
||
if (notification is null) | ||
{ | ||
create = true; | ||
notification = Create(request); | ||
} | ||
|
||
await notification.Send(_pushServices); | ||
|
||
if(create) | ||
_notificationRepository.Add(notification); | ||
else | ||
_notificationRepository.Update(notification); | ||
|
||
await _notificationRepository.unitOfWork.Commit(); | ||
|
||
return new OkResult(); | ||
} | ||
private Domain.Notification Create(SendNotificationPushCommand request) | ||
{ | ||
var parameters = request.Params.Select(c => new Parameter(c.Key, c.Value)).ToList(); | ||
return new Domain.Notification(request.AggregateId.ToString(), request.Recipient, ENotificationType.Email , parameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ation.Worker/Application/Commands/Send/Handlers/SendNotificationWhatsAppCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Notification.Core.Common.Domain; | ||
using Notification.Core.Domain.Enums; | ||
using Notification.Worker.Data.Repositories.Interfaces; | ||
using Notification.Worker.Domain.Entities; | ||
using Notification.Worker.Domain.Services.Interfaces; | ||
|
||
namespace Notification.Worker.Application.Commands.Handlers; | ||
|
||
public class SendNotificationWhatsAppCommandHandler: IRequestHandler<SendNotificationWhatsAppCommand, IActionResult> | ||
{ | ||
public SendNotificationWhatsAppCommandHandler(INotificationRepository notificationRepository, IWhatsAppServices whatsAppServices) | ||
{ | ||
_notificationRepository = notificationRepository; | ||
_whatsAppServices = whatsAppServices; | ||
} | ||
|
||
private readonly INotificationRepository _notificationRepository; | ||
private readonly IWhatsAppServices _whatsAppServices; | ||
|
||
public async Task<IActionResult> Handle(SendNotificationWhatsAppCommand request, CancellationToken cancellationToken) | ||
{ | ||
bool create = false; | ||
Domain.Notification notification = await _notificationRepository.GetByCorrelationId(request.AggregateId); | ||
|
||
if (notification != null && notification.Sent.Any(c => !c.Success)) | ||
throw new DomainException("Already processed"); | ||
|
||
if (notification is null) | ||
{ | ||
create = true; | ||
notification = Create(request); | ||
} | ||
|
||
await notification.Send(_whatsAppServices); | ||
|
||
if(create) | ||
_notificationRepository.Add(notification); | ||
else | ||
_notificationRepository.Update(notification); | ||
|
||
await _notificationRepository.unitOfWork.Commit(); | ||
|
||
return new OkResult(); | ||
} | ||
|
||
private Domain.Notification Create(SendNotificationWhatsAppCommand request) | ||
{ | ||
var parameters = request.Params.Select(c => new Parameter(c.Key, c.Value)).ToList(); | ||
return new Domain.Notification(request.AggregateId.ToString(), request.Recipient, ENotificationType.Email , parameters); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/Worker/Notification.Worker/Application/Commands/Send/SendNotificationLetterCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Notification.Worker.Application.Commands.Send.Base; | ||
|
||
namespace Notification.Worker.Application.Commands; | ||
|
||
public class SendNotificationLetterCommand : SendNotificationCommand | ||
{ | ||
public SendNotificationLetterCommand(CreateNotificationCommand request) : base(request) | ||
{ | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Worker/Notification.Worker/Application/Commands/Send/SendNotificationPushCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Notification.Worker.Application.Commands.Send.Base; | ||
|
||
namespace Notification.Worker.Application.Commands; | ||
|
||
public class SendNotificationPushCommand : SendNotificationCommand | ||
{ | ||
public SendNotificationPushCommand(CreateNotificationCommand request) : base(request) | ||
{ | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Worker/Notification.Worker/Application/Commands/Send/SendNotificationWhatsAppCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Notification.Worker.Application.Commands.Send.Base; | ||
|
||
namespace Notification.Worker.Application.Commands; | ||
|
||
public class SendNotificationWhatsAppCommand : SendNotificationCommand | ||
{ | ||
public SendNotificationWhatsAppCommand(CreateNotificationCommand request) : base(request) | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.