Browse Source

Renaming

pull/1/head
Sebastian Stehle 9 years ago
parent
commit
f5bf3c9aba
  1. 1
      PinkParrot.sln.DotSettings
  2. 6
      src/PinkParrot/Configurations/InfrastructureModule.cs
  3. 10
      src/PinkParrot/Configurations/ReadModule.cs
  4. 8
      src/PinkParrot/Configurations/Serializers.cs
  5. 8
      src/PinkParrot/Configurations/WriteModule.cs
  6. 2
      src/PinkParrot/Modules/Api/EntityCreatedDto.cs
  7. 6
      src/PinkParrot/Modules/Api/Schemas/CreateSchemaDto.cs
  8. 2
      src/PinkParrot/Modules/Api/Schemas/ListSchemaDto.cs
  9. 16
      src/PinkParrot/Modules/Api/Schemas/SchemaFieldsController.cs
  10. 24
      src/PinkParrot/Modules/Api/Schemas/SchemasController.cs
  11. 12
      src/PinkParrot/Pipeline/CommandHandlers/EnrichWithAggregateIdHandler.cs
  12. 36
      src/pinkparrot_core/PinkParrot.Core/Schemas/Field.cs
  13. 8
      src/pinkparrot_core/PinkParrot.Core/Schemas/FieldProperties.cs
  14. 24
      src/pinkparrot_core/PinkParrot.Core/Schemas/FieldRegistry.cs
  15. 14
      src/pinkparrot_core/PinkParrot.Core/Schemas/Field_Generic.cs
  16. 6
      src/pinkparrot_core/PinkParrot.Core/Schemas/IFieldProperties.cs
  17. 8
      src/pinkparrot_core/PinkParrot.Core/Schemas/IRegisteredField.cs
  18. 3
      src/pinkparrot_core/PinkParrot.Core/Schemas/NamedElementProperties.cs
  19. 8
      src/pinkparrot_core/PinkParrot.Core/Schemas/NumberField.cs
  20. 4
      src/pinkparrot_core/PinkParrot.Core/Schemas/NumberFieldProperties.cs
  21. 59
      src/pinkparrot_core/PinkParrot.Core/Schemas/Schema.cs
  22. 8
      src/pinkparrot_core/PinkParrot.Core/Schemas/SchemaProperties.cs
  23. 21
      src/pinkparrot_events/PinkParrot.Events/Schema/ModelFieldUpdated.cs
  24. 19
      src/pinkparrot_events/PinkParrot.Events/Schema/ModelSchemaUpdated.cs
  25. 12
      src/pinkparrot_events/PinkParrot.Events/Schemas/FieldAdded.cs
  26. 8
      src/pinkparrot_events/PinkParrot.Events/Schemas/FieldDeleted.cs
  27. 8
      src/pinkparrot_events/PinkParrot.Events/Schemas/FieldDisabled.cs
  28. 8
      src/pinkparrot_events/PinkParrot.Events/Schemas/FieldEnabled.cs
  29. 8
      src/pinkparrot_events/PinkParrot.Events/Schemas/FieldHidden.cs
  30. 18
      src/pinkparrot_events/PinkParrot.Events/Schemas/FieldShown.cs
  31. 11
      src/pinkparrot_events/PinkParrot.Events/Schemas/FieldUpdated.cs
  32. 12
      src/pinkparrot_events/PinkParrot.Events/Schemas/SchemaCreated.cs
  33. 8
      src/pinkparrot_events/PinkParrot.Events/Schemas/SchemaDeleted.cs
  34. 19
      src/pinkparrot_events/PinkParrot.Events/Schemas/SchemaUpdated.cs
  35. 1
      src/pinkparrot_infrastructure/PinkParrot.Infrastructure/CQRS/EventStore/IStreamPositionStorage.cs
  36. 12
      src/pinkparrot_read/PinkParrot.Read/Models/FieldDto.cs
  37. 23
      src/pinkparrot_read/PinkParrot.Read/Models/SchemaDto.cs
  38. 8
      src/pinkparrot_read/PinkParrot.Read/Repositories/EntityWithSchema.cs
  39. 4
      src/pinkparrot_read/PinkParrot.Read/Repositories/ISchemaEntity.cs
  40. 6
      src/pinkparrot_read/PinkParrot.Read/Repositories/ISchemaRepository.cs
  41. 2
      src/pinkparrot_read/PinkParrot.Read/Repositories/Implementations/Mongo/MongoPosition.cs
  42. 6
      src/pinkparrot_read/PinkParrot.Read/Repositories/Implementations/Mongo/MongoPositionStorage.cs
  43. 4
      src/pinkparrot_read/PinkParrot.Read/Repositories/Implementations/Mongo/MongoSchemaEntity.cs
  44. 54
      src/pinkparrot_read/PinkParrot.Read/Repositories/Implementations/Mongo/MongoSchemaRepository.cs
  45. 4
      src/pinkparrot_read/PinkParrot.Read/Services/ISchemaProvider.cs
  46. 13
      src/pinkparrot_read/PinkParrot.Read/Services/Implementations/CachingSchemaProvider.cs
  47. 17
      src/pinkparrot_write/PinkParrot.Write/Schema/Commands/UpdateModelSchema.cs
  48. 6
      src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/AddField.cs
  49. 10
      src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/CreateSchema.cs
  50. 7
      src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/DeleteField.cs
  51. 7
      src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/DeleteSchema.cs
  52. 7
      src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/DisableField.cs
  53. 7
      src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/EnableField.cs
  54. 7
      src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/HideField.cs
  55. 7
      src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/ShowField.cs
  56. 6
      src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/UpdateField.cs
  57. 17
      src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/UpdateSchema.cs
  58. 42
      src/pinkparrot_write/PinkParrot.Write/Schemas/SchemaCommandHandler.cs
  59. 68
      src/pinkparrot_write/PinkParrot.Write/Schemas/SchemaDomainObject.cs

1
PinkParrot.sln.DotSettings

@ -28,6 +28,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestVarOrType_005FSimpleTypes/@EntryIndexedValue">SUGGESTION</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestVarOrType_005FSimpleTypes/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=TsResolvedFromInaccessibleModule/@EntryIndexedValue">DO_NOT_SHOW</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=TsResolvedFromInaccessibleModule/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/TypeScriptInspections/Level/@EntryValue">TypeScript16</s:String> <s:String x:Key="/Default/CodeInspection/TypeScriptInspections/Level/@EntryValue">TypeScript16</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Header/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="Header"&gt;&lt;CSUpdateFileHeader&gt;True&lt;/CSUpdateFileHeader&gt;&lt;/Profile&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Namespaces/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="Namespaces"&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;EmbraceInRegion&gt;False&lt;/EmbraceInRegion&gt;&lt;RegionName&gt;&lt;/RegionName&gt;&lt;/CSOptimizeUsings&gt;&lt;CSUpdateFileHeader&gt;True&lt;/CSUpdateFileHeader&gt;&lt;/Profile&gt;</s:String> <s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Namespaces/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="Namespaces"&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;EmbraceInRegion&gt;False&lt;/EmbraceInRegion&gt;&lt;RegionName&gt;&lt;/RegionName&gt;&lt;/CSOptimizeUsings&gt;&lt;CSUpdateFileHeader&gt;True&lt;/CSUpdateFileHeader&gt;&lt;/Profile&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Typescript/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="Typescript"&gt;&lt;JsInsertSemicolon&gt;True&lt;/JsInsertSemicolon&gt;&lt;FormatAttributeQuoteDescriptor&gt;True&lt;/FormatAttributeQuoteDescriptor&gt;&lt;CorrectVariableKindsDescriptor&gt;True&lt;/CorrectVariableKindsDescriptor&gt;&lt;VariablesToInnerScopesDescriptor&gt;True&lt;/VariablesToInnerScopesDescriptor&gt;&lt;StringToTemplatesDescriptor&gt;True&lt;/StringToTemplatesDescriptor&gt;&lt;RemoveRedundantQualifiersTs&gt;True&lt;/RemoveRedundantQualifiersTs&gt;&lt;OptimizeImportsTs&gt;True&lt;/OptimizeImportsTs&gt;&lt;/Profile&gt;</s:String> <s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Typescript/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="Typescript"&gt;&lt;JsInsertSemicolon&gt;True&lt;/JsInsertSemicolon&gt;&lt;FormatAttributeQuoteDescriptor&gt;True&lt;/FormatAttributeQuoteDescriptor&gt;&lt;CorrectVariableKindsDescriptor&gt;True&lt;/CorrectVariableKindsDescriptor&gt;&lt;VariablesToInnerScopesDescriptor&gt;True&lt;/VariablesToInnerScopesDescriptor&gt;&lt;StringToTemplatesDescriptor&gt;True&lt;/StringToTemplatesDescriptor&gt;&lt;RemoveRedundantQualifiersTs&gt;True&lt;/RemoveRedundantQualifiersTs&gt;&lt;OptimizeImportsTs&gt;True&lt;/OptimizeImportsTs&gt;&lt;/Profile&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/SilentCleanupProfile/@EntryValue"></s:String> <s:String x:Key="/Default/CodeStyle/CodeCleanup/SilentCleanupProfile/@EntryValue"></s:String>

6
src/PinkParrot/Configurations/InfrastructureModule.cs

@ -15,7 +15,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using MongoDB.Driver; using MongoDB.Driver;
using PinkParrot.Core.Schema; using PinkParrot.Core.Schemas;
using PinkParrot.Infrastructure.CQRS.Autofac; using PinkParrot.Infrastructure.CQRS.Autofac;
using PinkParrot.Infrastructure.CQRS.Commands; using PinkParrot.Infrastructure.CQRS.Commands;
using PinkParrot.Infrastructure.CQRS.EventStore; using PinkParrot.Infrastructure.CQRS.EventStore;
@ -58,7 +58,7 @@ namespace PinkParrot.Configurations
.As<IMongoDatabase>() .As<IMongoDatabase>()
.SingleInstance(); .SingleInstance();
builder.RegisterType<MongoStreamPositionsStorage>() builder.RegisterType<MongoPositionStorage>()
.As<IStreamPositionStorage>() .As<IStreamPositionStorage>()
.SingleInstance(); .SingleInstance();
@ -86,7 +86,7 @@ namespace PinkParrot.Configurations
.AsSelf() .AsSelf()
.SingleInstance(); .SingleInstance();
builder.RegisterType<ModelFieldRegistry>() builder.RegisterType<FieldRegistry>()
.AsSelf() .AsSelf()
.SingleInstance(); .SingleInstance();
} }

10
src/PinkParrot/Configurations/ReadModule.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ReadDependencies.cs // ReadModule.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -23,13 +23,13 @@ namespace PinkParrot.Configurations
.As<ITenantProvider>() .As<ITenantProvider>()
.SingleInstance(); .SingleInstance();
builder.RegisterType<ModelSchemaProvider>() builder.RegisterType<CachingSchemaProvider>()
.As<IModelSchemaProvider>() .As<ISchemaProvider>()
.As<ILiveEventConsumer>() .As<ILiveEventConsumer>()
.SingleInstance(); .SingleInstance();
builder.RegisterType<MongoModelSchemaRepository>() builder.RegisterType<MongoSchemaRepository>()
.As<IModelSchemaRepository>() .As<ISchemaRepository>()
.As<ICatchEventConsumer>() .As<ICatchEventConsumer>()
.SingleInstance(); .SingleInstance();
} }

8
src/PinkParrot/Configurations/Serializers.cs

