diff --git a/ClubService.Application/EventHandlers/TournamentEventHandlers/TournamentConfirmedEventHandler.cs b/ClubService.Application/EventHandlers/TournamentEventHandlers/TournamentConfirmedEventHandler.cs index 13de8dba..ef4b8e99 100644 --- a/ClubService.Application/EventHandlers/TournamentEventHandlers/TournamentConfirmedEventHandler.cs +++ b/ClubService.Application/EventHandlers/TournamentEventHandlers/TournamentConfirmedEventHandler.cs @@ -27,11 +27,11 @@ public async Task Handle(DomainEnvelope domainEnvelope) var tournamentConfirmedEvent = (TournamentConfirmedEvent)domainEnvelope.EventData; var tennisClubReadModel = - await tennisClubReadModelRepository.GetTennisClubById(tournamentConfirmedEvent.ClubId); + await tennisClubReadModelRepository.GetTennisClubById(tournamentConfirmedEvent.Tournament.ClubId); if (tennisClubReadModel == null) { - loggerService.LogTennisClubNotFound(tournamentConfirmedEvent.ClubId); + loggerService.LogTennisClubNotFound(tournamentConfirmedEvent.Tournament.ClubId); throw new TennisClubNotFoundException(domainEnvelope.EntityId); } @@ -42,7 +42,8 @@ public async Task Handle(DomainEnvelope domainEnvelope) foreach (var member in members) { var emailMessage = new EmailMessage(Guid.NewGuid(), member.Email, - tournamentConfirmedEvent.Name, tournamentConfirmedEvent.Description, DateTime.UtcNow); + tournamentConfirmedEvent.Tournament.Name, tournamentConfirmedEvent.Tournament.Description, + DateTime.UtcNow); await emailOutboxRepository.Add(emailMessage); } diff --git a/ClubService.Domain/Event/Tournament/TournamentConfirmedEvent.cs b/ClubService.Domain/Event/Tournament/TournamentConfirmedEvent.cs index 4a0f87b9..5ef1aadb 100644 --- a/ClubService.Domain/Event/Tournament/TournamentConfirmedEvent.cs +++ b/ClubService.Domain/Event/Tournament/TournamentConfirmedEvent.cs @@ -1,30 +1,6 @@ -using ClubService.Domain.Model.Entity; -using ClubService.Domain.Model.Enum; - namespace ClubService.Domain.Event.Tournament; -public class TournamentConfirmedEvent( - Guid id, - Guid clubId, - bool isCanceled, - string name, - string description, - int maximumParticipants, - HashSet courts, - HashSet days, - HashSet participants, - int version, - TournamentStatus status) : ITournamentDomainEvent +public class TournamentConfirmedEvent(Model.Entity.Tournament tournament) : ITournamentDomainEvent { - public Guid Id { get; } = id; - public Guid ClubId { get; } = clubId; - public bool IsCanceled { get; } = isCanceled; - public string Name { get; } = name; - public string Description { get; } = description; - public int MaximumParticipants { get; } = maximumParticipants; - public HashSet Courts { get; } = courts; - public HashSet Days { get; } = days; - public HashSet Participants { get; } = participants; - public int Version { get; } = version; - public TournamentStatus Status { get; } = status; + public Model.Entity.Tournament Tournament { get; } = tournament; } \ No newline at end of file diff --git a/ClubService.Domain/Model/Entity/Tournament.cs b/ClubService.Domain/Model/Entity/Tournament.cs new file mode 100644 index 00000000..8596b37e --- /dev/null +++ b/ClubService.Domain/Model/Entity/Tournament.cs @@ -0,0 +1,29 @@ +using ClubService.Domain.Model.Enum; + +namespace ClubService.Domain.Model.Entity; + +public class Tournament( + Guid id, + Guid clubId, + bool isCanceled, + string name, + string description, + int maximumParticipants, + HashSet courts, + HashSet days, + HashSet participants, + int version, + TournamentStatus status) +{ + public Guid Id { get; } = id; + public Guid ClubId { get; } = clubId; + public bool IsCanceled { get; } = isCanceled; + public string Name { get; } = name; + public string Description { get; } = description; + public int MaximumParticipants { get; } = maximumParticipants; + public HashSet Courts { get; } = courts; + public HashSet Days { get; } = days; + public HashSet Participants { get; } = participants; + public int Version { get; } = version; + public TournamentStatus Status { get; } = status; +} \ No newline at end of file diff --git a/ClubService.Domain/Model/Enum/TournamentStatus.cs b/ClubService.Domain/Model/Enum/TournamentStatus.cs index 8be1ca94..35f72a0d 100644 --- a/ClubService.Domain/Model/Enum/TournamentStatus.cs +++ b/ClubService.Domain/Model/Enum/TournamentStatus.cs @@ -2,8 +2,5 @@ namespace ClubService.Domain.Model.Enum; public enum TournamentStatus { - PENDING, - CREATED, - REJECTED, - CANCELED + CONFIRMED } \ No newline at end of file diff --git a/ClubService.Domain/ReadModel/TournamentReadModel.cs b/ClubService.Domain/ReadModel/TournamentReadModel.cs index 43bda4db..cfa2a9f3 100644 --- a/ClubService.Domain/ReadModel/TournamentReadModel.cs +++ b/ClubService.Domain/ReadModel/TournamentReadModel.cs @@ -21,13 +21,13 @@ private TournamentReadModel(Guid tournamentId, Guid tennisClubId, string name, D public static TournamentReadModel FromDomainEvent(TournamentConfirmedEvent tournamentConfirmedEvent) { - var startDate = tournamentConfirmedEvent.Days.OrderBy(d => d.Day).First(); - var endDate = tournamentConfirmedEvent.Days.OrderBy(d => d.Day).Last(); + var startDate = tournamentConfirmedEvent.Tournament.Days.OrderBy(d => d.Day).First(); + var endDate = tournamentConfirmedEvent.Tournament.Days.OrderBy(d => d.Day).Last(); return new TournamentReadModel( - tournamentConfirmedEvent.Id, - tournamentConfirmedEvent.ClubId, - tournamentConfirmedEvent.Name, + tournamentConfirmedEvent.Tournament.Id, + tournamentConfirmedEvent.Tournament.ClubId, + tournamentConfirmedEvent.Tournament.Name, startDate.Day, endDate.Day ); diff --git a/ClubService.Domain/Repository/ILoggerService.cs b/ClubService.Domain/Repository/ILoggerService.cs index 176b4b4d..2a0b2545 100644 --- a/ClubService.Domain/Repository/ILoggerService.cs +++ b/ClubService.Domain/Repository/ILoggerService.cs @@ -64,5 +64,6 @@ public interface ILoggerService void LogJsonMissingProperties(string jsonValue); void LogEmailMessageRelayStop(); void LogSystemOperatorRegistered(Guid id); + void LogInvalidEMailAddress(string emailAddress); void LogDuplicateSeedData(); } \ No newline at end of file diff --git a/ClubService.Infrastructure/EventHandling/EventParser.cs b/ClubService.Infrastructure/EventHandling/EventParser.cs index 7c9a9803..64dec917 100644 --- a/ClubService.Infrastructure/EventHandling/EventParser.cs +++ b/ClubService.Infrastructure/EventHandling/EventParser.cs @@ -26,8 +26,8 @@ public static DomainEnvelope ParseEvent(JsonElement jsonEvent) var eventId = Guid.Parse(eventIdStr); var entityId = Guid.Parse(entityIdStr); - var eventType = (EventType)Enum.Parse(typeof(EventType), eventTypeStr); - var entityType = (EntityType)Enum.Parse(typeof(EntityType), entityTypeStr); + var eventType = (EventType)Enum.Parse(typeof(EventType), eventTypeStr, true); + var entityType = (EntityType)Enum.Parse(typeof(EntityType), entityTypeStr, true); var timestamp = DateTime.Parse(timestampStr).ToUniversalTime(); var deserializedEventData = EventDeserializer.DeserializeEventData(eventType, eventData); diff --git a/ClubService.Infrastructure/Logging/LoggerService.cs b/ClubService.Infrastructure/Logging/LoggerService.cs index 284647f8..2c36a5d7 100644 --- a/ClubService.Infrastructure/Logging/LoggerService.cs +++ b/ClubService.Infrastructure/Logging/LoggerService.cs @@ -320,6 +320,11 @@ public void LogSystemOperatorRegistered(Guid id) { logger.LogInformation("Registered system operator with id '{id}'.", id); } + + public void LogInvalidEMailAddress(string emailAddress) + { + logger.LogError("The following email address is invalid: {emailMessageRecipientEMailAddress}", emailAddress); + } public void LogDuplicateSeedData() { diff --git a/ClubService.Infrastructure/Mail/EmailMessageRelay.cs b/ClubService.Infrastructure/Mail/EmailMessageRelay.cs index 426b22cf..f7f7f65f 100644 --- a/ClubService.Infrastructure/Mail/EmailMessageRelay.cs +++ b/ClubService.Infrastructure/Mail/EmailMessageRelay.cs @@ -12,7 +12,7 @@ public class EmailMessageRelay : BackgroundService { private readonly ILoggerService _loggerService; private readonly int _pollingInterval; - private readonly string _senderEmailAddress; + private readonly MailAddress _senderEmailAddress; private readonly IServiceProvider _serviceProvider; private readonly SmtpClient _smtpClient; @@ -24,7 +24,7 @@ public EmailMessageRelay( _serviceProvider = serviceProvider; _loggerService = loggerService; _pollingInterval = smtpConfiguration.Value.PollingInterval; - _senderEmailAddress = smtpConfiguration.Value.SenderEmailAddress; + _senderEmailAddress = new MailAddress(smtpConfiguration.Value.SenderEmailAddress); _smtpClient = new SmtpClient(smtpConfiguration.Value.Host, smtpConfiguration.Value.Port); _smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; } @@ -41,7 +41,18 @@ private async Task SendEmails() { await transactionManager.TransactionScope(async () => { - var mailMessage = new MailMessage(_senderEmailAddress, emailMessage.RecipientEMailAddress) + MailAddress recipientEmailAddress; + try + { + recipientEmailAddress = new MailAddress(emailMessage.RecipientEMailAddress); + } + catch (FormatException) + { + _loggerService.LogInvalidEMailAddress(emailMessage.RecipientEMailAddress); + throw; + } + + var mailMessage = new MailMessage(_senderEmailAddress, recipientEmailAddress) { Subject = emailMessage.Subject, Body = emailMessage.Body diff --git a/deployment/configs/mailhog-config.yaml b/deployment/configs/mailhog-config.yaml index 5a7a2c72..8f2bb69c 100644 --- a/deployment/configs/mailhog-config.yaml +++ b/deployment/configs/mailhog-config.yaml @@ -4,4 +4,5 @@ metadata: name: club-service-mailhog-config data: mailhog-host: "club-service-mailhog-service" - mailhog-smtp-port: "1025" \ No newline at end of file + mailhog-smtp-port: "1025" + smtp-sender-email-address: "admin@thc-dornbirn.at" \ No newline at end of file diff --git a/deployment/deployments/club-service-deployment.yaml b/deployment/deployments/club-service-deployment.yaml index 8d210f7c..5222b422 100644 --- a/deployment/deployments/club-service-deployment.yaml +++ b/deployment/deployments/club-service-deployment.yaml @@ -85,6 +85,6 @@ spec: key: mailhog-smtp-port - name: SMTP_SENDER_EMAIL_ADDRESS valueFrom: - secretKeyRef: - name: club-service-mailhog-secret + configMapKeyRef: + name: club-service-mailhog-config key: smtp-sender-email-address \ No newline at end of file diff --git a/deployment/secrets/mailhog-secret.yaml b/deployment/secrets/mailhog-secret.yaml deleted file mode 100644 index 64843f0c..00000000 --- a/deployment/secrets/mailhog-secret.yaml +++ /dev/null @@ -1,7 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: club-service-mailhog-secret -type: Opaque -stringData: - smtp-sender-email-address: YWRtaW5AdGhjZG9ybmJpcm4uYXQK \ No newline at end of file