Skip to content

Commit

Permalink
Feature #679 - create initial channel when creating app (#708)
Browse files Browse the repository at this point in the history
* Added bindle-client dll to the infrastructure

* Added bindle client interface to application and implementation to core

* added bindle service to dependency injection and instantiated the BindleClient

* Added configuration as DI, fixing mistake from past commit

* removed dll, added package reference

* Create initial channel when app created

* Integrate bindle-dotnet in project infrastructure

* Removed local dll reference

* Make sure domain name is valid for initial channel

Co-authored-by: Robert Gogete <gogeterobert@yahoo.com>
  • Loading branch information
StefanNedelcu and gogeterobert committed May 2, 2022
1 parent 492ea5c commit 8c11b91
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
45 changes: 45 additions & 0 deletions src/Application/Apps/EventHandlers/CreateInitialChannel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Hippo.Application.Channels.Commands;
using Hippo.Application.Common.Config;
using Hippo.Application.Common.Models;
using Hippo.Core.Entities;
using Hippo.Core.Enums;
using Hippo.Core.Events;
using MediatR;
using Microsoft.Extensions.Logging;

namespace Hippo.Application.Apps.EventHandlers;

public class CreateInitialChannel : INotificationHandler<DomainEventNotification<CreatedEvent<App>>>
{
private readonly ILogger<AppCreatedEventHandler> _logger;

private readonly IMediator _mediator;

private readonly HippoConfig _config;

public CreateInitialChannel(ILogger<AppCreatedEventHandler> logger, IMediator mediator, HippoConfig config)
{
_logger = logger;
_mediator = mediator;
_config = config;
}

public async Task Handle(DomainEventNotification<CreatedEvent<App>> notification, CancellationToken cancellationToken)
{
var domainEvent = notification.DomainEvent;
var app = domainEvent.Entity;

var command = new CreateChannelCommand
{
AppId = app.Id,
Name = "Production",
RevisionSelectionStrategy = ChannelRevisionSelectionStrategy.UseRangeRule,
RangeRule = "*",
Domain = $"{app.Name}.{_config.PlatformDomain}".Replace('_', '-').ToLower(),
};

await _mediator.Send(command, cancellationToken);

_logger.LogInformation("Hippo Domain Event: {DomainEvent}", domainEvent.GetType().Name);
}
}
5 changes: 4 additions & 1 deletion src/Application/Channels/Commands/CreateChannelCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ public async Task<Guid> Handle(CreateChannelCommand request, CancellationToken c
.Where(a => a.Id == request.AppId)
.SingleOrDefaultAsync(cancellationToken);
_ = app ?? throw new NotFoundException(nameof(App), request.AppId);
var defaultDomain = $"{request.Name}.{app.Name}.{_config.PlatformDomain}"
.Replace('_', '-')
.ToLower();

var entity = new Channel
{
AppId = request.AppId,
App = app,
Name = request.Name,
Domain = (request.Domain is not null) ? request.Domain : $"{request.Name}.{app.Name}.{_config.PlatformDomain}",
Domain = (request.Domain is not null) ? request.Domain : defaultDomain,
RevisionSelectionStrategy = request.RevisionSelectionStrategy,
RangeRule = request.RangeRule,
ActiveRevisionId = request.ActiveRevisionId,
Expand Down

0 comments on commit 8c11b91

Please sign in to comment.