|
|
|
@ -8,13 +8,13 @@ |
|
|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using Squidex.Domain.Apps.Core; |
|
|
|
using Squidex.Domain.Apps.Core.Schemas; |
|
|
|
using Squidex.Domain.Apps.Entities.Schemas.Commands; |
|
|
|
using Squidex.Domain.Apps.Entities.Schemas.State; |
|
|
|
using Squidex.Domain.Apps.Events.Schemas; |
|
|
|
using Squidex.Infrastructure; |
|
|
|
using Squidex.Infrastructure.Commands; |
|
|
|
using Squidex.Infrastructure.EventSourcing; |
|
|
|
using Squidex.Infrastructure.Reflection; |
|
|
|
|
|
|
|
namespace Squidex.Domain.Apps.Entities.Schemas |
|
|
|
@ -57,22 +57,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas |
|
|
|
{ |
|
|
|
VerifyCreatedAndNotDeleted(); |
|
|
|
|
|
|
|
var partitioning = |
|
|
|
string.Equals(command.Partitioning, Partitioning.Language.Key, StringComparison.OrdinalIgnoreCase) ? |
|
|
|
Partitioning.Language : |
|
|
|
Partitioning.Invariant; |
|
|
|
|
|
|
|
var fieldId = State.TotalFields; |
|
|
|
|
|
|
|
var field = registry.CreateField(fieldId, command.Name, partitioning, command.Properties); |
|
|
|
|
|
|
|
UpdateState(command, state => |
|
|
|
{ |
|
|
|
state.SchemaDef = state.SchemaDef.AddField(field); |
|
|
|
state.TotalFields = fieldId + 1; |
|
|
|
}); |
|
|
|
|
|
|
|
RaiseEvent(SimpleMapper.Map(command, new FieldAdded { FieldId = new NamedId<long>(fieldId + 1, command.Name) })); |
|
|
|
RaiseEvent(SimpleMapper.Map(command, new FieldAdded { FieldId = new NamedId<long>(State.TotalFields + 1, command.Name) })); |
|
|
|
|
|
|
|
return this; |
|
|
|
} |
|
|
|
@ -81,8 +66,6 @@ namespace Squidex.Domain.Apps.Entities.Schemas |
|
|
|
{ |
|
|
|
VerifyCreatedAndNotDeleted(); |
|
|
|
|
|
|
|
UpdateSchema(command, s => s.UpdateField(command.FieldId, command.Properties)); |
|
|
|
|
|
|
|
RaiseEvent(command, SimpleMapper.Map(command, new FieldUpdated())); |
|
|
|
|
|
|
|
return this; |
|
|
|
@ -92,8 +75,6 @@ namespace Squidex.Domain.Apps.Entities.Schemas |
|
|
|
{ |
|
|
|
VerifyCreatedAndNotDeleted(); |
|
|
|
|
|
|
|
UpdateSchema(command, s => s.LockField(command.FieldId)); |
|
|
|
|
|
|
|
RaiseEvent(command, new FieldLocked()); |
|
|
|
|
|
|
|
return this; |
|
|
|
@ -103,8 +84,6 @@ namespace Squidex.Domain.Apps.Entities.Schemas |
|
|
|
{ |
|
|
|
VerifyCreatedAndNotDeleted(); |
|
|
|
|
|
|
|
UpdateSchema(command, s => s.HideField(command.FieldId)); |
|
|
|
|
|
|
|
RaiseEvent(command, new FieldHidden()); |
|
|
|
|
|
|
|
return this; |
|
|
|
@ -114,8 +93,6 @@ namespace Squidex.Domain.Apps.Entities.Schemas |
|
|
|
{ |
|
|
|
VerifyCreatedAndNotDeleted(); |
|
|
|
|
|
|
|
UpdateSchema(command, s => s.ShowField(command.FieldId)); |
|
|
|
|
|
|
|
RaiseEvent(command, new FieldShown()); |
|
|
|
|
|
|
|
return this; |
|
|
|
@ -125,8 +102,6 @@ namespace Squidex.Domain.Apps.Entities.Schemas |
|
|
|
{ |
|
|
|
VerifyCreatedAndNotDeleted(); |
|
|
|
|
|
|
|
UpdateSchema(command, s => s.DisableField(command.FieldId)); |
|
|
|
|
|
|
|
RaiseEvent(command, new FieldDisabled()); |
|
|
|
|
|
|
|
return this; |
|
|
|
@ -136,8 +111,6 @@ namespace Squidex.Domain.Apps.Entities.Schemas |
|
|
|
{ |
|
|
|
VerifyCreatedAndNotDeleted(); |
|
|
|
|
|
|
|
UpdateSchema(command, s => s.EnableField(command.FieldId)); |
|
|
|
|
|
|
|
RaiseEvent(command, new FieldEnabled()); |
|
|
|
|
|
|
|
return this; |
|
|
|
@ -147,8 +120,6 @@ namespace Squidex.Domain.Apps.Entities.Schemas |
|
|
|
{ |
|
|
|
VerifyCreatedAndNotDeleted(); |
|
|
|
|
|
|
|
UpdateSchema(command, s => s.DeleteField(command.FieldId)); |
|
|
|
|
|
|
|
RaiseEvent(command, new FieldDeleted()); |
|
|
|
|
|
|
|
return this; |
|
|
|
@ -158,8 +129,6 @@ namespace Squidex.Domain.Apps.Entities.Schemas |
|
|
|
{ |
|
|
|
VerifyCreatedAndNotDeleted(); |
|
|
|
|
|
|
|
UpdateSchema(command, s => s.ReorderFields(command.FieldIds)); |
|
|
|
|
|
|
|
RaiseEvent(SimpleMapper.Map(command, new SchemaFieldsReordered())); |
|
|
|
|
|
|
|
return this; |
|
|
|
@ -169,8 +138,6 @@ namespace Squidex.Domain.Apps.Entities.Schemas |
|
|
|
{ |
|
|
|
VerifyCreatedAndNotDeleted(); |
|
|
|
|
|
|
|
UpdateSchema(command, s => s.Publish()); |
|
|
|
|
|
|
|
RaiseEvent(SimpleMapper.Map(command, new SchemaPublished())); |
|
|
|
|
|
|
|
return this; |
|
|
|
@ -180,8 +147,6 @@ namespace Squidex.Domain.Apps.Entities.Schemas |
|
|
|
{ |
|
|
|
VerifyCreatedAndNotDeleted(); |
|
|
|
|
|
|
|
UpdateSchema(command, s => s.Unpublish()); |
|
|
|
|
|
|
|
RaiseEvent(SimpleMapper.Map(command, new SchemaUnpublished())); |
|
|
|
|
|
|
|
return this; |
|
|
|
@ -191,8 +156,6 @@ namespace Squidex.Domain.Apps.Entities.Schemas |
|
|
|
{ |
|
|
|
VerifyCreatedAndNotDeleted(); |
|
|
|
|
|
|
|
UpdateState(command, s => SimpleMapper.Map(command, s)); |
|
|
|
|
|
|
|
RaiseEvent(SimpleMapper.Map(command, new ScriptsConfigured())); |
|
|
|
|
|
|
|
return this; |
|
|
|
@ -202,8 +165,6 @@ namespace Squidex.Domain.Apps.Entities.Schemas |
|
|
|
{ |
|
|
|
VerifyCreatedAndNotDeleted(); |
|
|
|
|
|
|
|
UpdateState(command, s => s.IsDeleted = true); |
|
|
|
|
|
|
|
RaiseEvent(SimpleMapper.Map(command, new SchemaDeleted())); |
|
|
|
|
|
|
|
return this; |
|
|
|
@ -213,8 +174,6 @@ namespace Squidex.Domain.Apps.Entities.Schemas |
|
|
|
{ |
|
|
|
VerifyCreatedAndNotDeleted(); |
|
|
|
|
|
|
|
UpdateState(command, s => SimpleMapper.Map(command, s)); |
|
|
|
|
|
|
|
RaiseEvent(SimpleMapper.Map(command, new SchemaUpdated())); |
|
|
|
|
|
|
|
return this; |
|
|
|
@ -248,14 +207,9 @@ namespace Squidex.Domain.Apps.Entities.Schemas |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void UpdateSchema(ICommand command, Func<Schema, Schema> updater) |
|
|
|
{ |
|
|
|
UpdateState(command, s => s.SchemaDef = updater(s.SchemaDef)); |
|
|
|
} |
|
|
|
|
|
|
|
protected override SchemaState CloneState(ICommand command, Action<SchemaState> updater) |
|
|
|
protected override void OnRaised(Envelope<IEvent> @event) |
|
|
|
{ |
|
|
|
return State.Clone().Update((SquidexCommand)command, updater); |
|
|
|
UpdateState(State.Apply(@event)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |