-
Notifications
You must be signed in to change notification settings - Fork 0
Tast/ssad 93/create email microservice #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Darsicl
wants to merge
32
commits into
dev
Choose a base branch
from
tast/SSAD-93/Create_EmailMicroservice
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
9d005be
feat: create microservice
Darsicl 9566399
feat: create entity, hadlers, dbcontext, mapping, dtos, validation, s…
Darsicl 1218d73
feat: finish emailservice, created docker-compose
Darsicl 2f46d9c
feat: create appsetings
Darsicl 88efed7
feat: crate rabbitmq consumer
Darsicl 037d6b5
fix: prepared for migration
Darsicl 636ddf3
fix: fix appsettings
Darsicl ba87c76
fix: fix problem with migration
Darsicl e9491a3
refactor: removed unusing files
Darsicl d3ddcc5
feat: create endpoint for email
Darsicl 1df68e0
fix: change email endpoint, on masstransit publisher
Darsicl d4cbea5
fix: fix consumer setting for masstransit
Darsicl 9490658
feat: remove old logic for email
Darsicl 8f44931
fix: fix handfire configuration with sql
Darsicl 1c7c496
test: implement test for mediatr email
Darsicl 55303d2
refactor: rename feedbackEntity in Email Entity
Darsicl 21c2a4b
refactor: rename feedbackMethods into Email
Darsicl 5083966
refactor: preparing for db update
Darsicl 06470cc
refactor: renamed test from feedback to email
Darsicl 1653f03
refactor: renamed main api endpoint from feedback to email
Darsicl a359cff
Merge branch 'dev' into tast/SSAD-93/Create_EmailMicroservice
Darsicl eb121c8
refactor: fix spacing
Darsicl 40d650e
chore: stop tracking dockerpassword.env
Darsicl 17c9520
fix: change order of migration down build
Darsicl 9f155a2
chore: stop tracking dockerpassword.env
Darsicl ffa66c5
fix: replace hardcoder RabbitMQ configuration
Darsicl 77e7b88
fix: add construction try-catch for emailService
Darsicl 1e75cb9
fix: changes access to hangfire, for differnt enviroment
Darsicl 0af405b
fix: change attribute validation on 1000 from 100 like entity allow
Darsicl 898a44c
fix: finish rename in bll and test
Darsicl 65f6736
fix: fix inmemory version different
Darsicl 80f11a2
fix: fix validator settings into test
Darsicl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,14 +1,18 @@ | ||
| using System.ComponentModel.DataAnnotations; | ||
| using System.ComponentModel.DataAnnotations; | ||
|
|
||
| namespace Streetcode.BLL.DTO.Email | ||
| { | ||
| public class EmailDTO | ||
| { | ||
| public EmailDTO() | ||
| { | ||
| } | ||
|
|
||
| [MaxLength(80)] | ||
| public string From { get; set; } | ||
|
|
||
| [Required] | ||
| [StringLength(500, MinimumLength = 1)] | ||
| public string Content { get; set; } | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
42 changes: 0 additions & 42 deletions
42
Streetcode/Streetcode.BLL/MediatR/Email/SendEmailHandler.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
Streetcode/Streetcode.Email.BLL/Configs/EmailConfiguration.cs
This file contains hidden or 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,14 @@ | ||
| namespace Streetcode.Email.BLL.Configs | ||
| { | ||
| public class EmailConfiguration | ||
| { | ||
| public const string SectionName = "EmailConfiguration"; | ||
|
|
||
| public string FromAddress { get; set; } | ||
| public string AdminAddress { get; set; } | ||
| public string SmtpServer { get; set; } | ||
| public int Port { get; set; } | ||
| public string SmtpUser { get; set; } | ||
| public string SmtpPassword { get; set; } | ||
| } | ||
| } |
This file contains hidden or 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 @@ | ||
| namespace Streetcode.Email.BLL.DTO | ||
| { | ||
| public class EmailDTO | ||
| { | ||
| public EmailDTO() | ||
| { | ||
|
Darsicl marked this conversation as resolved.
|
||
| } | ||
| public string From { get; set; } | ||
| public string Content { get; set; } | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
Streetcode/Streetcode.Email.BLL/Exceptions/ValidationException.cs
This file contains hidden or 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,29 @@ | ||
| using FluentValidation.Results; | ||
|
|
||
| namespace Streetcode.Email.BLL.Exceptions | ||
| { | ||
| public class ValidationException : Exception | ||
| { | ||
| public ValidationException() : base("One or more validation failures have occurred.") | ||
| { | ||
| Errors = new Dictionary<string, string[]>(); | ||
| } | ||
|
|
||
| public ValidationException(IEnumerable<ValidationFailure> failures) : this() | ||
| { | ||
| Errors = failures | ||
| .GroupBy(e => e.PropertyName, e => e.ErrorMessage) | ||
| .ToDictionary(failureGroup => failureGroup.Key, failureGroup => failureGroup.ToArray()); | ||
| } | ||
|
|
||
| public ValidationException(string propertyName, string errorMessage) : this() | ||
| { | ||
| Errors = new Dictionary<string, string[]> | ||
| { | ||
|
Darsicl marked this conversation as resolved.
|
||
| { propertyName, new[] { errorMessage } } | ||
| }; | ||
| } | ||
|
|
||
| public IDictionary<string, string[]> Errors { get; } | ||
| } | ||
| } | ||
This file contains hidden or 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,9 @@ | ||
| using Streetcode.Email.BLL.DTO; | ||
|
|
||
| namespace Streetcode.Email.BLL.Interfaces | ||
| { | ||
| public interface IEmailService | ||
| { | ||
| Task SendEmailAsync(EmailDTO email); | ||
| } | ||
| } |
This file contains hidden or 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,14 @@ | ||
| using AutoMapper; | ||
| using Streetcode.Email.BLL.DTO; | ||
| using EmailEntity = Streetcode.Email.DAL.Entities.Email; | ||
|
|
||
| namespace Streetcode.Email.BLL.Mapping | ||
| { | ||
| public class EmailProfile : Profile | ||
| { | ||
| public EmailProfile() | ||
| { | ||
| CreateMap<EmailEntity, EmailDTO>().ReverseMap(); | ||
| } | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
Streetcode/Streetcode.Email.BLL/MediatR/Behavior/ValidatorBehavior.cs
This file contains hidden or 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,33 @@ | ||
| using FluentValidation; | ||
| using MediatR; | ||
|
|
||
| namespace Streetcode.Email.BLL.MediatR.Behavior | ||
| { | ||
| public class ValidatorBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> | ||
| where TRequest : IRequest<TResponse> | ||
| { | ||
| private readonly IEnumerable<IValidator<TRequest>> _validators; | ||
|
|
||
| public ValidatorBehavior(IEnumerable<IValidator<TRequest>> validators) | ||
| { | ||
| _validators = validators; | ||
| } | ||
|
|
||
| public Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken) | ||
| { | ||
| var context = new ValidationContext<TRequest>(request); | ||
| var failures = _validators | ||
| .Select(v => v.Validate(context)) | ||
| .SelectMany(result => result.Errors) | ||
| .Where(f => f != null) | ||
| .ToList(); | ||
|
|
||
| if (failures.Count != 0) | ||
| { | ||
| throw new Exceptions.ValidationException(failures); | ||
| } | ||
|
|
||
| return next(); | ||
| } | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
Streetcode/Streetcode.Email.BLL/MediatR/Email/EmailDTOValidator.cs
This file contains hidden or 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,20 @@ | ||
| using FluentValidation; | ||
| using Streetcode.Email.BLL.DTO; | ||
|
|
||
| namespace Streetcode.Email.BLL.MediatR.Email | ||
| { | ||
| public class EmailDTOValidator : AbstractValidator<EmailDTO> | ||
| { | ||
| public EmailDTOValidator() | ||
| { | ||
| RuleFor(x => x.From) | ||
| .NotEmpty() | ||
| .EmailAddress(); | ||
|
|
||
| RuleFor(x => x.Content) | ||
| .NotEmpty() | ||
| .MinimumLength(5) | ||
| .MaximumLength(1000); | ||
| } | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
Streetcode/Streetcode.Email.BLL/MediatR/Email/SendEmailCommand.cs
This file contains hidden or 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,8 @@ | ||
| using FluentResults; | ||
| using MediatR; | ||
| using Streetcode.Email.BLL.DTO; | ||
|
|
||
| namespace Streetcode.Email.BLL.MediatR.Email | ||
| { | ||
| public record SendEmailCommand(EmailDTO email) : IRequest<Result<Unit>>; | ||
| } |
16 changes: 16 additions & 0 deletions
16
Streetcode/Streetcode.Email.BLL/MediatR/Email/SendEmailCommandValidator.cs
This file contains hidden or 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,16 @@ | ||
| using FluentValidation; | ||
| using Streetcode.Resources; | ||
|
|
||
| namespace Streetcode.Email.BLL.MediatR.Email | ||
| { | ||
| public class SendEmailCommandValidator : AbstractValidator<SendEmailCommand> | ||
| { | ||
| public SendEmailCommandValidator() | ||
| { | ||
| RuleFor(x => x.email) | ||
| .NotNull() | ||
| .WithMessage(Messages.Error_CommandDataRequired) | ||
| .SetValidator(new EmailDTOValidator()); | ||
| } | ||
| } | ||
| } |
52 changes: 52 additions & 0 deletions
52
Streetcode/Streetcode.Email.BLL/MediatR/Email/SendEmailHandler.cs
This file contains hidden or 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 AutoMapper; | ||
| using FluentResults; | ||
| using Hangfire; | ||
| using MediatR; | ||
| using Microsoft.Extensions.Logging; | ||
| using Streetcode.Email.BLL.DTO; | ||
| using Streetcode.Email.BLL.Interfaces; | ||
| using Streetcode.Email.DAL.Persistence; | ||
| using Streetcode.Resources; | ||
| using EmailEntity = Streetcode.Email.DAL.Entities.Email; | ||
|
|
||
| namespace Streetcode.Email.BLL.MediatR.Email | ||
| { | ||
| public class SendEmailHandler : IRequestHandler<SendEmailCommand, Result<Unit>> | ||
| { | ||
| private readonly EmailDbContext _context; | ||
| private readonly IMapper _mapper; | ||
| private readonly ILogger<SendEmailHandler> _logger; | ||
| private readonly IBackgroundJobClient _backgroundJob; | ||
|
|
||
| public SendEmailHandler(EmailDbContext context, IMapper mapper, ILogger<SendEmailHandler> logger, IBackgroundJobClient backgroundJob) | ||
| { | ||
| _context = context; | ||
| _mapper = mapper; | ||
| _logger = logger; | ||
| _backgroundJob = backgroundJob; | ||
| } | ||
|
|
||
| public async Task<Result<Unit>> Handle(SendEmailCommand request, CancellationToken cancellationToken) | ||
| { | ||
| var EmailEntity = _mapper.Map<EmailEntity>(request.email); | ||
|
|
||
| _context.Emails.Add(EmailEntity); | ||
|
|
||
| var rowsAffected = await _context.SaveChangesAsync(cancellationToken); | ||
|
|
||
| if (rowsAffected <= 0) | ||
| { | ||
| var errorMsg = Messages.Error_FailedToCreateEntity; | ||
| _logger.LogError(errorMsg); | ||
| return Result.Fail(errorMsg); | ||
| } | ||
|
|
||
| _backgroundJob.Enqueue<IEmailService>(emailService => | ||
| emailService.SendEmailAsync(request.email)); | ||
|
|
||
| _logger.LogInformation("Email saved to DB and email task enqueued for {Email}", request.email.From); | ||
|
|
||
| return Result.Ok(Unit.Value); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.