mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.2 KiB
84 lines
2.2 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
using Newtonsoft.Json;
|
|
using NodaTime;
|
|
using Squidex.Domain.Apps.Core.Contents;
|
|
using Squidex.Domain.Apps.Events;
|
|
using Squidex.Domain.Apps.Events.Contents;
|
|
using Squidex.Infrastructure;
|
|
using Squidex.Infrastructure.Dispatching;
|
|
using Squidex.Infrastructure.EventSourcing;
|
|
|
|
namespace Squidex.Domain.Apps.Entities.Contents.State
|
|
{
|
|
public class ContentState : DomainObjectState<ContentState>,
|
|
IContentEntity
|
|
{
|
|
[JsonProperty]
|
|
public NamedId<Guid> AppId { get; set; }
|
|
|
|
[JsonProperty]
|
|
public NamedId<Guid> SchemaId { get; set; }
|
|
|
|
[JsonProperty]
|
|
public NamedContentData Data { get; set; }
|
|
|
|
[JsonProperty]
|
|
public Status Status { get; set; }
|
|
|
|
[JsonProperty]
|
|
public RefToken PublishAtBy { get; set; }
|
|
|
|
[JsonProperty]
|
|
public Instant? PublishAt { get; set; }
|
|
|
|
[JsonProperty]
|
|
public bool IsDeleted { get; set; }
|
|
|
|
protected void On(ContentCreated @event)
|
|
{
|
|
SchemaId = @event.SchemaId;
|
|
|
|
Data = @event.Data;
|
|
|
|
AppId = @event.AppId;
|
|
}
|
|
|
|
protected void On(ContentUpdated @event)
|
|
{
|
|
Data = @event.Data;
|
|
}
|
|
|
|
protected void On(ContentPublishScheduled @event)
|
|
{
|
|
PublishAt = @event.PublishAt;
|
|
PublishAtBy = @event.Actor;
|
|
}
|
|
|
|
protected void On(ContentStatusChanged @event)
|
|
{
|
|
Status = @event.Status;
|
|
|
|
PublishAt = null;
|
|
PublishAtBy = null;
|
|
}
|
|
|
|
protected void On(ContentDeleted @event)
|
|
{
|
|
IsDeleted = true;
|
|
}
|
|
|
|
public ContentState Apply(Envelope<IEvent> @event)
|
|
{
|
|
var payload = (SquidexEvent)@event.Payload;
|
|
|
|
return Clone().Update(payload, @event.Headers, r => r.DispatchAction(payload));
|
|
}
|
|
}
|
|
}
|
|
|