@ -10,8 +10,8 @@ using System.Reflection;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Serialization;
using PinkParrot.Core.Schema; using PinkParrot.Core.Schemas;
using PinkParrot.Events.Schema; using PinkParrot.Events.Schemas;
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
using PinkParrot.Infrastructure.CQRS.EventStore; using PinkParrot.Infrastructure.CQRS.EventStore;
using PinkParrot.Infrastructure.Json; using PinkParrot.Infrastructure.Json;
@ -45,8 +45,8 @@ namespace PinkParrot.Configurations
public static void AddEventFormatter(this IServiceCollection services) public static void AddEventFormatter(this IServiceCollection services)
{ {
TypeNameRegistry.Map(typeof(ModelSchema).GetTypeInfo().Assembly); TypeNameRegistry.Map(typeof(Schema).GetTypeInfo().Assembly);
TypeNameRegistry.Map(typeof(ModelSchemaCreated).GetTypeInfo().Assembly); TypeNameRegistry.Map(typeof(SchemaCreated).GetTypeInfo().Assembly);
services.AddSingleton(t => CreateSettings()); services.AddSingleton(t => CreateSettings());
services.AddSingleton(t => CreateSerializer(t.GetRequiredService<JsonSerializerSettings>())); services.AddSingleton(t => CreateSerializer(t.GetRequiredService<JsonSerializerSettings>()));

8
src/PinkParrot/Configurations/WriteModule.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// WriteDependencies.cs // WriteModule.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -9,7 +9,7 @@
using Autofac; using Autofac;
using PinkParrot.Infrastructure.CQRS.Commands; using PinkParrot.Infrastructure.CQRS.Commands;
using PinkParrot.Pipeline.CommandHandlers; using PinkParrot.Pipeline.CommandHandlers;
using PinkParrot.Write.Schema; using PinkParrot.Write.Schemas;
namespace PinkParrot.Configurations namespace PinkParrot.Configurations
{ {
@ -25,11 +25,11 @@ namespace PinkParrot.Configurations
.As<ICommandHandler>() .As<ICommandHandler>()
.SingleInstance(); .SingleInstance();
builder.RegisterType<ModelSchemaCommandHandler>() builder.RegisterType<SchemaCommandHandler>()
.As<ICommandHandler>() .As<ICommandHandler>()
.SingleInstance(); .SingleInstance();
builder.RegisterType<ModelSchemaDomainObject>() builder.RegisterType<SchemaDomainObject>()
.AsSelf() .AsSelf()
.InstancePerDependency(); .InstancePerDependency();
} }

2
src/PinkParrot/Modules/Api/EntityCreatedDto.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// EntityCreated.cs // EntityCreatedDto.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group

6
src/PinkParrot/Modules/Api/Schemas/CreateSchemaDto.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// CreateFieldDto.cs // CreateSchemaDto.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -7,7 +7,7 @@
// ========================================================================== // ==========================================================================
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using PinkParrot.Core.Schema; using PinkParrot.Core.Schemas;
namespace PinkParrot.Modules.Api.Schemas namespace PinkParrot.Modules.Api.Schemas
{ {
@ -17,6 +17,6 @@ namespace PinkParrot.Modules.Api.Schemas
public string Name { get; set; } public string Name { get; set; }
[Required] [Required]
public ModelFieldProperties Properties { get; set; } public FieldProperties Properties { get; set; }
} }
} }

2
src/PinkParrot/Modules/Api/Schemas/ListSchemaDto.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// SchemaListModel.cs // ListSchemaDto.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group

16
src/PinkParrot/Modules/Api/Schemas/SchemaFieldsController.cs

