Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9d005be
feat: create microservice
Darsicl Feb 23, 2026
9566399
feat: create entity, hadlers, dbcontext, mapping, dtos, validation, s…
Darsicl Feb 25, 2026
1218d73
feat: finish emailservice, created docker-compose
Darsicl Feb 25, 2026
2f46d9c
feat: create appsetings
Darsicl Feb 25, 2026
88efed7
feat: crate rabbitmq consumer
Darsicl Feb 26, 2026
037d6b5
fix: prepared for migration
Darsicl Feb 26, 2026
636ddf3
fix: fix appsettings
Darsicl Feb 26, 2026
ba87c76
fix: fix problem with migration
Darsicl Feb 27, 2026
e9491a3
refactor: removed unusing files
Darsicl Feb 27, 2026
d3ddcc5
feat: create endpoint for email
Darsicl Feb 27, 2026
1df68e0
fix: change email endpoint, on masstransit publisher
Darsicl Mar 1, 2026
d4cbea5
fix: fix consumer setting for masstransit
Darsicl Mar 1, 2026
9490658
feat: remove old logic for email
Darsicl Mar 1, 2026
8f44931
fix: fix handfire configuration with sql
Darsicl Mar 2, 2026
1c7c496
test: implement test for mediatr email
Darsicl Mar 2, 2026
55303d2
refactor: rename feedbackEntity in Email Entity
Darsicl Mar 2, 2026
21c2a4b
refactor: rename feedbackMethods into Email
Darsicl Mar 2, 2026
5083966
refactor: preparing for db update
Darsicl Mar 2, 2026
06470cc
refactor: renamed test from feedback to email
Darsicl Mar 2, 2026
1653f03
refactor: renamed main api endpoint from feedback to email
Darsicl Mar 2, 2026
a359cff
Merge branch 'dev' into tast/SSAD-93/Create_EmailMicroservice
Darsicl Mar 2, 2026
eb121c8
refactor: fix spacing
Darsicl Mar 2, 2026
40d650e
chore: stop tracking dockerpassword.env
Darsicl Mar 2, 2026
17c9520
fix: change order of migration down build
Darsicl Mar 2, 2026
9f155a2
chore: stop tracking dockerpassword.env
Darsicl Mar 2, 2026
ffa66c5
fix: replace hardcoder RabbitMQ configuration
Darsicl Mar 2, 2026
77e7b88
fix: add construction try-catch for emailService
Darsicl Mar 2, 2026
1e75cb9
fix: changes access to hangfire, for differnt enviroment
Darsicl Mar 2, 2026
0af405b
fix: change attribute validation on 1000 from 100 like entity allow
Darsicl Mar 2, 2026
898a44c
fix: finish rename in bll and test
Darsicl Mar 2, 2026
65f6736
fix: fix inmemory version different
Darsicl Mar 2, 2026
80f11a2
fix: fix validator settings into test
Darsicl Mar 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Streetcode/Streetcode.BLL/DTO/Email/EmailDTO.cs
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()
{
Comment thread
Darsicl marked this conversation as resolved.
}

[MaxLength(80)]
public string From { get; set; }

[Required]
[StringLength(500, MinimumLength = 1)]
public string Content { get; set; }
}
}
}
9 changes: 0 additions & 9 deletions Streetcode/Streetcode.BLL/Interfaces/Email/IEmailService.cs

This file was deleted.

6 changes: 0 additions & 6 deletions Streetcode/Streetcode.BLL/MediatR/Email/SendEmailCommand.cs

This file was deleted.

42 changes: 0 additions & 42 deletions Streetcode/Streetcode.BLL/MediatR/Email/SendEmailHandler.cs

This file was deleted.

70 changes: 0 additions & 70 deletions Streetcode/Streetcode.BLL/Services/Email/EmailService.cs

This file was deleted.

14 changes: 14 additions & 0 deletions Streetcode/Streetcode.Email.BLL/Configs/EmailConfiguration.cs
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; }
}
}
11 changes: 11 additions & 0 deletions Streetcode/Streetcode.Email.BLL/DTO/EmailDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Streetcode.Email.BLL.DTO
{
public class EmailDTO
{
public EmailDTO()
{
Comment thread
Darsicl marked this conversation as resolved.
}
public string From { get; set; }
public string Content { get; set; }
}
}
29 changes: 29 additions & 0 deletions Streetcode/Streetcode.Email.BLL/Exceptions/ValidationException.cs
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[]>
{
Comment thread
Darsicl marked this conversation as resolved.
{ propertyName, new[] { errorMessage } }
};
}

public IDictionary<string, string[]> Errors { get; }
}
}
9 changes: 9 additions & 0 deletions Streetcode/Streetcode.Email.BLL/Interfaces/IEmailService.cs
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);
}
}
14 changes: 14 additions & 0 deletions Streetcode/Streetcode.Email.BLL/Mapping/EmailProfile.cs
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();
}
}
}
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 Streetcode/Streetcode.Email.BLL/MediatR/Email/EmailDTOValidator.cs
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);
}
}
}
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>>;
}
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 Streetcode/Streetcode.Email.BLL/MediatR/Email/SendEmailHandler.cs
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);
}
}
}
Loading
Loading