Skip to content

Commit

Permalink
Event Type Constants
Browse files Browse the repository at this point in the history
  • Loading branch information
phongnguyend committed Sep 6, 2023
1 parent 346eb08 commit 574549a
Show file tree
Hide file tree
Showing 30 changed files with 113 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ClassifiedAds.CrossCuttingConcerns.ExtensionMethods;
using ClassifiedAds.Domain.Repositories;
using ClassifiedAds.Infrastructure.Identity;
using ClassifiedAds.Services.Product.Constants;
using ClassifiedAds.Services.Product.Entities;
using MediatR;
using System;
Expand Down Expand Up @@ -45,7 +46,7 @@ public async Task Handle(AddAuditLogEntryCommand command, CancellationToken canc

await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
{
EventType = "AUDIT_LOG_ENTRY_CREATED",
EventType = EventTypeConstants.AuditLogEntryCreated,
TriggeredById = _currentUser.UserId,
CreatedDateTime = auditLog.CreatedDateTime,
ObjectId = auditLog.Id.ToString(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ClassifiedAds.CrossCuttingConcerns.DateTimes;
using ClassifiedAds.Domain.Infrastructure.MessageBrokers;
using ClassifiedAds.Domain.Repositories;
using ClassifiedAds.Services.Product.Constants;
using ClassifiedAds.Services.Product.DTOs;
using ClassifiedAds.Services.Product.Entities;
using Dapr.Client;
Expand Down Expand Up @@ -50,7 +51,7 @@ public async Task Handle(PublishEventsCommand command, CancellationToken cancell

foreach (var eventLog in events)
{
if (eventLog.EventType == "AUDIT_LOG_ENTRY_CREATED")
if (eventLog.EventType == EventTypeConstants.AuditLogEntryCreated)
{
var logEntry = JsonSerializer.Deserialize<AuditLogEntry>(eventLog.Message);
await _messageBus.SendAsync(new AuditLogCreatedEvent { AuditLog = logEntry },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ClassifiedAds.Services.Product.Constants;

internal class EventTypeConstants
{
public const string ProductCreated = "PRODUCT_CREATED";
public const string ProductUpdated = "PRODUCT_UPDATED";
public const string ProductDeleted = "PRODUCT_DELETED";

public const string AuditLogEntryCreated = "AUDIT_LOG_ENTRY_CREATED";
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ClassifiedAds.Domain.Repositories;
using ClassifiedAds.Infrastructure.Identity;
using ClassifiedAds.Services.Product.Commands;
using ClassifiedAds.Services.Product.Constants;
using ClassifiedAds.Services.Product.Entities;
using MediatR;
using System;
Expand Down Expand Up @@ -42,7 +43,7 @@ public async Task HandleAsync(EntityCreatedEvent<Entities.Product> domainEvent,

await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
{
EventType = "PRODUCT_CREATED",
EventType = EventTypeConstants.ProductCreated,
TriggeredById = _currentUser.UserId,
CreatedDateTime = domainEvent.EventDateTime,
ObjectId = domainEvent.Entity.Id.ToString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ClassifiedAds.Domain.Repositories;
using ClassifiedAds.Infrastructure.Identity;
using ClassifiedAds.Services.Product.Commands;
using ClassifiedAds.Services.Product.Constants;
using ClassifiedAds.Services.Product.Entities;
using MediatR;
using System;
Expand Down Expand Up @@ -42,7 +43,7 @@ public async Task HandleAsync(EntityDeletedEvent<Entities.Product> domainEvent,

await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
{
EventType = "PRODUCT_DELETED",
EventType = EventTypeConstants.ProductDeleted,
TriggeredById = _currentUser.UserId,
CreatedDateTime = domainEvent.EventDateTime,
ObjectId = domainEvent.Entity.Id.ToString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ClassifiedAds.Domain.Repositories;
using ClassifiedAds.Infrastructure.Identity;
using ClassifiedAds.Services.Product.Commands;
using ClassifiedAds.Services.Product.Constants;
using ClassifiedAds.Services.Product.Entities;
using MediatR;
using System;
Expand Down Expand Up @@ -42,7 +43,7 @@ public async Task HandleAsync(EntityUpdatedEvent<Entities.Product> domainEvent,

await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
{
EventType = "PRODUCT_UPDATED",
EventType = EventTypeConstants.ProductUpdated,
TriggeredById = _currentUser.UserId,
CreatedDateTime = domainEvent.EventDateTime,
ObjectId = domainEvent.Entity.Id.ToString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ClassifiedAds.CrossCuttingConcerns.ExtensionMethods;
using ClassifiedAds.Domain.Repositories;
using ClassifiedAds.Infrastructure.Identity;
using ClassifiedAds.Services.Storage.Constants;
using ClassifiedAds.Services.Storage.Entities;
using System;
using System.Threading;
Expand Down Expand Up @@ -45,7 +46,7 @@ public async Task HandleAsync(AddAuditLogEntryCommand command, CancellationToken

await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
{
EventType = "AUDIT_LOG_ENTRY_CREATED",
EventType = EventTypeConstants.AuditLogEntryCreated,
TriggeredById = _currentUser.UserId,
CreatedDateTime = auditLog.CreatedDateTime,
ObjectId = auditLog.Id.ToString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ClassifiedAds.CrossCuttingConcerns.DateTimes;
using ClassifiedAds.Domain.Infrastructure.MessageBrokers;
using ClassifiedAds.Domain.Repositories;
using ClassifiedAds.Services.Storage.Constants;
using ClassifiedAds.Services.Storage.DTOs;
using ClassifiedAds.Services.Storage.Entities;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -46,15 +47,15 @@ public async Task HandleAsync(PublishEventsCommand command, CancellationToken ca

foreach (var eventLog in events)
{
if (eventLog.EventType == "FILEENTRY_CREATED")
if (eventLog.EventType == EventTypeConstants.FileEntryCreated)
{
await _messageBus.SendAsync(new FileUploadedEvent { FileEntry = JsonSerializer.Deserialize<FileEntry>(eventLog.Message) });
}
else if (eventLog.EventType == "FILEENTRY_DELETED")
else if (eventLog.EventType == EventTypeConstants.FileEntryDeleted)
{
await _messageBus.SendAsync(new FileDeletedEvent { FileEntry = JsonSerializer.Deserialize<FileEntry>(eventLog.Message) });
}
else if (eventLog.EventType == "AUDIT_LOG_ENTRY_CREATED")
else if (eventLog.EventType == EventTypeConstants.AuditLogEntryCreated)
{
var logEntry = JsonSerializer.Deserialize<AuditLogEntry>(eventLog.Message);
await _messageBus.SendAsync(new AuditLogCreatedEvent { AuditLog = logEntry },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ClassifiedAds.Services.Storage.Constants;

internal class EventTypeConstants
{
public const string FileEntryCreated = "FILEENTRY_CREATED";
public const string FileEntryUpdated = "FILEENTRY_UPDATED";
public const string FileEntryDeleted = "FILEENTRY_DELETED";

public const string AuditLogEntryCreated = "AUDIT_LOG_ENTRY_CREATED";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using ClassifiedAds.Domain.Repositories;
using ClassifiedAds.Infrastructure.Identity;
using ClassifiedAds.Services.Storage.Commands;
using ClassifiedAds.Services.Storage.Constants;
using ClassifiedAds.Services.Storage.Entities;
using System;
using System.Threading;
Expand Down Expand Up @@ -42,7 +43,7 @@ public async Task HandleAsync(EntityCreatedEvent<FileEntry> domainEvent, Cancell

await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
{
EventType = "FILEENTRY_CREATED",
EventType = EventTypeConstants.FileEntryCreated,
TriggeredById = _currentUser.UserId,
CreatedDateTime = domainEvent.EventDateTime,
ObjectId = domainEvent.Entity.Id.ToString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using ClassifiedAds.Domain.Repositories;
using ClassifiedAds.Infrastructure.Identity;
using ClassifiedAds.Services.Storage.Commands;
using ClassifiedAds.Services.Storage.Constants;
using ClassifiedAds.Services.Storage.Entities;
using System;
using System.Threading;
Expand Down Expand Up @@ -42,7 +43,7 @@ public async Task HandleAsync(EntityDeletedEvent<FileEntry> domainEvent, Cancell

await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
{
EventType = "FILEENTRY_DELETED",
EventType = EventTypeConstants.FileEntryDeleted,
TriggeredById = _currentUser.UserId,
CreatedDateTime = domainEvent.EventDateTime,
ObjectId = domainEvent.Entity.Id.ToString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using ClassifiedAds.Domain.Repositories;
using ClassifiedAds.Infrastructure.Identity;
using ClassifiedAds.Services.Storage.Commands;
using ClassifiedAds.Services.Storage.Constants;
using ClassifiedAds.Services.Storage.Entities;
using System;
using System.Threading;
Expand Down Expand Up @@ -42,7 +43,7 @@ public async Task HandleAsync(EntityUpdatedEvent<FileEntry> domainEvent, Cancell

await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
{
EventType = "FILEENTRY_UPDATED",
EventType = EventTypeConstants.FileEntryUpdated,
TriggeredById = _currentUser.UserId,
CreatedDateTime = domainEvent.EventDateTime,
ObjectId = domainEvent.Entity.Id.ToString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ClassifiedAds.Contracts.AuditLog.Services;
using ClassifiedAds.CrossCuttingConcerns.DateTimes;
using ClassifiedAds.Domain.Repositories;
using ClassifiedAds.Modules.Product.Constants;
using ClassifiedAds.Modules.Product.Entities;
using Microsoft.Extensions.Logging;
using System;
Expand Down Expand Up @@ -45,7 +46,7 @@ public async Task HandleAsync(PublishEventsCommand command, CancellationToken ca

foreach (var eventLog in events)
{
if (eventLog.EventType == "AUDIT_LOG_ENTRY_CREATED")
if (eventLog.EventType == EventTypeConstants.AuditLogEntryCreated)
{
var logEntry = JsonSerializer.Deserialize<Contracts.AuditLog.DTOs.AuditLogEntryDTO>(eventLog.Message);
await _externalAuditLogService.AddAsync(logEntry, eventLog.Id.ToString());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ClassifiedAds.Modules.Product.Constants;

internal class EventTypeConstants
{
public const string ProductCreated = "PRODUCT_CREATED";
public const string ProductUpdated = "PRODUCT_UPDATED";
public const string ProductDeleted = "PRODUCT_DELETED";

public const string AuditLogEntryCreated = "AUDIT_LOG_ENTRY_CREATED";
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ClassifiedAds.CrossCuttingConcerns.ExtensionMethods;
using ClassifiedAds.Domain.Events;
using ClassifiedAds.Domain.Repositories;
using ClassifiedAds.Modules.Product.Constants;
using ClassifiedAds.Modules.Product.Entities;
using System;
using System.Threading;
Expand Down Expand Up @@ -40,7 +41,7 @@ public async Task HandleAsync(EntityCreatedEvent<Entities.Product> domainEvent,

await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
{
EventType = "AUDIT_LOG_ENTRY_CREATED",
EventType = EventTypeConstants.AuditLogEntryCreated,
TriggeredById = _currentUser.UserId,
CreatedDateTime = auditLog.CreatedDateTime,
ObjectId = auditLog.Id.ToString(),
Expand All @@ -50,7 +51,7 @@ public async Task HandleAsync(EntityCreatedEvent<Entities.Product> domainEvent,

await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
{
EventType = "PRODUCT_CREATED",
EventType = EventTypeConstants.ProductCreated,
TriggeredById = _currentUser.UserId,
CreatedDateTime = domainEvent.EventDateTime,
ObjectId = domainEvent.Entity.Id.ToString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ClassifiedAds.CrossCuttingConcerns.ExtensionMethods;
using ClassifiedAds.Domain.Events;
using ClassifiedAds.Domain.Repositories;
using ClassifiedAds.Modules.Product.Constants;
using ClassifiedAds.Modules.Product.Entities;
using System;
using System.Threading;
Expand Down Expand Up @@ -40,7 +41,7 @@ public async Task HandleAsync(EntityDeletedEvent<Entities.Product> domainEvent,

await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
{
EventType = "AUDIT_LOG_ENTRY_CREATED",
EventType = EventTypeConstants.AuditLogEntryCreated,
TriggeredById = _currentUser.UserId,
CreatedDateTime = auditLog.CreatedDateTime,
ObjectId = auditLog.Id.ToString(),
Expand All @@ -50,7 +51,7 @@ public async Task HandleAsync(EntityDeletedEvent<Entities.Product> domainEvent,

await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
{
EventType = "PRODUCT_DELETED",
EventType = EventTypeConstants.ProductDeleted,
TriggeredById = _currentUser.UserId,
CreatedDateTime = domainEvent.EventDateTime,
ObjectId = domainEvent.Entity.Id.ToString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ClassifiedAds.CrossCuttingConcerns.ExtensionMethods;
using ClassifiedAds.Domain.Events;
using ClassifiedAds.Domain.Repositories;
using ClassifiedAds.Modules.Product.Constants;
using ClassifiedAds.Modules.Product.Entities;
using System;
using System.Threading;
Expand Down Expand Up @@ -40,7 +41,7 @@ public async Task HandleAsync(EntityUpdatedEvent<Entities.Product> domainEvent,

await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
{
EventType = "AUDIT_LOG_ENTRY_CREATED",
EventType = EventTypeConstants.AuditLogEntryCreated,
TriggeredById = _currentUser.UserId,
CreatedDateTime = auditLog.CreatedDateTime,
ObjectId = auditLog.Id.ToString(),
Expand All @@ -50,7 +51,7 @@ public async Task HandleAsync(EntityUpdatedEvent<Entities.Product> domainEvent,

await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
{
EventType = "PRODUCT_UPDATED",
EventType = EventTypeConstants.ProductUpdated,
TriggeredById = _currentUser.UserId,
CreatedDateTime = domainEvent.EventDateTime,
ObjectId = domainEvent.Entity.Id.ToString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ClassifiedAds.CrossCuttingConcerns.DateTimes;
using ClassifiedAds.Domain.Infrastructure.MessageBrokers;
using ClassifiedAds.Domain.Repositories;
using ClassifiedAds.Modules.Storage.Constants;
using ClassifiedAds.Modules.Storage.DTOs;
using ClassifiedAds.Modules.Storage.Entities;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -50,15 +51,15 @@ public async Task HandleAsync(PublishEventsCommand command, CancellationToken ca

foreach (var eventLog in events)
{
if (eventLog.EventType == "FILEENTRY_CREATED")
if (eventLog.EventType == EventTypeConstants.FileEntryCreated)
{
await _messageBus.SendAsync(new FileUploadedEvent { FileEntry = JsonSerializer.Deserialize<FileEntry>(eventLog.Message) });
}
else if (eventLog.EventType == "FILEENTRY_DELETED")
else if (eventLog.EventType == EventTypeConstants.FileEntryDeleted)
{
await _messageBus.SendAsync(new FileDeletedEvent { FileEntry = JsonSerializer.Deserialize<FileEntry>(eventLog.Message) });
}
else if (eventLog.EventType == "AUDIT_LOG_ENTRY_CREATED")
else if (eventLog.EventType == EventTypeConstants.AuditLogEntryCreated)
{
var logEntry = JsonSerializer.Deserialize<Contracts.AuditLog.DTOs.AuditLogEntryDTO>(eventLog.Message);
await _externalAuditLogService.AddAsync(logEntry, eventLog.Id.ToString());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ClassifiedAds.Modules.Storage.Constants;

internal class EventTypeConstants
{
public const string FileEntryCreated = "FILEENTRY_CREATED";
public const string FileEntryUpdated = "FILEENTRY_UPDATED";
public const string FileEntryDeleted = "FILEENTRY_DELETED";

public const string AuditLogEntryCreated = "AUDIT_LOG_ENTRY_CREATED";
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ClassifiedAds.CrossCuttingConcerns.ExtensionMethods;
using ClassifiedAds.Domain.Events;
using ClassifiedAds.Domain.Repositories;
using ClassifiedAds.Modules.Storage.Constants;
using ClassifiedAds.Modules.Storage.Entities;
using System;
using System.Threading;
Expand Down Expand Up @@ -40,7 +41,7 @@ public async Task HandleAsync(EntityCreatedEvent<FileEntry> domainEvent, Cancell

await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
{
EventType = "AUDIT_LOG_ENTRY_CREATED",
EventType = EventTypeConstants.AuditLogEntryCreated,
TriggeredById = _currentUser.UserId,
CreatedDateTime = auditLog.CreatedDateTime,
ObjectId = auditLog.Id.ToString(),
Expand All @@ -50,7 +51,7 @@ public async Task HandleAsync(EntityCreatedEvent<FileEntry> domainEvent, Cancell

await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
{
EventType = "FILEENTRY_CREATED",
EventType = EventTypeConstants.FileEntryCreated,
TriggeredById = _currentUser.UserId,
CreatedDateTime = domainEvent.EventDateTime,
ObjectId = domainEvent.Entity.Id.ToString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ClassifiedAds.CrossCuttingConcerns.ExtensionMethods;
using ClassifiedAds.Domain.Events;
using ClassifiedAds.Domain.Repositories;
using ClassifiedAds.Modules.Storage.Constants;
using ClassifiedAds.Modules.Storage.Entities;
using System;
using System.Threading;
Expand Down Expand Up @@ -40,7 +41,7 @@ public async Task HandleAsync(EntityDeletedEvent<FileEntry> domainEvent, Cancell

await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
{
EventType = "AUDIT_LOG_ENTRY_CREATED",
EventType = EventTypeConstants.AuditLogEntryCreated,
TriggeredById = _currentUser.UserId,
CreatedDateTime = auditLog.CreatedDateTime,
ObjectId = auditLog.Id.ToString(),
Expand All @@ -50,7 +51,7 @@ public async Task HandleAsync(EntityDeletedEvent<FileEntry> domainEvent, Cancell

await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
{
EventType = "FILEENTRY_DELETED",
EventType = EventTypeConstants.FileEntryDeleted,
TriggeredById = _currentUser.UserId,
CreatedDateTime = domainEvent.EventDateTime,
ObjectId = domainEvent.Entity.Id.ToString(),
Expand Down
Loading

0 comments on commit 574549a

Please sign in to comment.