@ -10,7 +10,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using PinkParrot.Infrastructure.CQRS.Commands; using PinkParrot.Infrastructure.CQRS.Commands;
using PinkParrot.Infrastructure.Reflection; using PinkParrot.Infrastructure.Reflection;
using PinkParrot.Write.Schema.Commands; using PinkParrot.Write.Schemas.Commands;
namespace PinkParrot.Modules.Api.Schemas namespace PinkParrot.Modules.Api.Schemas
{ {
@ -25,7 +25,7 @@ namespace PinkParrot.Modules.Api.Schemas
[Route("api/schemas/{name}/fields/")] [Route("api/schemas/{name}/fields/")]
public Task Add(string name, [FromBody] CreateFieldDto model) public Task Add(string name, [FromBody] CreateFieldDto model)
{ {
var command = SimpleMapper.Map(model, new AddModelField()); var command = SimpleMapper.Map(model, new AddField());
return CommandBus.PublishAsync(command); return CommandBus.PublishAsync(command);
} }
@ -34,7 +34,7 @@ namespace PinkParrot.Modules.Api.Schemas
[Route("api/schemas/{name}/fields/{fieldId:long}/")] [Route("api/schemas/{name}/fields/{fieldId:long}/")]
public Task Update(string name, long fieldId, [FromBody] UpdateFieldDto model) public Task Update(string name, long fieldId, [FromBody] UpdateFieldDto model)
{ {
var command = new UpdateModelField { FieldId = fieldId, Properties = model.Properties }; var command = new UpdateField { FieldId = fieldId, Properties = model.Properties };
return CommandBus.PublishAsync(command); return CommandBus.PublishAsync(command);
} }
@ -43,7 +43,7 @@ namespace PinkParrot.Modules.Api.Schemas
[Route("api/schemas/{name}/fields/{fieldId:long}/hide/")] [Route("api/schemas/{name}/fields/{fieldId:long}/hide/")]
public Task Hide(string name, long fieldId) public Task Hide(string name, long fieldId)
{ {
var command = new HideModelField { FieldId = fieldId }; var command = new HideField { FieldId = fieldId };
return CommandBus.PublishAsync(command); return CommandBus.PublishAsync(command);
} }
@ -52,7 +52,7 @@ namespace PinkParrot.Modules.Api.Schemas
[Route("api/schemas/{name}/fields/{fieldId:long}/show/")] [Route("api/schemas/{name}/fields/{fieldId:long}/show/")]
public Task Show(string name, long fieldId) public Task Show(string name, long fieldId)
{ {
var command = new ShowModelField { FieldId = fieldId }; var command = new ShowField { FieldId = fieldId };
return CommandBus.PublishAsync(command); return CommandBus.PublishAsync(command);
} }
@ -61,7 +61,7 @@ namespace PinkParrot.Modules.Api.Schemas
[Route("api/schemas/{name}/fields/{fieldId:long}/enable/")] [Route("api/schemas/{name}/fields/{fieldId:long}/enable/")]
public Task Enable(string name, long fieldId) public Task Enable(string name, long fieldId)
{ {
var command = new EnableModelField { FieldId = fieldId }; var command = new EnableField { FieldId = fieldId };
return CommandBus.PublishAsync(command); return CommandBus.PublishAsync(command);
} }
@ -70,7 +70,7 @@ namespace PinkParrot.Modules.Api.Schemas
[Route("api/schemas/{name}/fields/{fieldId:long}/disable/")] [Route("api/schemas/{name}/fields/{fieldId:long}/disable/")]
public Task Disable(string name, long fieldId) public Task Disable(string name, long fieldId)
{ {
var command = new DisableModelField { FieldId = fieldId }; var command = new DisableField { FieldId = fieldId };
return CommandBus.PublishAsync(command); return CommandBus.PublishAsync(command);
} }
@ -79,7 +79,7 @@ namespace PinkParrot.Modules.Api.Schemas
[Route("api/schemas/{name}/fields/{fieldId:long}/")] [Route("api/schemas/{name}/fields/{fieldId:long}/")]
public Task Delete(string name, long fieldId) public Task Delete(string name, long fieldId)
{ {
var command = new DeleteModelField { FieldId = fieldId }; var command = new DeleteField { FieldId = fieldId };
return CommandBus.PublishAsync(command); return CommandBus.PublishAsync(command);
} }

24
src/PinkParrot/Modules/Api/Schemas/SchemasController.cs

@ -11,30 +11,30 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using PinkParrot.Core.Schema; using PinkParrot.Core.Schemas;
using PinkParrot.Infrastructure.CQRS.Commands; using PinkParrot.Infrastructure.CQRS.Commands;
using PinkParrot.Infrastructure.Reflection; using PinkParrot.Infrastructure.Reflection;
using PinkParrot.Read.Models; using PinkParrot.Read.Models;
using PinkParrot.Read.Repositories; using PinkParrot.Read.Repositories;
using PinkParrot.Write.Schema.Commands; using PinkParrot.Write.Schemas.Commands;
namespace PinkParrot.Modules.Api.Schemas namespace PinkParrot.Modules.Api.Schemas
{ {
public class SchemasController : ControllerBase public class SchemasController : ControllerBase
{ {
private readonly IModelSchemaRepository modelSchemaRepository; private readonly ISchemaRepository schemaRepository;
public SchemasController(ICommandBus commandBus, IModelSchemaRepository modelSchemaRepository) public SchemasController(ICommandBus commandBus, ISchemaRepository schemaRepository)
: base(commandBus) : base(commandBus)
{ {
this.modelSchemaRepository = modelSchemaRepository; this.schemaRepository = schemaRepository;
} }
[HttpGet] [HttpGet]
[Route("api/schemas/")] [Route("api/schemas/")]
public async Task<List<ListSchemaDto>> Query() public async Task<List<ListSchemaDto>> Query()
{ {
var schemas = await modelSchemaRepository.QueryAllAsync(TenantId); var schemas = await schemaRepository.QueryAllAsync(TenantId);
return schemas.Select(s => SimpleMapper.Map(s, new ListSchemaDto())).ToList(); return schemas.Select(s => SimpleMapper.Map(s, new ListSchemaDto())).ToList();
} }
@ -43,21 +43,21 @@ namespace PinkParrot.Modules.Api.Schemas
[Route("api/schemas/{name}/")] [Route("api/schemas/{name}/")]
public async Task<ActionResult> Get(string name) public async Task<ActionResult> Get(string name)
{ {
var entity = await modelSchemaRepository.FindSchemaAsync(TenantId, name); var entity = await schemaRepository.FindSchemaAsync(TenantId, name);
if (entity == null) if (entity == null)
{ {
return NotFound(); return NotFound();
} }
return Ok(ModelSchemaDto.Create(entity.Schema)); return Ok(SchemaDto.Create(entity.Schema));
} }
[HttpPost] [HttpPost]
[Route("api/schemas/")] [Route("api/schemas/")]
public async Task<ActionResult> Create([FromBody] CreateSchemaDto model) public async Task<ActionResult> Create([FromBody] CreateSchemaDto model)
{ {
var command = SimpleMapper.Map(model, new CreateModelSchema { AggregateId = Guid.NewGuid() }); var command = SimpleMapper.Map(model, new CreateSchema { AggregateId = Guid.NewGuid() });
await CommandBus.PublishAsync(command); await CommandBus.PublishAsync(command);
@ -66,9 +66,9 @@ namespace PinkParrot.Modules.Api.Schemas
[HttpPut] [HttpPut]
[Route("api/schemas/{name}/")] [Route("api/schemas/{name}/")]
public async Task<ActionResult> Update(string name, [FromBody] ModelSchemaProperties schema) public async Task<ActionResult> Update(string name, [FromBody] SchemaProperties schema)
{ {
var command = new UpdateModelSchema { Properties = schema }; var command = new UpdateSchema { Properties = schema };
await CommandBus.PublishAsync(command); await CommandBus.PublishAsync(command);
@ -79,7 +79,7 @@ namespace PinkParrot.Modules.Api.Schemas
[Route("api/schemas/{name}/")] [Route("api/schemas/{name}/")]
public async Task<ActionResult> Delete(string name) public async Task<ActionResult> Delete(string name)
{ {
await CommandBus.PublishAsync(new DeleteModelSchema()); await CommandBus.PublishAsync(new DeleteSchema());
return NoContent(); return NoContent();
} }

12
src/PinkParrot/Pipeline/CommandHandlers/EnrichWithAggregateIdHandler.cs

@ -13,7 +13,7 @@ using PinkParrot.Infrastructure;
using PinkParrot.Infrastructure.CQRS.Commands; using PinkParrot.Infrastructure.CQRS.Commands;
using PinkParrot.Read.Services; using PinkParrot.Read.Services;
using PinkParrot.Write; using PinkParrot.Write;
using PinkParrot.Write.Schema; using PinkParrot.Write.Schemas;
// ReSharper disable InvertIf // ReSharper disable InvertIf
@ -21,12 +21,12 @@ namespace PinkParrot.Pipeline.CommandHandlers
{ {
public sealed class EnrichWithAggregateIdHandler : ICommandHandler public sealed class EnrichWithAggregateIdHandler : ICommandHandler
{ {
private readonly IModelSchemaProvider modelSchemaProvider; private readonly ISchemaProvider schemaProvider;
private readonly IActionContextAccessor actionContextAccessor; private readonly IActionContextAccessor actionContextAccessor;
public EnrichWithAggregateIdHandler(IModelSchemaProvider modelSchemaProvider, IActionContextAccessor actionContextAccessor) public EnrichWithAggregateIdHandler(ISchemaProvider schemaProvider, IActionContextAccessor actionContextAccessor)
{ {
this.modelSchemaProvider = modelSchemaProvider; this.schemaProvider = schemaProvider;
this.actionContextAccessor = actionContextAccessor; this.actionContextAccessor = actionContextAccessor;
} }
@ -53,11 +53,11 @@ namespace PinkParrot.Pipeline.CommandHandlers
{ {
var schemaName = routeValues["name"].ToString(); var schemaName = routeValues["name"].ToString();
var id = await modelSchemaProvider.FindSchemaIdByNameAsync(tenantCommand.TenantId, schemaName); var id = await schemaProvider.FindSchemaIdByNameAsync(tenantCommand.TenantId, schemaName);
if (!id.HasValue) if (!id.HasValue)
{ {
throw new DomainObjectNotFoundException(schemaName, typeof(ModelSchemaDomainObject)); throw new DomainObjectNotFoundException(schemaName, typeof(SchemaDomainObject));
} }
aggregateCommand.AggregateId = id.Value; aggregateCommand.AggregateId = id.Value;

36
src/pinkparrot_core/PinkParrot.Core/Schema/ModelField.cs → src/pinkparrot_core/PinkParrot.Core/Schemas/Field.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ModelField.cs // Field.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -15,9 +15,9 @@ using PinkParrot.Infrastructure.Tasks;
// ReSharper disable InvertIf // ReSharper disable InvertIf
// ReSharper disable ConvertIfStatementToReturnStatement // ReSharper disable ConvertIfStatementToReturnStatement
namespace PinkParrot.Core.Schema namespace PinkParrot.Core.Schemas
{ {
public abstract class ModelField public abstract class Field
{ {
private readonly long id; private readonly long id;
private string name; private string name;
@ -44,7 +44,7 @@ namespace PinkParrot.Core.Schema
get { return isDisabled; } get { return isDisabled; }
} }
public abstract IModelFieldProperties RawProperties { get; } public abstract IFieldProperties RawProperties { get; }
public abstract string Label { get; } public abstract string Label { get; }
@ -52,7 +52,7 @@ namespace PinkParrot.Core.Schema
public abstract bool IsRequired { get; } public abstract bool IsRequired { get; }
protected ModelField(long id, string name) protected Field(long id, string name)
{ {
Guard.GreaterThan(id, 0, nameof(id)); Guard.GreaterThan(id, 0, nameof(id));
Guard.ValidSlug(name, nameof(name)); Guard.ValidSlug(name, nameof(name));
@ -62,7 +62,7 @@ namespace PinkParrot.Core.Schema
this.name = name; this.name = name;
} }
public abstract ModelField Update(IModelFieldProperties newProperties); public abstract Field Update(IFieldProperties newProperties);
public Task ValidateAsync(PropertyValue property, ICollection<string> errors) public Task ValidateAsync(PropertyValue property, ICollection<string> errors)
{ {
@ -86,27 +86,27 @@ namespace PinkParrot.Core.Schema
return TaskHelper.Done; return TaskHelper.Done;
} }
public ModelField Hide() public Field Hide()
{ {
return Update<ModelField>(clone => clone.isHidden = true); return Update<Field>(clone => clone.isHidden = true);
} }
public ModelField Show() public Field Show()
{ {
return Update<ModelField>(clone => clone.isHidden = false); return Update<Field>(clone => clone.isHidden = false);
} }
public ModelField Disable() public Field Disable()
{ {
return Update<ModelField>(clone => clone.isDisabled = true); return Update<Field>(clone => clone.isDisabled = true);
} }
public ModelField Enable() public Field Enable()
{ {
return Update<ModelField>(clone => clone.isDisabled = false); return Update<Field>(clone => clone.isDisabled = false);
} }
public ModelField Rename(string newName) public Field Rename(string newName)
{ {
if (!newName.IsSlug()) if (!newName.IsSlug())
{ {
@ -115,10 +115,10 @@ namespace PinkParrot.Core.Schema
throw new ValidationException($"Cannot rename the field '{name}' ({id})", error); throw new ValidationException($"Cannot rename the field '{name}' ({id})", error);
} }
return Update<ModelField>(clone => clone.name = newName); return Update<Field>(clone => clone.name = newName);
} }
protected T Update<T>(Action<T> updater) where T : ModelField protected T Update<T>(Action<T> updater) where T : Field
{ {
var clone = (T)Clone(); var clone = (T)Clone();
@ -127,6 +127,6 @@ namespace PinkParrot.Core.Schema
return clone; return clone;
} }
protected abstract ModelField Clone(); protected abstract Field Clone();
} }
} }

8
src/pinkparrot_core/PinkParrot.Core/Schema/ModelFieldProperties.cs → src/pinkparrot_core/PinkParrot.Core/Schemas/FieldProperties.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ModelFieldProperties.cs // FieldProperties.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -9,13 +9,13 @@
using System.Collections.Generic; using System.Collections.Generic;
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
namespace PinkParrot.Core.Schema namespace PinkParrot.Core.Schemas
{ {
public abstract class ModelFieldProperties : NamedElementProperties, IModelFieldProperties public abstract class FieldProperties : NamedElementProperties, IFieldProperties
{ {
public bool IsRequired { get; } public bool IsRequired { get; }
protected ModelFieldProperties(string label, string hints, bool isRequired) protected FieldProperties(string label, string hints, bool isRequired)
: base(label, hints) : base(label, hints)
{ {
IsRequired = isRequired; IsRequired = isRequired;

24
src/pinkparrot_core/PinkParrot.Core/Schema/ModelFieldRegistry.cs → src/pinkparrot_core/PinkParrot.Core/Schemas/FieldRegistry.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ModelFieldRegistry.cs // FieldRegistry.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -10,16 +10,16 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
namespace PinkParrot.Core.Schema namespace PinkParrot.Core.Schemas
{ {
public delegate ModelField FactoryFunction(long id, string name, IModelFieldProperties properties); public delegate Field FactoryFunction(long id, string name, IFieldProperties properties);
public sealed class ModelFieldRegistry public sealed class FieldRegistry
{ {
private readonly Dictionary<string, IRegisterModelField> fieldsByTypeName = new Dictionary<string, IRegisterModelField>(); private readonly Dictionary<string, IRegisteredField> fieldsByTypeName = new Dictionary<string, IRegisteredField>();
private readonly Dictionary<Type, IRegisterModelField> fieldsByPropertyType = new Dictionary<Type, IRegisterModelField>(); private readonly Dictionary<Type, IRegisteredField> fieldsByPropertyType = new Dictionary<Type, IRegisteredField>();
private sealed class Registered : IRegisterModelField private sealed class Registered : IRegisteredField
{ {
private readonly FactoryFunction fieldFactory; private readonly FactoryFunction fieldFactory;
private readonly Type propertiesType; private readonly Type propertiesType;
@ -43,13 +43,13 @@ namespace PinkParrot.Core.Schema
this.propertiesType = propertiesType; this.propertiesType = propertiesType;
} }
ModelField IRegisterModelField.CreateField(long id, string name, IModelFieldProperties properties) Field IRegisteredField.CreateField(long id, string name, IFieldProperties properties)
{ {
return fieldFactory(id, name, properties); return fieldFactory(id, name, properties);
} }
} }
public ModelFieldRegistry() public FieldRegistry()
{ {
Add<NumberFieldProperties>((id, name, properties) => new NumberField(id, name, (NumberFieldProperties)properties)); Add<NumberFieldProperties>((id, name, properties) => new NumberField(id, name, (NumberFieldProperties)properties));
} }
@ -64,14 +64,14 @@ namespace PinkParrot.Core.Schema
fieldsByPropertyType[registered.PropertiesType] = registered; fieldsByPropertyType[registered.PropertiesType] = registered;
} }
public ModelField CreateField(long id, string name, IModelFieldProperties properties) public Field CreateField(long id, string name, IFieldProperties properties)
{ {
var registered = fieldsByPropertyType[properties.GetType()]; var registered = fieldsByPropertyType[properties.GetType()];
return registered.CreateField(id, name, properties); return registered.CreateField(id, name, properties);
} }
public IRegisterModelField FindByPropertiesType(Type type) public IRegisteredField FindByPropertiesType(Type type)
{ {
Guard.NotNull(type, nameof(type)); Guard.NotNull(type, nameof(type));
@ -85,7 +85,7 @@ namespace PinkParrot.Core.Schema
return registered; return registered;
} }
public IRegisterModelField FindByTypeName(string typeName) public IRegisteredField FindByTypeName(string typeName)
{ {
Guard.NotNullOrEmpty(typeName, nameof(typeName)); Guard.NotNullOrEmpty(typeName, nameof(typeName));

14
src/pinkparrot_core/PinkParrot.Core/Schema/ModelField_Generic.cs → src/pinkparrot_core/PinkParrot.Core/Schemas/Field_Generic.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ModelField_Generic.cs // Field_Generic.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -9,13 +9,13 @@
using System; using System;
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
namespace PinkParrot.Core.Schema namespace PinkParrot.Core.Schemas
{ {
public abstract class ModelField<T> : ModelField where T : ModelFieldProperties public abstract class Field<T> : Field where T : FieldProperties
{ {
private T properties; private T properties;
public override IModelFieldProperties RawProperties public override IFieldProperties RawProperties
{ {
get { return properties; } get { return properties; }
} }
@ -40,7 +40,7 @@ namespace PinkParrot.Core.Schema
get { return properties; } get { return properties; }
} }
protected ModelField(long id, string name, T properties) protected Field(long id, string name, T properties)
: base(id, name) : base(id, name)
{ {
Guard.NotNull(properties, nameof(properties)); Guard.NotNull(properties, nameof(properties));
@ -48,7 +48,7 @@ namespace PinkParrot.Core.Schema
this.properties = properties; this.properties = properties;
} }
public override ModelField Update(IModelFieldProperties newProperties) public override Field Update(IFieldProperties newProperties)
{ {
Guard.NotNull(newProperties, nameof(newProperties)); Guard.NotNull(newProperties, nameof(newProperties));
@ -61,7 +61,7 @@ namespace PinkParrot.Core.Schema
newProperties.Validate(() => $"Cannot update field with id '{Id}', becase the settings are invalid."); newProperties.Validate(() => $"Cannot update field with id '{Id}', becase the settings are invalid.");
return Update<ModelField<T>>(clone => clone.properties = typedProperties); return Update<Field<T>>(clone => clone.properties = typedProperties);
} }
} }
} }

6
src/pinkparrot_core/PinkParrot.Core/Schema/IModelFieldProperties.cs → src/pinkparrot_core/PinkParrot.Core/Schemas/IFieldProperties.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// IModelFieldProperties.cs // IFieldProperties.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -8,9 +8,9 @@
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
namespace PinkParrot.Core.Schema namespace PinkParrot.Core.Schemas
{ {
public interface IModelFieldProperties : IValidatable public interface IFieldProperties : IValidatable
{ {
} }
} }

8
src/pinkparrot_core/PinkParrot.Core/Schema/IRegisterModelField.cs → src/pinkparrot_core/PinkParrot.Core/Schemas/IRegisteredField.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// IRegisterModelField.cs // IRegisteredField.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -8,12 +8,12 @@
using System; using System;
namespace PinkParrot.Core.Schema namespace PinkParrot.Core.Schemas
{ {
public interface IRegisterModelField public interface IRegisteredField
{ {
Type PropertiesType { get; } Type PropertiesType { get; }
ModelField CreateField(long id, string name, IModelFieldProperties properties); Field CreateField(long id, string name, IFieldProperties properties);
} }
} }

3
src/pinkparrot_core/PinkParrot.Core/Schema/NamedElementProperties.cs → src/pinkparrot_core/PinkParrot.Core/Schemas/NamedElementProperties.cs

@ -5,8 +5,7 @@
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
namespace PinkParrot.Core.Schemas
namespace PinkParrot.Core.Schema
{ {
public abstract class NamedElementProperties public abstract class NamedElementProperties
{ {

8
src/pinkparrot_core/PinkParrot.Core/Schema/NumberField.cs → src/pinkparrot_core/PinkParrot.Core/Schemas/NumberField.cs

@ -14,9 +14,9 @@ using System.Threading.Tasks;
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
using PinkParrot.Infrastructure.Tasks; using PinkParrot.Infrastructure.Tasks;
namespace PinkParrot.Core.Schema namespace PinkParrot.Core.Schemas
{ {
public sealed class NumberField : ModelField<NumberFieldProperties> public sealed class NumberField : Field<NumberFieldProperties>
{ {
public double? MaxValue public double? MaxValue
{ {
@ -67,9 +67,9 @@ namespace PinkParrot.Core.Schema
return TaskHelper.Done; return TaskHelper.Done;
} }
protected override ModelField Clone() protected override Field Clone()
{ {
return (ModelField)MemberwiseClone(); return (Field)MemberwiseClone();
} }
} }
} }

4
src/pinkparrot_core/PinkParrot.Core/Schema/NumberFieldProperties.cs → src/pinkparrot_core/PinkParrot.Core/Schemas/NumberFieldProperties.cs

@ -9,10 +9,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
namespace PinkParrot.Core.Schema namespace PinkParrot.Core.Schemas
{ {
[TypeName("number")] [TypeName("number")]
public sealed class NumberFieldProperties : ModelFieldProperties public sealed class NumberFieldProperties : FieldProperties
{ {
public string Placeholder { get; set; } public string Placeholder { get; set; }

59
src/pinkparrot_core/PinkParrot.Core/Schema/ModelSchema.cs → src/pinkparrot_core/PinkParrot.Core/Schemas/Schema.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ModelSchema.cs // Schema.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -12,33 +12,34 @@ using System.Collections.Immutable;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
// ReSharper disable InvertIf // ReSharper disable InvertIf
namespace PinkParrot.Core.Schema namespace PinkParrot.Core.Schemas
{ {
public sealed class ModelSchema public sealed class Schema
{ {
private readonly string name; private readonly string name;
private readonly ModelSchemaProperties properties; private readonly SchemaProperties properties;
private readonly ImmutableDictionary<long, ModelField> fieldsById; private readonly ImmutableDictionary<long, Field> fieldsById;
private readonly Dictionary<string, ModelField> fieldsByName; private readonly Dictionary<string, Field> fieldsByName;
public string Name public string Name
{ {
get { return name; } get { return name; }
} }
public ImmutableDictionary<long, ModelField> Fields public ImmutableDictionary<long, Field> Fields
{ {
get { return fieldsById; } get { return fieldsById; }
} }
public ModelSchemaProperties Properties public SchemaProperties Properties
{ {
get { return properties; } get { return properties; }
} }
public ModelSchema(string name, ModelSchemaProperties properties, ImmutableDictionary<long, ModelField> fields) public Schema(string name, SchemaProperties properties, ImmutableDictionary<long, Field> fields)
{ {
Guard.NotNull(fields, nameof(fields)); Guard.NotNull(fields, nameof(fields));
Guard.NotNull(properties, nameof(properties)); Guard.NotNull(properties, nameof(properties));
@ -52,28 +53,28 @@ namespace PinkParrot.Core.Schema
fieldsByName = fields.Values.ToDictionary(x => x.Name, StringComparer.OrdinalIgnoreCase); fieldsByName = fields.Values.ToDictionary(x => x.Name, StringComparer.OrdinalIgnoreCase);
} }
public static ModelSchema Create(string name, ModelSchemaProperties newProperties) public static Schema Create(string name, SchemaProperties newProperties)
{ {
newProperties = newProperties ?? new ModelSchemaProperties(null, null); newProperties = newProperties ?? new SchemaProperties(null, null);
if (!name.IsSlug()) if (!name.IsSlug())
{ {
var error = new ValidationError("Name must be a valid slug", "Name"); var error = new ValidationError("Name must be a valid slug", "Name");
throw new ValidationException($"Cannot create a new schema", error); throw new ValidationException("Cannot create a new schema", error);
} }
return new ModelSchema(name, newProperties, ImmutableDictionary<long, ModelField>.Empty); return new Schema(name, newProperties, ImmutableDictionary<long, Field>.Empty);
} }
public ModelSchema Update(ModelSchemaProperties newProperties) public Schema Update(SchemaProperties newProperties)
{ {
Guard.NotNull(newProperties, nameof(newProperties)); Guard.NotNull(newProperties, nameof(newProperties));
return new ModelSchema(name, newProperties, fieldsById); return new Schema(name, newProperties, fieldsById);
} }
public ModelSchema AddOrUpdateField(ModelField field) public Schema AddOrUpdateField(Field field)
{ {
Guard.NotNull(field, nameof(field)); Guard.NotNull(field, nameof(field));
@ -82,53 +83,53 @@ namespace PinkParrot.Core.Schema
throw new ValidationException($"A field with name '{field.Name}' already exists."); throw new ValidationException($"A field with name '{field.Name}' already exists.");
} }
return new ModelSchema(name, properties, fieldsById.SetItem(field.Id, field)); return new Schema(name, properties, fieldsById.SetItem(field.Id, field));
} }
public ModelSchema UpdateField(long fieldId, IModelFieldProperties newProperties) public Schema UpdateField(long fieldId, IFieldProperties newProperties)
{ {
return UpdateField(fieldId, field => field.Update(newProperties)); return UpdateField(fieldId, field => field.Update(newProperties));
} }
public ModelSchema DisableField(long fieldId) public Schema DisableField(long fieldId)
{ {
return UpdateField(fieldId, field => field.Disable()); return UpdateField(fieldId, field => field.Disable());
} }
public ModelSchema EnableField(long fieldId) public Schema EnableField(long fieldId)
{ {
return UpdateField(fieldId, field => field.Enable()); return UpdateField(fieldId, field => field.Enable());
} }
public ModelSchema HideField(long fieldId) public Schema HideField(long fieldId)
{ {
return UpdateField(fieldId, field => field.Show()); return UpdateField(fieldId, field => field.Show());
} }
public ModelSchema ShowField(long fieldId) public Schema ShowField(long fieldId)
{ {
return UpdateField(fieldId, field => field.Show()); return UpdateField(fieldId, field => field.Show());
} }
public ModelSchema RenameField(long fieldId, string newName) public Schema RenameField(long fieldId, string newName)
{ {
return UpdateField(fieldId, field => field.Rename(newName)); return UpdateField(fieldId, field => field.Rename(newName));
} }
public ModelSchema DeleteField(long fieldId) public Schema DeleteField(long fieldId)
{ {
return new ModelSchema(name, properties, fieldsById.Remove(fieldId)); return new Schema(name, properties, fieldsById.Remove(fieldId));
} }
public ModelSchema UpdateField(long fieldId, Func<ModelField, ModelField> updater) public Schema UpdateField(long fieldId, Func<Field, Field> updater)
{ {
Guard.NotNull(updater, nameof(updater)); Guard.NotNull(updater, nameof(updater));
ModelField field; Field field;
if (!fieldsById.TryGetValue(fieldId, out field)) if (!fieldsById.TryGetValue(fieldId, out field))
{ {
throw new DomainObjectNotFoundException(fieldId.ToString(), typeof(ModelField)); throw new DomainObjectNotFoundException(fieldId.ToString(), typeof(Field));
} }
var newField = updater(field); var newField = updater(field);
@ -145,7 +146,7 @@ namespace PinkParrot.Core.Schema
{ {
var fieldErrors = new List<string>(); var fieldErrors = new List<string>();
ModelField field; Field field;
if (fieldsByName.TryGetValue(kvp.Key, out field)) if (fieldsByName.TryGetValue(kvp.Key, out field))
{ {

8
src/pinkparrot_core/PinkParrot.Core/Schema/ModelSchemaProperties.cs → src/pinkparrot_core/PinkParrot.Core/Schemas/SchemaProperties.cs

@ -1,15 +1,15 @@
// ========================================================================== // ==========================================================================
// ModelSchemaProperties.cs // SchemaProperties.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
namespace PinkParrot.Core.Schema namespace PinkParrot.Core.Schemas
{ {
public sealed class ModelSchemaProperties : NamedElementProperties public sealed class SchemaProperties : NamedElementProperties
{ {
public ModelSchemaProperties( public SchemaProperties(
string label, string label,
string hints) string hints)
: base(label, hints) : base(label, hints)

21
src/pinkparrot_events/PinkParrot.Events/Schema/ModelFieldUpdated.cs

@ -1,21 +0,0 @@
// ==========================================================================
// ModelFieldUpdated.cs
// PinkParrot Headless CMS
// ==========================================================================
// Copyright (c) PinkParrot Group
// All rights reserved.
// ==========================================================================
using PinkParrot.Core.Schema;
using PinkParrot.Infrastructure;
namespace PinkParrot.Events.Schema
{
[TypeName("ModelFieldUpdatedEvent")]
public class ModelFieldUpdated : TenantEvent
{
public long FieldId { get; set; }
public IModelFieldProperties Properties { get; set; }
}
}

19
src/pinkparrot_events/PinkParrot.Events/Schema/ModelSchemaUpdated.cs

@ -1,19 +0,0 @@
// ==========================================================================
// ModelSchemaUpdated.cs
// PinkParrot Headless CMS
// ==========================================================================
// Copyright (c) PinkParrot Group
// All rights reserved.
// ==========================================================================
using PinkParrot.Core.Schema;
using PinkParrot.Infrastructure;
namespace PinkParrot.Events.Schema
{
[TypeName("ModelSchemaUpdated")]
public class ModelSchemaUpdated : TenantEvent
{
public ModelSchemaProperties Properties { get; set; }
}
}

12
src/pinkparrot_events/PinkParrot.Events/Schema/ModelFieldAdded.cs → src/pinkparrot_events/PinkParrot.Events/Schemas/FieldAdded.cs

@ -1,23 +1,23 @@
// ========================================================================== // ==========================================================================
// ModelFieldAdded.cs // FieldAdded.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
using PinkParrot.Core.Schema; using PinkParrot.Core.Schemas;
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
namespace PinkParrot.Events.Schema namespace PinkParrot.Events.Schemas
{ {
[TypeName("ModelFieldAddedEvent")] [TypeName("FieldAddedEvent")]
public class ModelFieldAdded : TenantEvent public class FieldAdded : TenantEvent
{ {
public long FieldId { get; set; } public long FieldId { get; set; }
public string Name { get; set; } public string Name { get; set; }
public IModelFieldProperties Properties { get; set; } public IFieldProperties Properties { get; set; }
} }
} }

8
src/pinkparrot_events/PinkParrot.Events/Schema/ModelFieldShown.cs → src/pinkparrot_events/PinkParrot.Events/Schemas/FieldDeleted.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ModelFieldShown.cs // FieldDeleted.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -8,10 +8,10 @@
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
namespace PinkParrot.Events.Schema namespace PinkParrot.Events.Schemas
{ {
[TypeName("ModelFieldShownEvent")] [TypeName("FieldDeletedEvent")]
public class ModelFieldShown : TenantEvent public class FieldDeleted : TenantEvent
{ {
public long FieldId { get; set; } public long FieldId { get; set; }
} }

8
src/pinkparrot_events/PinkParrot.Events/Schema/ModelFieldHidden.cs → src/pinkparrot_events/PinkParrot.Events/Schemas/FieldDisabled.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ModelFieldHidden.cs // FieldDisabled.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -8,10 +8,10 @@
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
namespace PinkParrot.Events.Schema namespace PinkParrot.Events.Schemas
{ {
[TypeName("ModelFieldHiddenEvent")] [TypeName("FieldDisabledEvent")]
public class ModelFieldHidden : TenantEvent public class FieldDisabled : TenantEvent
{ {
public long FieldId { get; set; } public long FieldId { get; set; }
} }

8
src/pinkparrot_events/PinkParrot.Events/Schema/ModelFieldDeleted.cs → src/pinkparrot_events/PinkParrot.Events/Schemas/FieldEnabled.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ModelFieldDeleted.cs // FieldEnabled.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -8,10 +8,10 @@
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
namespace PinkParrot.Events.Schema namespace PinkParrot.Events.Schemas
{ {
[TypeName("ModelFieldDeletedEvent")] [TypeName("FieldEnabledEvent")]
public class ModelFieldDeleted : TenantEvent public class FieldEnabled : TenantEvent
{ {
public long FieldId { get; set; } public long FieldId { get; set; }
} }

8
src/pinkparrot_events/PinkParrot.Events/Schema/ModelFieldEnabled.cs → src/pinkparrot_events/PinkParrot.Events/Schemas/FieldHidden.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ModelFieldEnabled.cs // FieldHidden.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -8,10 +8,10 @@
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
namespace PinkParrot.Events.Schema namespace PinkParrot.Events.Schemas
{ {
[TypeName("ModelFieldEnabledEvent")] [TypeName("FieldHiddenEvent")]
public class ModelFieldEnabled : TenantEvent public class FieldHidden : TenantEvent
{ {
public long FieldId { get; set; } public long FieldId { get; set; }
} }

18
src/pinkparrot_events/PinkParrot.Events/Schemas/FieldShown.cs

@ -0,0 +1,18 @@
// ==========================================================================
// FieldShown.cs
// PinkParrot Headless CMS
// ==========================================================================
// Copyright (c) PinkParrot Group
// All rights reserved.
// ==========================================================================
using PinkParrot.Infrastructure;
namespace PinkParrot.Events.Schemas
{
[TypeName("FieldShownEvent")]
public class FieldShown : TenantEvent
{
public long FieldId { get; set; }
}
}

11
src/pinkparrot_events/PinkParrot.Events/Schema/ModelFieldDisabled.cs → src/pinkparrot_events/PinkParrot.Events/Schemas/FieldUpdated.cs

@ -1,18 +1,21 @@
// ========================================================================== // ==========================================================================
// ModelFieldDisabled.cs // FieldUpdated.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
using PinkParrot.Core.Schemas;
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
namespace PinkParrot.Events.Schema namespace PinkParrot.Events.Schemas
{ {
[TypeName("ModelFieldDisabledEvent")] [TypeName("FieldUpdatedEvent")]
public class ModelFieldDisabled : TenantEvent public class FieldUpdated : TenantEvent
{ {
public long FieldId { get; set; } public long FieldId { get; set; }
public IFieldProperties Properties { get; set; }
} }
} }

12
src/pinkparrot_events/PinkParrot.Events/Schema/ModelSchemaCreated.cs → src/pinkparrot_events/PinkParrot.Events/Schemas/SchemaCreated.cs

@ -1,21 +1,21 @@
// ========================================================================== // ==========================================================================
// ModelSchemaCreated.cs // SchemaCreated.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
using PinkParrot.Core.Schema; using PinkParrot.Core.Schemas;
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
namespace PinkParrot.Events.Schema namespace PinkParrot.Events.Schemas
{ {
[TypeName("ModelSchemaCreatedEvent")] [TypeName("SchemaCreatedEvent")]
public class ModelSchemaCreated : TenantEvent public class SchemaCreated : TenantEvent
{ {
public string Name { get; set; } public string Name { get; set; }
public ModelSchemaProperties Properties { get; set; } public SchemaProperties Properties { get; set; }
} }
} }

8
src/pinkparrot_events/PinkParrot.Events/Schema/ModelSchemaDeleted.cs → src/pinkparrot_events/PinkParrot.Events/Schemas/SchemaDeleted.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ModelSchemaDeleted.cs // SchemaDeleted.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -8,10 +8,10 @@
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
namespace PinkParrot.Events.Schema namespace PinkParrot.Events.Schemas
{ {
[TypeName("ModelSchemaDeleted")] [TypeName("SchemaDeleted")]
public class ModelSchemaDeleted : TenantEvent public class SchemaDeleted : TenantEvent
{ {
} }
} }

19
src/pinkparrot_events/PinkParrot.Events/Schemas/SchemaUpdated.cs

@ -0,0 +1,19 @@
// ==========================================================================
// SchemaUpdated.cs
// PinkParrot Headless CMS
// ==========================================================================
// Copyright (c) PinkParrot Group
// All rights reserved.
// ==========================================================================
using PinkParrot.Core.Schemas;
using PinkParrot.Infrastructure;
namespace PinkParrot.Events.Schemas
{
[TypeName("SchemaUpdated")]
public class SchemaUpdated : TenantEvent
{
public SchemaProperties Properties { get; set; }
}
}

1
src/pinkparrot_infrastructure/PinkParrot.Infrastructure/CQRS/EventStore/IStreamPositionStorage.cs

@ -5,7 +5,6 @@
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
namespace PinkParrot.Infrastructure.CQRS.EventStore namespace PinkParrot.Infrastructure.CQRS.EventStore
{ {
public interface IStreamPositionStorage public interface IStreamPositionStorage

12
src/pinkparrot_read/PinkParrot.Read/Models/ModelFieldDto.cs → src/pinkparrot_read/PinkParrot.Read/Models/FieldDto.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ModelFieldDto.cs // FieldDto.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -7,21 +7,21 @@
// ========================================================================== // ==========================================================================
using Newtonsoft.Json; using Newtonsoft.Json;
using PinkParrot.Core.Schema; using PinkParrot.Core.Schemas;
namespace PinkParrot.Read.Models namespace PinkParrot.Read.Models
{ {
public class ModelFieldDto public class FieldDto
{ {
[JsonProperty] [JsonProperty]
public string Name { get; set; } public string Name { get; set; }
[JsonProperty] [JsonProperty]
public IModelFieldProperties Properties { get; set; } public IFieldProperties Properties { get; set; }
public static ModelFieldDto Create(ModelField field) public static FieldDto Create(Field field)
{ {
return new ModelFieldDto { Name = field.Name, Properties = field.RawProperties }; return new FieldDto { Name = field.Name, Properties = field.RawProperties };
} }
} }
} }

23
src/pinkparrot_read/PinkParrot.Read/Models/ModelSchemaDto.cs → src/pinkparrot_read/PinkParrot.Read/Models/SchemaDto.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ModelSchemaDto.cs // SchemaDto.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -8,44 +8,45 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using PinkParrot.Core.Schema;
using PinkParrot.Infrastructure;
using Newtonsoft.Json; using Newtonsoft.Json;
using PinkParrot.Core.Schemas;
using PinkParrot.Infrastructure;
// ReSharper disable UseObjectOrCollectionInitializer // ReSharper disable UseObjectOrCollectionInitializer
// ReSharper disable InvertIf // ReSharper disable InvertIf
namespace PinkParrot.Read.Models namespace PinkParrot.Read.Models
{ {
public sealed class ModelSchemaDto public sealed class SchemaDto
{ {
[JsonProperty] [JsonProperty]
public string Name { get; set; } public string Name { get; set; }
[JsonProperty] [JsonProperty]
public Dictionary<long, ModelFieldDto> Fields { get; set; } public Dictionary<long, FieldDto> Fields { get; set; }
[JsonProperty] [JsonProperty]
public ModelSchemaProperties Properties { get; set; } public SchemaProperties Properties { get; set; }
public static ModelSchemaDto Create(ModelSchema schema) public static SchemaDto Create(Schema schema)
{ {
Guard.NotNull(schema, nameof(schema)); Guard.NotNull(schema, nameof(schema));
var dto = new ModelSchemaDto { Properties = schema.Properties, Name = schema.Name }; var dto = new SchemaDto { Properties = schema.Properties, Name = schema.Name };
dto.Fields = dto.Fields =
schema.Fields.ToDictionary( schema.Fields.ToDictionary(
kvp => kvp.Key, kvp => kvp.Key,
kvp => ModelFieldDto.Create(kvp.Value)); kvp => FieldDto.Create(kvp.Value));
return dto; return dto;
} }
public ModelSchema ToSchema(ModelFieldRegistry registry) public Schema ToSchema(FieldRegistry registry)
{ {
Guard.NotNull(registry, nameof(registry)); Guard.NotNull(registry, nameof(registry));
var schema = ModelSchema.Create(Name, Properties); var schema = Schema.Create(Name, Properties);
if (Fields != null) if (Fields != null)
{ {

8
src/pinkparrot_read/PinkParrot.Read/Repositories/EntityWithSchema.cs

@ -6,17 +6,17 @@
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
using PinkParrot.Core.Schema; using PinkParrot.Core.Schemas;
namespace PinkParrot.Read.Repositories namespace PinkParrot.Read.Repositories
{ {
public sealed class EntityWithSchema public sealed class EntityWithSchema
{ {
public IModelSchemaEntity Entity { get; } public ISchemaEntity Entity { get; }
public ModelSchema Schema { get; } public Schema Schema { get; }
internal EntityWithSchema(IModelSchemaEntity entity, ModelSchema schema) internal EntityWithSchema(ISchemaEntity entity, Schema schema)
{ {
Entity = entity; Entity = entity;

4
src/pinkparrot_read/PinkParrot.Read/Repositories/IModelSchemaEntity.cs → src/pinkparrot_read/PinkParrot.Read/Repositories/ISchemaEntity.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// IModelSchemaEntity.cs // ISchemaEntity.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -7,7 +7,7 @@
// ========================================================================== // ==========================================================================
namespace PinkParrot.Read.Repositories namespace PinkParrot.Read.Repositories
{ {
public interface IModelSchemaEntity : ITenantEntity public interface ISchemaEntity : ITenantEntity
{ {
string Name { get; } string Name { get; }
} }

6
src/pinkparrot_read/PinkParrot.Read/Repositories/IModelSchemaRepository.cs → src/pinkparrot_read/PinkParrot.Read/Repositories/ISchemaRepository.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// IModelSchemaRepository.cs // ISchemaRepository.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -12,9 +12,9 @@ using System.Threading.Tasks;
namespace PinkParrot.Read.Repositories namespace PinkParrot.Read.Repositories
{ {
public interface IModelSchemaRepository public interface ISchemaRepository
{ {
Task<List<IModelSchemaEntity>> QueryAllAsync(Guid tenantId); Task<List<ISchemaEntity>> QueryAllAsync(Guid tenantId);
Task<Guid?> FindSchemaIdAsync(Guid tenantId, string name); Task<Guid?> FindSchemaIdAsync(Guid tenantId, string name);

2
src/pinkparrot_read/PinkParrot.Read/Repositories/Implementations/Mongo/MongoPositions.cs → src/pinkparrot_read/PinkParrot.Read/Repositories/Implementations/Mongo/MongoPosition.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// MongoPositions.cs // MongoPosition.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group

6
src/pinkparrot_read/PinkParrot.Read/Repositories/Implementations/Mongo/MongoStreamPositionsStorage.cs → src/pinkparrot_read/PinkParrot.Read/Repositories/Implementations/Mongo/MongoPositionStorage.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// MongoStreamPositionsStorage.cs // MongoPositionStorage.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -15,11 +15,11 @@ using PinkParrot.Infrastructure.MongoDb;
namespace PinkParrot.Read.Repositories.Implementations.Mongo namespace PinkParrot.Read.Repositories.Implementations.Mongo
{ {
public sealed class MongoStreamPositionsStorage : MongoRepositoryBase<MongoPosition>, IStreamPositionStorage public sealed class MongoPositionStorage : MongoRepositoryBase<MongoPosition>, IStreamPositionStorage
{ {
private static readonly ObjectId Id = new ObjectId("507f1f77bcf86cd799439011"); private static readonly ObjectId Id = new ObjectId("507f1f77bcf86cd799439011");
public MongoStreamPositionsStorage(IMongoDatabase database) public MongoPositionStorage(IMongoDatabase database)
: base(database) : base(database)
{ {
} }

4
src/pinkparrot_read/PinkParrot.Read/Repositories/Implementations/Mongo/MongoModelSchemaEntity.cs → src/pinkparrot_read/PinkParrot.Read/Repositories/Implementations/Mongo/MongoSchemaEntity.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// MongoModelSchemaEntity.cs // MongoSchemaEntity.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -12,7 +12,7 @@ using MongoDB.Bson.Serialization.Attributes;
namespace PinkParrot.Read.Repositories.Implementations.Mongo namespace PinkParrot.Read.Repositories.Implementations.Mongo
{ {
public sealed class MongoModelSchemaEntity : IModelSchemaEntity public sealed class MongoSchemaEntity : ISchemaEntity
{ {
[BsonId] [BsonId]
[BsonElement] [BsonElement]

54
src/pinkparrot_read/PinkParrot.Read/Repositories/Implementations/Mongo/MongoModelSchemaRepository.cs → src/pinkparrot_read/PinkParrot.Read/Repositories/Implementations/Mongo/MongoSchemaRepository.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// MongoModelSchemaRepository.cs // MongoSchemaRepository.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -12,8 +12,8 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver; using MongoDB.Driver;
using Newtonsoft.Json; using Newtonsoft.Json;
using PinkParrot.Core.Schema; using PinkParrot.Core.Schemas;
using PinkParrot.Events.Schema; using PinkParrot.Events.Schemas;
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
using PinkParrot.Infrastructure.CQRS; using PinkParrot.Infrastructure.CQRS;
using PinkParrot.Infrastructure.CQRS.Events; using PinkParrot.Infrastructure.CQRS.Events;
@ -23,12 +23,12 @@ using PinkParrot.Read.Models;
namespace PinkParrot.Read.Repositories.Implementations.Mongo namespace PinkParrot.Read.Repositories.Implementations.Mongo
{ {
public sealed class MongoModelSchemaRepository : MongoRepositoryBase<MongoModelSchemaEntity>, IModelSchemaRepository, ICatchEventConsumer public sealed class MongoSchemaRepository : MongoRepositoryBase<MongoSchemaEntity>, ISchemaRepository, ICatchEventConsumer
{ {
private readonly JsonSerializerSettings serializerSettings; private readonly JsonSerializerSettings serializerSettings;
private readonly ModelFieldRegistry fieldRegistry; private readonly FieldRegistry fieldRegistry;
public MongoModelSchemaRepository(IMongoDatabase database, JsonSerializerSettings serializerSettings, ModelFieldRegistry fieldRegistry) public MongoSchemaRepository(IMongoDatabase database, JsonSerializerSettings serializerSettings, FieldRegistry fieldRegistry)
: base(database) : base(database)
{ {
Guard.NotNull(serializerSettings, nameof(serializerSettings)); Guard.NotNull(serializerSettings, nameof(serializerSettings));
@ -38,16 +38,16 @@ namespace PinkParrot.Read.Repositories.Implementations.Mongo
this.fieldRegistry = fieldRegistry; this.fieldRegistry = fieldRegistry;
} }
protected override Task SetupCollectionAsync(IMongoCollection<MongoModelSchemaEntity> collection) protected override Task SetupCollectionAsync(IMongoCollection<MongoSchemaEntity> collection)
{ {
return collection.Indexes.CreateOneAsync(IndexKeys.Ascending(x => x.Name)); return collection.Indexes.CreateOneAsync(IndexKeys.Ascending(x => x.Name));
} }
public async Task<List<IModelSchemaEntity>> QueryAllAsync(Guid tenantId) public async Task<List<ISchemaEntity>> QueryAllAsync(Guid tenantId)
{ {
var entities = await Collection.Find(s => s.TenantId == tenantId && !s.IsDeleted).ToListAsync(); var entities = await Collection.Find(s => s.TenantId == tenantId && !s.IsDeleted).ToListAsync();
return entities.OfType<IModelSchemaEntity>().ToList(); return entities.OfType<ISchemaEntity>().ToList();
} }
public async Task<EntityWithSchema> FindSchemaAsync(Guid tenantId, string name) public async Task<EntityWithSchema> FindSchemaAsync(Guid tenantId, string name)
@ -72,65 +72,65 @@ namespace PinkParrot.Read.Repositories.Implementations.Mongo
{ {
var entity = var entity =
await Collection.Find(s => s.Name == name & s.TenantId == tenantId && !s.IsDeleted) await Collection.Find(s => s.Name == name & s.TenantId == tenantId && !s.IsDeleted)
.Project<MongoModelSchemaEntity>(Projection.Include(x => x.Id)).FirstOrDefaultAsync(); .Project<MongoSchemaEntity>(Projection.Include(x => x.Id)).FirstOrDefaultAsync();
return entity?.Id; return entity?.Id;
} }
public Task On(ModelSchemaDeleted @event, EnvelopeHeaders headers) public Task On(SchemaDeleted @event, EnvelopeHeaders headers)
{ {
return Collection.UpdateAsync(headers, e => e.IsDeleted = true); return Collection.UpdateAsync(headers, e => e.IsDeleted = true);
} }
public Task On(ModelFieldDeleted @event, EnvelopeHeaders headers) public Task On(FieldDeleted @event, EnvelopeHeaders headers)
{ {
return UpdateSchema(headers, s => s.DeleteField(@event.FieldId)); return UpdateSchema(headers, s => s.DeleteField(@event.FieldId));
} }
public Task On(ModelFieldDisabled @event, EnvelopeHeaders headers) public Task On(FieldDisabled @event, EnvelopeHeaders headers)
{ {
return UpdateSchema(headers, s => s.DisableField(@event.FieldId)); return UpdateSchema(headers, s => s.DisableField(@event.FieldId));
} }
public Task On(ModelFieldEnabled @event, EnvelopeHeaders headers) public Task On(FieldEnabled @event, EnvelopeHeaders headers)
{ {
return UpdateSchema(headers, s => s.EnableField(@event.FieldId)); return UpdateSchema(headers, s => s.EnableField(@event.FieldId));
} }
public Task On(ModelFieldHidden @event, EnvelopeHeaders headers) public Task On(FieldHidden @event, EnvelopeHeaders headers)
{ {
return UpdateSchema(headers, s => s.HideField(@event.FieldId)); return UpdateSchema(headers, s => s.HideField(@event.FieldId));
} }
public Task On(ModelFieldShown @event, EnvelopeHeaders headers) public Task On(FieldShown @event, EnvelopeHeaders headers)
{ {
return UpdateSchema(headers, s => s.ShowField(@event.FieldId)); return UpdateSchema(headers, s => s.ShowField(@event.FieldId));
} }
public Task On(ModelFieldUpdated @event, EnvelopeHeaders headers) public Task On(FieldUpdated @event, EnvelopeHeaders headers)
{ {
return UpdateSchema(headers, s => s.UpdateField(@event.FieldId, @event.Properties)); return UpdateSchema(headers, s => s.UpdateField(@event.FieldId, @event.Properties));
} }
public Task On(ModelSchemaUpdated @event, EnvelopeHeaders headers) public Task On(SchemaUpdated @event, EnvelopeHeaders headers)
{ {
return UpdateSchema(headers, s => s.Update(@event.Properties)); return UpdateSchema(headers, s => s.Update(@event.Properties));
} }
public Task On(ModelFieldAdded @event, EnvelopeHeaders headers) public Task On(FieldAdded @event, EnvelopeHeaders headers)
{ {
var field = fieldRegistry.CreateField(@event.FieldId, @event.Name, @event.Properties); var field = fieldRegistry.CreateField(@event.FieldId, @event.Name, @event.Properties);
return UpdateSchema(headers, s => s.AddOrUpdateField(field)); return UpdateSchema(headers, s => s.AddOrUpdateField(field));
} }
public Task On(ModelSchemaCreated @event, EnvelopeHeaders headers) public Task On(SchemaCreated @event, EnvelopeHeaders headers)
{ {
return Collection.CreateAsync(headers, e => return Collection.CreateAsync(headers, e =>
{ {
e.Name = @event.Name; e.Name = @event.Name;
Serialize(e, ModelSchema.Create(@event.Name, @event.Properties)); Serialize(e, Schema.Create(@event.Name, @event.Properties));
}); });
} }
@ -139,7 +139,7 @@ namespace PinkParrot.Read.Repositories.Implementations.Mongo
return this.DispatchActionAsync(@event.Payload, @event.Headers); return this.DispatchActionAsync(@event.Payload, @event.Headers);
} }
private void UpdateSchema(MongoModelSchemaEntity entity, Func<ModelSchema, ModelSchema> updater) private void UpdateSchema(MongoSchemaEntity entity, Func<Schema, Schema> updater)
{ {
var currentSchema = Deserialize(entity); var currentSchema = Deserialize(entity);
@ -148,21 +148,21 @@ namespace PinkParrot.Read.Repositories.Implementations.Mongo
Serialize(entity, currentSchema); Serialize(entity, currentSchema);
} }
private Task UpdateSchema(EnvelopeHeaders headers, Func<ModelSchema, ModelSchema> updater) private Task UpdateSchema(EnvelopeHeaders headers, Func<Schema, Schema> updater)
{ {
return Collection.UpdateAsync(headers, e=> UpdateSchema(e, updater)); return Collection.UpdateAsync(headers, e=> UpdateSchema(e, updater));
} }
private void Serialize(MongoModelSchemaEntity entity, ModelSchema schema) private void Serialize(MongoSchemaEntity entity, Schema schema)
{ {
var dto = ModelSchemaDto.Create(schema); var dto = SchemaDto.Create(schema);
entity.Schema = dto.ToJsonBsonDocument(serializerSettings); entity.Schema = dto.ToJsonBsonDocument(serializerSettings);
} }
private ModelSchema Deserialize(MongoModelSchemaEntity entity) private Schema Deserialize(MongoSchemaEntity entity)
{ {
var dto = entity?.Schema.ToJsonObject<ModelSchemaDto>(serializerSettings); var dto = entity?.Schema.ToJsonObject<SchemaDto>(serializerSettings);
return dto?.ToSchema(fieldRegistry); return dto?.ToSchema(fieldRegistry);
} }

4
src/pinkparrot_read/PinkParrot.Read/Services/IModelSchemaProvider.cs → src/pinkparrot_read/PinkParrot.Read/Services/ISchemaProvider.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// IModelSchemaProvider.cs // ISchemaProvider.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -11,7 +11,7 @@ using System.Threading.Tasks;
namespace PinkParrot.Read.Services namespace PinkParrot.Read.Services
{ {
public interface IModelSchemaProvider public interface ISchemaProvider
{ {
Task<Guid?> FindSchemaIdByNameAsync(Guid tenantId, string name); Task<Guid?> FindSchemaIdByNameAsync(Guid tenantId, string name);
} }

13
src/pinkparrot_read/PinkParrot.Read/Services/Implementations/ModelSchemaProvider.cs → src/pinkparrot_read/PinkParrot.Read/Services/Implementations/CachingSchemaProvider.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ModelSchemaProvider.cs // CachingSchemaProvider.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -9,22 +9,23 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Caching.Memory;
using PinkParrot.Events.Schema; using PinkParrot.Events.Schemas;
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
using PinkParrot.Infrastructure.CQRS; using PinkParrot.Infrastructure.CQRS;
using PinkParrot.Infrastructure.CQRS.Events; using PinkParrot.Infrastructure.CQRS.Events;
using PinkParrot.Read.Repositories; using PinkParrot.Read.Repositories;
// ReSharper disable InvertIf // ReSharper disable InvertIf
namespace PinkParrot.Read.Services.Implementations namespace PinkParrot.Read.Services.Implementations
{ {
public class ModelSchemaProvider : IModelSchemaProvider, ILiveEventConsumer public class CachingSchemaProvider : ISchemaProvider, ILiveEventConsumer
{ {
private static readonly TimeSpan CacheDuration = TimeSpan.FromMinutes(10); private static readonly TimeSpan CacheDuration = TimeSpan.FromMinutes(10);
private readonly IMemoryCache cache; private readonly IMemoryCache cache;
private readonly IModelSchemaRepository repository; private readonly ISchemaRepository repository;
public ModelSchemaProvider(IMemoryCache cache, IModelSchemaRepository repository) public CachingSchemaProvider(IMemoryCache cache, ISchemaRepository repository)
{ {
Guard.NotNull(cache, nameof(cache)); Guard.NotNull(cache, nameof(cache));
Guard.NotNull(repository, nameof(repository)); Guard.NotNull(repository, nameof(repository));
@ -58,7 +59,7 @@ namespace PinkParrot.Read.Services.Implementations
public Task On(Envelope<IEvent> @event) public Task On(Envelope<IEvent> @event)
{ {
if (@event.Payload is ModelSchemaUpdated || @event.Payload is ModelSchemaDeleted) if (@event.Payload is SchemaUpdated || @event.Payload is SchemaDeleted)
{ {
var oldName = cache.Get<string>(BuildNamesCacheKey(@event.Headers.AggregateId())); var oldName = cache.Get<string>(BuildNamesCacheKey(@event.Headers.AggregateId()));

17
src/pinkparrot_write/PinkParrot.Write/Schema/Commands/UpdateModelSchema.cs

@ -1,17 +0,0 @@
// ==========================================================================
// UpdateModelSchema.cs
// PinkParrot Headless CMS
// ==========================================================================
// Copyright (c) PinkParrot Group
// All rights reserved.
// ==========================================================================
using PinkParrot.Core.Schema;
namespace PinkParrot.Write.Schema.Commands
{
public class UpdateModelSchema : TenantCommand
{
public ModelSchemaProperties Properties { get; set; }
}
}

6
src/pinkparrot_write/PinkParrot.Write/Schema/Commands/AddModelField.cs → src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/AddField.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// AddModelField.cs // AddField.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -8,9 +8,9 @@
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace PinkParrot.Write.Schema.Commands namespace PinkParrot.Write.Schemas.Commands
{ {
public class AddModelField : TenantCommand public class AddField : TenantCommand
{ {
public string Name { get; set; } public string Name { get; set; }

10
src/pinkparrot_write/PinkParrot.Write/Schema/Commands/CreateModelSchema.cs → src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/CreateSchema.cs

@ -1,19 +1,19 @@
// ========================================================================== // ==========================================================================
// CreateModelSchema.cs // CreateSchema.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
using PinkParrot.Core.Schema; using PinkParrot.Core.Schemas;
namespace PinkParrot.Write.Schema.Commands namespace PinkParrot.Write.Schemas.Commands
{ {
public class CreateModelSchema : TenantCommand public class CreateSchema : TenantCommand
{ {
public string Name { get; set; } public string Name { get; set; }
public ModelSchemaProperties Properties { get; set; } public SchemaProperties Properties { get; set; }
} }
} }

7
src/pinkparrot_write/PinkParrot.Write/Schema/Commands/DeleteModelField.cs → src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/DeleteField.cs

@ -1,14 +1,13 @@
// ========================================================================== // ==========================================================================
// DeleteModelField.cs // DeleteField.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
namespace PinkParrot.Write.Schemas.Commands
namespace PinkParrot.Write.Schema.Commands
{ {
public class DeleteModelField : TenantCommand public class DeleteField : TenantCommand
{ {
public long FieldId { get; set; } public long FieldId { get; set; }
} }

7
src/pinkparrot_write/PinkParrot.Write/Schema/Commands/DeleteModelSchema.cs → src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/DeleteSchema.cs

@ -1,14 +1,13 @@
// ========================================================================== // ==========================================================================
// DeleteModelSchema.cs // DeleteSchema.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
namespace PinkParrot.Write.Schemas.Commands
namespace PinkParrot.Write.Schema.Commands
{ {
public class DeleteModelSchema : TenantCommand public class DeleteSchema : TenantCommand
{ {
} }
} }

7
src/pinkparrot_write/PinkParrot.Write/Schema/Commands/ShowModelField.cs → src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/DisableField.cs

@ -1,14 +1,13 @@
// ========================================================================== // ==========================================================================
// ShowModelField.cs // DisableField.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
namespace PinkParrot.Write.Schemas.Commands
namespace PinkParrot.Write.Schema.Commands
{ {
public class ShowModelField : TenantCommand public class DisableField : TenantCommand
{ {
public long FieldId { get; set; } public long FieldId { get; set; }
} }

7
src/pinkparrot_write/PinkParrot.Write/Schema/Commands/HideModelField.cs → src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/EnableField.cs

@ -1,14 +1,13 @@
// ========================================================================== // ==========================================================================
// HideModelField.cs // EnableField.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
namespace PinkParrot.Write.Schemas.Commands
namespace PinkParrot.Write.Schema.Commands
{ {
public class HideModelField : TenantCommand public class EnableField : TenantCommand
{ {
public long FieldId { get; set; } public long FieldId { get; set; }
} }

7
src/pinkparrot_write/PinkParrot.Write/Schema/Commands/EnableModelField.cs → src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/HideField.cs

@ -1,14 +1,13 @@
// ========================================================================== // ==========================================================================
// EnableModelField.cs // HideField.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
namespace PinkParrot.Write.Schemas.Commands
namespace PinkParrot.Write.Schema.Commands
{ {
public class EnableModelField : TenantCommand public class HideField : TenantCommand
{ {
public long FieldId { get; set; } public long FieldId { get; set; }
} }

7
src/pinkparrot_write/PinkParrot.Write/Schema/Commands/DisableModelField.cs → src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/ShowField.cs

@ -1,14 +1,13 @@
// ========================================================================== // ==========================================================================
// DisableModelField.cs // ShowField.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
namespace PinkParrot.Write.Schemas.Commands
namespace PinkParrot.Write.Schema.Commands
{ {
public class DisableModelField : TenantCommand public class ShowField : TenantCommand
{ {
public long FieldId { get; set; } public long FieldId { get; set; }
} }

6
src/pinkparrot_write/PinkParrot.Write/Schema/Commands/UpdateModelField.cs → src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/UpdateField.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// UpdateModelField.cs // UpdateField.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -8,9 +8,9 @@
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace PinkParrot.Write.Schema.Commands namespace PinkParrot.Write.Schemas.Commands
{ {
public class UpdateModelField : TenantCommand public class UpdateField : TenantCommand
{ {
public long FieldId { get; set; } public long FieldId { get; set; }

17
src/pinkparrot_write/PinkParrot.Write/Schemas/Commands/UpdateSchema.cs

@ -0,0 +1,17 @@
// ==========================================================================
// UpdateSchema.cs
// PinkParrot Headless CMS
// ==========================================================================
// Copyright (c) PinkParrot Group
// All rights reserved.
// ==========================================================================
using PinkParrot.Core.Schemas;
namespace PinkParrot.Write.Schemas.Commands
{
public class UpdateSchema : TenantCommand
{
public SchemaProperties Properties { get; set; }
}
}

42
src/pinkparrot_write/PinkParrot.Write/Schema/ModelSchemaCommandHandler.cs → src/pinkparrot_write/PinkParrot.Write/Schemas/SchemaCommandHandler.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ModelSchemaCommandHandler.cs // SchemaCommandHandler.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -10,21 +10,21 @@ using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using PinkParrot.Core.Schema; using PinkParrot.Core.Schemas;
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
using PinkParrot.Infrastructure.CQRS.Commands; using PinkParrot.Infrastructure.CQRS.Commands;
using PinkParrot.Infrastructure.Dispatching; using PinkParrot.Infrastructure.Dispatching;
using PinkParrot.Write.Schema.Commands; using PinkParrot.Write.Schemas.Commands;
namespace PinkParrot.Write.Schema namespace PinkParrot.Write.Schemas
{ {
public class ModelSchemaCommandHandler : CommandHandler<ModelSchemaDomainObject> public class SchemaCommandHandler : CommandHandler<SchemaDomainObject>
{ {
private readonly ModelFieldRegistry registry; private readonly FieldRegistry registry;
private readonly JsonSerializer serializer; private readonly JsonSerializer serializer;
public ModelSchemaCommandHandler( public SchemaCommandHandler(
ModelFieldRegistry registry, FieldRegistry registry,
IDomainObjectFactory domainObjectFactory, IDomainObjectFactory domainObjectFactory,
IDomainObjectRepository domainObjectRepository, IDomainObjectRepository domainObjectRepository,
JsonSerializer serializer) JsonSerializer serializer)
@ -40,47 +40,47 @@ namespace PinkParrot.Write.Schema
return context.IsHandled ? Task.FromResult(false) : this.DispatchActionAsync(context.Command); return context.IsHandled ? Task.FromResult(false) : this.DispatchActionAsync(context.Command);
} }
public Task On(CreateModelSchema command) public Task On(CreateSchema command)
{ {
return CreateAsync(command, s => s.Create(command.TenantId, command.Name, command.Properties)); return CreateAsync(command, s => s.Create(command.TenantId, command.Name, command.Properties));
} }
public Task On(DeleteModelSchema command) public Task On(DeleteSchema command)
{ {
return UpdateAsync(command, s => s.Delete()); return UpdateAsync(command, s => s.Delete());
} }
public Task On(DeleteModelField command) public Task On(DeleteField command)
{ {
return UpdateAsync(command, s => s.DeleteField(command.FieldId)); return UpdateAsync(command, s => s.DeleteField(command.FieldId));
} }
public Task On(DisableModelField command) public Task On(DisableField command)
{ {
return UpdateAsync(command, s => s.DisableField(command.FieldId)); return UpdateAsync(command, s => s.DisableField(command.FieldId));
} }
public Task On(EnableModelField command) public Task On(EnableField command)
{ {
return UpdateAsync(command, s => s.EnableField(command.FieldId)); return UpdateAsync(command, s => s.EnableField(command.FieldId));
} }
public Task On(HideModelField command) public Task On(HideField command)
{ {
return UpdateAsync(command, s => s.HideField(command.FieldId)); return UpdateAsync(command, s => s.HideField(command.FieldId));
} }
public Task On(ShowModelField command) public Task On(ShowField command)
{ {
return UpdateAsync(command, s => s.ShowField(command.FieldId)); return UpdateAsync(command, s => s.ShowField(command.FieldId));
} }
public Task On(UpdateModelSchema command) public Task On(UpdateSchema command)
{ {
return UpdateAsync(command, s => s.Update(command.Properties)); return UpdateAsync(command, s => s.Update(command.Properties));
} }
public Task On(AddModelField command) public Task On(AddField command)
{ {
var propertiesType = registry.FindByTypeName(command.Type).PropertiesType; var propertiesType = registry.FindByTypeName(command.Type).PropertiesType;
var propertiesValue = CreateProperties(command.Properties, propertiesType); var propertiesValue = CreateProperties(command.Properties, propertiesType);
@ -88,7 +88,7 @@ namespace PinkParrot.Write.Schema
return UpdateAsync(command, s => s.AddField(command.Name, propertiesValue)); return UpdateAsync(command, s => s.AddField(command.Name, propertiesValue));
} }
public Task On(UpdateModelField command) public Task On(UpdateField command)
{ {
return UpdateAsync(command, s => return UpdateAsync(command, s =>
{ {
@ -96,7 +96,7 @@ namespace PinkParrot.Write.Schema
if (field == null) if (field == null)
{ {
throw new DomainObjectNotFoundException(command.FieldId.ToString(), typeof(ModelField)); throw new DomainObjectNotFoundException(command.FieldId.ToString(), typeof(Field));
} }
var propertiesType = registry.FindByPropertiesType(field.RawProperties.GetType()).PropertiesType; var propertiesType = registry.FindByPropertiesType(field.RawProperties.GetType()).PropertiesType;
@ -106,9 +106,9 @@ namespace PinkParrot.Write.Schema
}); });
} }
private IModelFieldProperties CreateProperties(JToken token, Type type) private IFieldProperties CreateProperties(JToken token, Type type)
{ {
return (IModelFieldProperties)token.ToObject(type, serializer); return (IFieldProperties)token.ToObject(type, serializer);
} }
} }
} }

68
src/pinkparrot_write/PinkParrot.Write/Schema/ModelSchemaDomainObject.cs → src/pinkparrot_write/PinkParrot.Write/Schemas/SchemaDomainObject.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// ModelSchemaDomainObject.cs // SchemaDomainObject.cs
// PinkParrot Headless CMS // PinkParrot Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) PinkParrot Group // Copyright (c) PinkParrot Group
@ -7,24 +7,24 @@
// ========================================================================== // ==========================================================================
using System; using System;
using PinkParrot.Core.Schema; using PinkParrot.Core.Schemas;
using PinkParrot.Events.Schema; using PinkParrot.Events.Schemas;
using PinkParrot.Infrastructure; using PinkParrot.Infrastructure;
using PinkParrot.Infrastructure.CQRS; using PinkParrot.Infrastructure.CQRS;
using PinkParrot.Infrastructure.CQRS.Events; using PinkParrot.Infrastructure.CQRS.Events;
using PinkParrot.Infrastructure.Dispatching; using PinkParrot.Infrastructure.Dispatching;
namespace PinkParrot.Write.Schema namespace PinkParrot.Write.Schemas
{ {
public class ModelSchemaDomainObject : DomainObject, ITenantAggregate public class SchemaDomainObject : DomainObject, ITenantAggregate
{ {
private readonly ModelFieldRegistry registry; private readonly FieldRegistry registry;
private Guid tenantId; private Guid tenantId;
private bool isDeleted; private bool isDeleted;
private long totalFields; private long totalFields;
private ModelSchema schema; private Schema schema;
public ModelSchema Schema public Schema Schema
{ {
get { return schema; } get { return schema; }
} }
@ -39,7 +39,7 @@ namespace PinkParrot.Write.Schema
get { return isDeleted; } get { return isDeleted; }
} }
public ModelSchemaDomainObject(Guid id, int version, ModelFieldRegistry registry) public SchemaDomainObject(Guid id, int version, FieldRegistry registry)
: base(id, version) : base(id, version)
{ {
Guard.NotNull(registry, nameof(registry)); Guard.NotNull(registry, nameof(registry));
@ -47,128 +47,128 @@ namespace PinkParrot.Write.Schema
this.registry = registry; this.registry = registry;
} }
public void On(ModelFieldAdded @event) public void On(FieldAdded @event)
{ {
totalFields++; totalFields++;
schema = schema.AddOrUpdateField(registry.CreateField(@event.FieldId, @event.Name, @event.Properties)); schema = schema.AddOrUpdateField(registry.CreateField(@event.FieldId, @event.Name, @event.Properties));
} }
public void On(ModelSchemaCreated @event) public void On(SchemaCreated @event)
{ {
tenantId = @event.TenantId; tenantId = @event.TenantId;
schema = ModelSchema.Create(@event.Name, @event.Properties); schema = Schema.Create(@event.Name, @event.Properties);
} }
public void On(ModelFieldUpdated @event) public void On(FieldUpdated @event)
{ {
schema = schema.UpdateField(@event.FieldId, @event.Properties); schema = schema.UpdateField(@event.FieldId, @event.Properties);
} }
public void On(ModelFieldHidden @event) public void On(FieldHidden @event)
{ {
schema = schema.HideField(@event.FieldId); schema = schema.HideField(@event.FieldId);
} }
public void On(ModelFieldShown @event) public void On(FieldShown @event)
{ {
schema = schema.ShowField(@event.FieldId); schema = schema.ShowField(@event.FieldId);
} }
public void On(ModelFieldDisabled @event) public void On(FieldDisabled @event)
{ {
schema = schema.DisableField(@event.FieldId); schema = schema.DisableField(@event.FieldId);
} }
public void On(ModelFieldEnabled @event) public void On(FieldEnabled @event)
{ {
schema = schema.EnableField(@event.FieldId); schema = schema.EnableField(@event.FieldId);
} }
public void On(ModelSchemaUpdated @event) public void On(SchemaUpdated @event)
{ {
schema = schema.Update(@event.Properties); schema = schema.Update(@event.Properties);
} }
public void On(ModelFieldDeleted @event) public void On(FieldDeleted @event)
{ {
schema = schema.DeleteField(@event.FieldId); schema = schema.DeleteField(@event.FieldId);
} }
public void On(ModelSchemaDeleted @event) public void On(SchemaDeleted @event)
{ {
isDeleted = false; isDeleted = false;
} }
public void AddField(string name, IModelFieldProperties properties) public void AddField(string name, IFieldProperties properties)
{ {
VerifyCreatedAndNotDeleted(); VerifyCreatedAndNotDeleted();
RaiseEvent(new ModelFieldAdded { FieldId = ++totalFields, Name = name, Properties = properties }); RaiseEvent(new FieldAdded { FieldId = ++totalFields, Name = name, Properties = properties });
} }
public void Create(Guid newTenantId, string name, ModelSchemaProperties properties) public void Create(Guid newTenantId, string name, SchemaProperties properties)
{ {
VerifyNotCreated(); VerifyNotCreated();
RaiseEvent(new ModelSchemaCreated { TenantId = newTenantId, Name = name, Properties = properties }); RaiseEvent(new SchemaCreated { TenantId = newTenantId, Name = name, Properties = properties });
} }
public void Update(ModelSchemaProperties properties) public void Update(SchemaProperties properties)
{ {
VerifyCreatedAndNotDeleted(); VerifyCreatedAndNotDeleted();
RaiseEvent(new ModelSchemaUpdated { Properties = properties }); RaiseEvent(new SchemaUpdated { Properties = properties });
} }
public void UpdateField(long fieldId, IModelFieldProperties properties) public void UpdateField(long fieldId, IFieldProperties properties)
{ {
VerifyCreatedAndNotDeleted(); VerifyCreatedAndNotDeleted();
RaiseEvent(new ModelFieldUpdated { FieldId = fieldId, Properties = properties }); RaiseEvent(new FieldUpdated { FieldId = fieldId, Properties = properties });
} }
public void HideField(long fieldId) public void HideField(long fieldId)
{ {
VerifyCreatedAndNotDeleted(); VerifyCreatedAndNotDeleted();
RaiseEvent(new ModelFieldHidden { FieldId = fieldId }); RaiseEvent(new FieldHidden { FieldId = fieldId });
} }
public void ShowField(long fieldId) public void ShowField(long fieldId)
{ {
VerifyCreatedAndNotDeleted(); VerifyCreatedAndNotDeleted();
RaiseEvent(new ModelFieldShown { FieldId = fieldId }); RaiseEvent(new FieldShown { FieldId = fieldId });
} }
public void DisableField(long fieldId) public void DisableField(long fieldId)
{ {
VerifyCreatedAndNotDeleted(); VerifyCreatedAndNotDeleted();
RaiseEvent(new ModelFieldDisabled { FieldId = fieldId }); RaiseEvent(new FieldDisabled { FieldId = fieldId });
} }
public void EnableField(long fieldId) public void EnableField(long fieldId)
{ {
VerifyCreatedAndNotDeleted(); VerifyCreatedAndNotDeleted();
RaiseEvent(new ModelFieldEnabled { FieldId = fieldId }); RaiseEvent(new FieldEnabled { FieldId = fieldId });
} }
public void DeleteField(long fieldId) public void DeleteField(long fieldId)
{ {
VerifyCreatedAndNotDeleted(); VerifyCreatedAndNotDeleted();
RaiseEvent(new ModelFieldDeleted { FieldId = fieldId }); RaiseEvent(new FieldDeleted { FieldId = fieldId });
} }
public void Delete() public void Delete()
{ {
VerifyCreatedAndNotDeleted(); VerifyCreatedAndNotDeleted();
RaiseEvent(new ModelSchemaDeleted()); RaiseEvent(new SchemaDeleted());
} }
private void VerifyNotCreated() private void VerifyNotCreated()
Loading…
Cancel
Save