Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Add publish date on overview page #963

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Application/Channels/Commands/CreateChannelCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public async Task<Guid> Handle(CreateChannelCommand request, CancellationToken c
}

entity.ActiveRevision = await GetActiveRevision(request, entity, cancellationToken);
if (entity.ActiveRevision is not null)
{
entity.LastPublishAt = DateTime.Now;
}

entity.AddDomainEvent(new CreatedEvent<Channel>(entity));

Expand Down
4 changes: 3 additions & 1 deletion src/Application/Channels/Commands/UpdateChannelCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class UpdateChannelCommand : IRequest
public string Name { get; set; } = "";

[Required]
public string Domain { get; set; } = "";
public string? Domain { get; set; }

[Required]
public ChannelRevisionSelectionStrategy RevisionSelectionStrategy { get; set; }
Expand All @@ -27,6 +27,8 @@ public class UpdateChannelCommand : IRequest

public Guid? ActiveRevisionId { get; set; }

public DateTime LastPublishDate { get; set; }

public Guid? CertificateId { get; set; }
}

Expand Down
2 changes: 2 additions & 0 deletions src/Application/Channels/Queries/ChannelItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public ChannelItem()

public RevisionItem? ActiveRevision { get; set; }

public DateTime? LastPublishAt { get; set; }

public string? RangeRule { get; set; }

public CertificateItem? Certificate { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Hippo.Application.Channels.Commands;
using Hippo.Application.Common.Interfaces;
using Hippo.Application.Rules;
using Hippo.Core.Entities;
Expand All @@ -15,10 +16,15 @@ public class RevisionCreatedEventHandler : INotificationHandler<CreatedEvent<Rev

private readonly IApplicationDbContext _context;

public RevisionCreatedEventHandler(ILogger<RevisionCreatedEventHandler> logger, IApplicationDbContext context)
private readonly IMediator _mediator;

public RevisionCreatedEventHandler(ILogger<RevisionCreatedEventHandler> logger,
IApplicationDbContext context,
IMediator mediator)
{
_logger = logger;
_context = context;
_mediator = mediator;
}

public async Task Handle(CreatedEvent<Revision> notification, CancellationToken cancellationToken)
Expand All @@ -39,13 +45,20 @@ public async Task Handle(CreatedEvent<Revision> notification, CancellationToken
if (activeRevision is not null && activeRevision != channel.ActiveRevision && activeRevision.RevisionNumber == notification.Entity.RevisionNumber)
{
_logger.LogInformation($"Channel {channel.Id} changed its active revision to {activeRevision.Id}");
channel.ActiveRevision = activeRevision;
channel.AddDomainEvent(new ModifiedEvent<Channel>(channel));
// TODO Call a command instead of updating the database in the EventHandler

await _mediator.Send(new UpdateChannelCommand
{
Id = channel.Id,
ActiveRevisionId = activeRevision.Id,
LastPublishDate = DateTime.Now,
CertificateId = channel.CertificateId,
Domain = channel.Domain,
Name = channel.Name,
RangeRule = channel.RangeRule,
RevisionSelectionStrategy = channel.RevisionSelectionStrategy,
}, cancellationToken);
}
}
}

await _context.SaveChangesAsync(cancellationToken);
}
}
2 changes: 2 additions & 0 deletions src/Core/Entities/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class Channel : AuditableEntity

public Revision? ActiveRevision { get; set; }

public DateTime? LastPublishAt { get; set; }

public Guid? CertificateId { get; set; }

public Certificate? Certificate { get; set; }
Expand Down
4 changes: 3 additions & 1 deletion src/Infrastructure/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
{
var result = await base.SaveChangesAsync(cancellationToken);

await _mediator.DispatchDomainEvents(this);

return await base.SaveChangesAsync(cancellationToken);
return result;
}
}
Loading