Skip to content

Commit 574549a

Browse files
committed
Event Type Constants
1 parent 346eb08 commit 574549a

File tree

30 files changed

+113
-36
lines changed

30 files changed

+113
-36
lines changed

src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/Commands/AddAuditLogEntryCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using ClassifiedAds.CrossCuttingConcerns.ExtensionMethods;
22
using ClassifiedAds.Domain.Repositories;
33
using ClassifiedAds.Infrastructure.Identity;
4+
using ClassifiedAds.Services.Product.Constants;
45
using ClassifiedAds.Services.Product.Entities;
56
using MediatR;
67
using System;
@@ -45,7 +46,7 @@ public async Task Handle(AddAuditLogEntryCommand command, CancellationToken canc
4546

4647
await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
4748
{
48-
EventType = "AUDIT_LOG_ENTRY_CREATED",
49+
EventType = EventTypeConstants.AuditLogEntryCreated,
4950
TriggeredById = _currentUser.UserId,
5051
CreatedDateTime = auditLog.CreatedDateTime,
5152
ObjectId = auditLog.Id.ToString(),

src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/Commands/PublishEventsCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using ClassifiedAds.CrossCuttingConcerns.DateTimes;
22
using ClassifiedAds.Domain.Infrastructure.MessageBrokers;
33
using ClassifiedAds.Domain.Repositories;
4+
using ClassifiedAds.Services.Product.Constants;
45
using ClassifiedAds.Services.Product.DTOs;
56
using ClassifiedAds.Services.Product.Entities;
67
using Dapr.Client;
@@ -50,7 +51,7 @@ public async Task Handle(PublishEventsCommand command, CancellationToken cancell
5051

5152
foreach (var eventLog in events)
5253
{
53-
if (eventLog.EventType == "AUDIT_LOG_ENTRY_CREATED")
54+
if (eventLog.EventType == EventTypeConstants.AuditLogEntryCreated)
5455
{
5556
var logEntry = JsonSerializer.Deserialize<AuditLogEntry>(eventLog.Message);
5657
await _messageBus.SendAsync(new AuditLogCreatedEvent { AuditLog = logEntry },
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace ClassifiedAds.Services.Product.Constants;
2+
3+
internal class EventTypeConstants
4+
{
5+
public const string ProductCreated = "PRODUCT_CREATED";
6+
public const string ProductUpdated = "PRODUCT_UPDATED";
7+
public const string ProductDeleted = "PRODUCT_DELETED";
8+
9+
public const string AuditLogEntryCreated = "AUDIT_LOG_ENTRY_CREATED";
10+
}

src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/EventHandlers/ProductCreatedEventHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using ClassifiedAds.Domain.Repositories;
44
using ClassifiedAds.Infrastructure.Identity;
55
using ClassifiedAds.Services.Product.Commands;
6+
using ClassifiedAds.Services.Product.Constants;
67
using ClassifiedAds.Services.Product.Entities;
78
using MediatR;
89
using System;
@@ -42,7 +43,7 @@ await _dispatcher.Send(new AddAuditLogEntryCommand
4243

4344
await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
4445
{
45-
EventType = "PRODUCT_CREATED",
46+
EventType = EventTypeConstants.ProductCreated,
4647
TriggeredById = _currentUser.UserId,
4748
CreatedDateTime = domainEvent.EventDateTime,
4849
ObjectId = domainEvent.Entity.Id.ToString(),

src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/EventHandlers/ProductDeletedEventHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using ClassifiedAds.Domain.Repositories;
44
using ClassifiedAds.Infrastructure.Identity;
55
using ClassifiedAds.Services.Product.Commands;
6+
using ClassifiedAds.Services.Product.Constants;
67
using ClassifiedAds.Services.Product.Entities;
78
using MediatR;
89
using System;
@@ -42,7 +43,7 @@ await _dispatcher.Send(new AddAuditLogEntryCommand
4243

4344
await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
4445
{
45-
EventType = "PRODUCT_DELETED",
46+
EventType = EventTypeConstants.ProductDeleted,
4647
TriggeredById = _currentUser.UserId,
4748
CreatedDateTime = domainEvent.EventDateTime,
4849
ObjectId = domainEvent.Entity.Id.ToString(),

src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/EventHandlers/ProductUpdatedEventHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using ClassifiedAds.Domain.Repositories;
44
using ClassifiedAds.Infrastructure.Identity;
55
using ClassifiedAds.Services.Product.Commands;
6+
using ClassifiedAds.Services.Product.Constants;
67
using ClassifiedAds.Services.Product.Entities;
78
using MediatR;
89
using System;
@@ -42,7 +43,7 @@ await _dispatcher.Send(new AddAuditLogEntryCommand
4243

4344
await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
4445
{
45-
EventType = "PRODUCT_UPDATED",
46+
EventType = EventTypeConstants.ProductUpdated,
4647
TriggeredById = _currentUser.UserId,
4748
CreatedDateTime = domainEvent.EventDateTime,
4849
ObjectId = domainEvent.Entity.Id.ToString(),

src/Microservices/Services.Storage/ClassifiedAds.Services.Storage.Api/Commands/AddAuditLogEntryCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using ClassifiedAds.CrossCuttingConcerns.ExtensionMethods;
33
using ClassifiedAds.Domain.Repositories;
44
using ClassifiedAds.Infrastructure.Identity;
5+
using ClassifiedAds.Services.Storage.Constants;
56
using ClassifiedAds.Services.Storage.Entities;
67
using System;
78
using System.Threading;
@@ -45,7 +46,7 @@ public async Task HandleAsync(AddAuditLogEntryCommand command, CancellationToken
4546

4647
await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
4748
{
48-
EventType = "AUDIT_LOG_ENTRY_CREATED",
49+
EventType = EventTypeConstants.AuditLogEntryCreated,
4950
TriggeredById = _currentUser.UserId,
5051
CreatedDateTime = auditLog.CreatedDateTime,
5152
ObjectId = auditLog.Id.ToString(),

src/Microservices/Services.Storage/ClassifiedAds.Services.Storage.Api/Commands/PublishEventsCommand.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using ClassifiedAds.CrossCuttingConcerns.DateTimes;
33
using ClassifiedAds.Domain.Infrastructure.MessageBrokers;
44
using ClassifiedAds.Domain.Repositories;
5+
using ClassifiedAds.Services.Storage.Constants;
56
using ClassifiedAds.Services.Storage.DTOs;
67
using ClassifiedAds.Services.Storage.Entities;
78
using Microsoft.Extensions.Logging;
@@ -46,15 +47,15 @@ public async Task HandleAsync(PublishEventsCommand command, CancellationToken ca
4647

4748
foreach (var eventLog in events)
4849
{
49-
if (eventLog.EventType == "FILEENTRY_CREATED")
50+
if (eventLog.EventType == EventTypeConstants.FileEntryCreated)
5051
{
5152
await _messageBus.SendAsync(new FileUploadedEvent { FileEntry = JsonSerializer.Deserialize<FileEntry>(eventLog.Message) });
5253
}
53-
else if (eventLog.EventType == "FILEENTRY_DELETED")
54+
else if (eventLog.EventType == EventTypeConstants.FileEntryDeleted)
5455
{
5556
await _messageBus.SendAsync(new FileDeletedEvent { FileEntry = JsonSerializer.Deserialize<FileEntry>(eventLog.Message) });
5657
}
57-
else if (eventLog.EventType == "AUDIT_LOG_ENTRY_CREATED")
58+
else if (eventLog.EventType == EventTypeConstants.AuditLogEntryCreated)
5859
{
5960
var logEntry = JsonSerializer.Deserialize<AuditLogEntry>(eventLog.Message);
6061
await _messageBus.SendAsync(new AuditLogCreatedEvent { AuditLog = logEntry },
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace ClassifiedAds.Services.Storage.Constants;
2+
3+
internal class EventTypeConstants
4+
{
5+
public const string FileEntryCreated = "FILEENTRY_CREATED";
6+
public const string FileEntryUpdated = "FILEENTRY_UPDATED";
7+
public const string FileEntryDeleted = "FILEENTRY_DELETED";
8+
9+
public const string AuditLogEntryCreated = "AUDIT_LOG_ENTRY_CREATED";
10+
}

src/Microservices/Services.Storage/ClassifiedAds.Services.Storage.Api/EventHandlers/FileEntryCreatedEventHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using ClassifiedAds.Domain.Repositories;
55
using ClassifiedAds.Infrastructure.Identity;
66
using ClassifiedAds.Services.Storage.Commands;
7+
using ClassifiedAds.Services.Storage.Constants;
78
using ClassifiedAds.Services.Storage.Entities;
89
using System;
910
using System.Threading;
@@ -42,7 +43,7 @@ await _dispatcher.DispatchAsync(new AddAuditLogEntryCommand
4243

4344
await _outboxEventRepository.AddOrUpdateAsync(new OutboxEvent
4445
{
45-
EventType = "FILEENTRY_CREATED",
46+
EventType = EventTypeConstants.FileEntryCreated,
4647
TriggeredById = _currentUser.UserId,
4748
CreatedDateTime = domainEvent.EventDateTime,
4849
ObjectId = domainEvent.Entity.Id.ToString(),

0 commit comments

Comments
 (0)