-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: raise event on encode status change
- Loading branch information
1 parent
dae34ec
commit 8f2fc21
Showing
5 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
25 changes: 25 additions & 0 deletions
25
...vice.Dashboard/src/Application.Components/Encodes/Events/RaiseEncodeStatusChangedTopic.cs
This file contains 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,25 @@ | ||
using Giantnodes.Service.Dashboard.Application.Contracts.Encodes.Events; | ||
using Giantnodes.Service.Dashboard.Domain.Aggregates.Encodes.Repositories; | ||
using HotChocolate.Subscriptions; | ||
using MassTransit; | ||
|
||
namespace Giantnodes.Service.Dashboard.Application.Components.Encodes.Events; | ||
|
||
public class RaiseEncodeStatusChangedTopic : IConsumer<EncodeStatusChangedEvent> | ||
{ | ||
private readonly IEncodeRepository _repository; | ||
private readonly ITopicEventSender _sender; | ||
|
||
public RaiseEncodeStatusChangedTopic(IEncodeRepository repository, ITopicEventSender sender) | ||
{ | ||
_repository = repository; | ||
_sender = sender; | ||
} | ||
|
||
public async Task Consume(ConsumeContext<EncodeStatusChangedEvent> context) | ||
{ | ||
var encode = await _repository.SingleAsync(x => x.Id == context.Message.EncodeId); | ||
|
||
await _sender.SendAsync(nameof(EncodeStatusChangedEvent), encode, context.CancellationToken); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Service.Dashboard/src/Application.Contracts/Encodes/Events/EncodeStatusChangedEvent.cs
This file contains 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,13 @@ | ||
using Giantnodes.Infrastructure.Domain.Events; | ||
using Giantnodes.Service.Dashboard.Domain.Shared.Enums; | ||
|
||
namespace Giantnodes.Service.Dashboard.Application.Contracts.Encodes.Events; | ||
|
||
public sealed record EncodeStatusChangedEvent : DomainEvent | ||
{ | ||
public required Guid EncodeId { get; init; } | ||
|
||
public required EncodeStatus FromStatus { get; init; } | ||
|
||
public required EncodeStatus ToStatus { get; init; } | ||
} |
This file contains 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
23 changes: 23 additions & 0 deletions
23
....Dashboard/src/HttpApi/Resolvers/Encodes/Subscriptions/EncodeStatusChangedSubscription.cs
This file contains 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,23 @@ | ||
using Giantnodes.Service.Dashboard.Application.Contracts.Encodes.Events; | ||
using Giantnodes.Service.Dashboard.Domain.Aggregates.Encodes; | ||
using Giantnodes.Service.Dashboard.Persistence.DbContexts; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Giantnodes.Service.Dashboard.HttpApi.Resolvers.Encodes.Subscriptions; | ||
|
||
[ExtendObjectType(OperationTypeNames.Subscription)] | ||
public class EncodeStatusChangedSubscription | ||
{ | ||
[Subscribe] | ||
[Topic(nameof(EncodeStatusChangedEvent))] | ||
[UseSingleOrDefault] | ||
[UseProjection] | ||
[UseFiltering] | ||
[UseSorting] | ||
public IQueryable<Encode> EncodeStatusChanged( | ||
[Service] ApplicationDbContext database, | ||
[EventMessage] Encode encode) | ||
{ | ||
return database.Encodes.Where(x => x.Id == encode.Id).AsNoTracking(); | ||
} | ||
} |