mirror of https://github.com/Squidex/squidex.git
43 changed files with 535 additions and 97 deletions
@ -0,0 +1,74 @@ |
|||||
|
// ==========================================================================
|
||||
|
// SchemaFieldsController.cs
|
||||
|
// PinkParrot Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) PinkParrot Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using PinkParrot.Infrastructure.CQRS.Commands; |
||||
|
using PinkParrot.Write.Schema.Commands; |
||||
|
|
||||
|
namespace PinkParrot.Modules.Api.Schemas |
||||
|
{ |
||||
|
public class SchemasFieldsController : Controller |
||||
|
{ |
||||
|
private readonly ICommandBus commandBus; |
||||
|
|
||||
|
public SchemasFieldsController(ICommandBus commandBus) |
||||
|
{ |
||||
|
this.commandBus = commandBus; |
||||
|
} |
||||
|
|
||||
|
[HttpPost] |
||||
|
[Route("schemas/{name}/fields/")] |
||||
|
public Task Add(AddModelField command) |
||||
|
{ |
||||
|
return commandBus.PublishAsync(command); |
||||
|
} |
||||
|
|
||||
|
[HttpPut] |
||||
|
[Route("schemas/{name}/fields/{fieldId:long}/")] |
||||
|
public Task Update(UpdateModelField command) |
||||
|
{ |
||||
|
return commandBus.PublishAsync(command); |
||||
|
} |
||||
|
|
||||
|
[HttpPut] |
||||
|
[Route("schemas/{name}/fields/{fieldId:long}/hide/")] |
||||
|
public Task Hide(HideModelField command) |
||||
|
{ |
||||
|
return commandBus.PublishAsync(command); |
||||
|
} |
||||
|
|
||||
|
[HttpPut] |
||||
|
[Route("schemas/{name}/fields/{fieldId:long}/show/")] |
||||
|
public Task Show(ShowModelField command) |
||||
|
{ |
||||
|
return commandBus.PublishAsync(command); |
||||
|
} |
||||
|
|
||||
|
[HttpPut] |
||||
|
[Route("schemas/{name}/fields/{fieldId:long}/enable/")] |
||||
|
public Task Enable(EnableModelField command) |
||||
|
{ |
||||
|
return commandBus.PublishAsync(command); |
||||
|
} |
||||
|
|
||||
|
[HttpPut] |
||||
|
[Route("schemas/{name}/fields/{fieldId:long}/disable/")] |
||||
|
public Task Enable(DisableModelField command) |
||||
|
{ |
||||
|
return commandBus.PublishAsync(command); |
||||
|
} |
||||
|
|
||||
|
[HttpDelete] |
||||
|
[Route("schemas/{name}/fields/{fieldId:long}/")] |
||||
|
public Task Delete(DeleteModelField command) |
||||
|
{ |
||||
|
return commandBus.PublishAsync(command); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,26 +1,55 @@ |
|||||
using System.Threading.Tasks; |
// ==========================================================================
|
||||
|
// SchemasController.cs
|
||||
|
// PinkParrot Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) PinkParrot Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
using Microsoft.AspNetCore.Mvc; |
using Microsoft.AspNetCore.Mvc; |
||||
|
using PinkParrot.Infrastructure.CQRS.Commands; |
||||
|
using PinkParrot.Read.Models; |
||||
|
using PinkParrot.Write.Schema.Commands; |
||||
|
|
||||
namespace PinkParrot.Modules.Api.Schemas |
namespace PinkParrot.Modules.Api.Schemas |
||||
{ |
{ |
||||
public class SchemasController : Controller |
public class SchemasController : Controller |
||||
{ |
{ |
||||
|
private readonly ICommandBus commandBus; |
||||
|
|
||||
|
public SchemasController(ICommandBus commandBus) |
||||
|
{ |
||||
|
this.commandBus = commandBus; |
||||
|
} |
||||
|
|
||||
|
[HttpGet] |
||||
|
[Route("schemas/")] |
||||
|
public Task<List<ModelSchemaRM>> Query() |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
[HttpPost] |
[HttpPost] |
||||
[Route("schemas/")] |
[Route("schemas/")] |
||||
public async Task Create() |
public Task Create(CreateModelSchema command) |
||||
{ |
{ |
||||
|
return commandBus.PublishAsync(command); |
||||
} |
} |
||||
|
|
||||
[HttpPut] |
[HttpPut] |
||||
[Route("schemas/{name}/")] |
[Route("schemas/{name}/")] |
||||
public async Task Update() |
public Task Update(UpdateModelSchema command) |
||||
{ |
{ |
||||
|
return commandBus.PublishAsync(command); |
||||
} |
} |
||||
|
|
||||
[HttpDelete] |
[HttpDelete] |
||||
[Route("schemas/{name}/")] |
[Route("schemas/{name}/")] |
||||
public async Task Delete() |
public Task Delete() |
||||
{ |
{ |
||||
|
return commandBus.PublishAsync(new DeleteModelSchema()); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
// ==========================================================================
|
||||
|
// TenantEvent.cs
|
||||
|
// PinkParrot Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) PinkParrot Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using PinkParrot.Infrastructure.CQRS.Events; |
||||
|
|
||||
|
namespace PinkParrot.Events |
||||
|
{ |
||||
|
public class TenantEvent : IEvent |
||||
|
{ |
||||
|
public Guid TenantId; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
// ==========================================================================
|
||||
|
// AutofacDomainObjectFactory.cs
|
||||
|
// PinkParrot Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) PinkParrot Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using Autofac; |
||||
|
using PinkParrot.Infrastructure.CQRS.Commands; |
||||
|
|
||||
|
namespace PinkParrot.Infrastructure.CQRS.Autofac |
||||
|
{ |
||||
|
public sealed class AutofacDomainObjectFactory : IDomainObjectFactory |
||||
|
{ |
||||
|
private readonly IContainer container; |
||||
|
|
||||
|
public AutofacDomainObjectFactory(IContainer container) |
||||
|
{ |
||||
|
Guard.NotNull(container, nameof(container)); |
||||
|
|
||||
|
this.container = container; |
||||
|
} |
||||
|
|
||||
|
public IAggregate CreateNew(Type type, Guid id) |
||||
|
{ |
||||
|
return (IAggregate)container.Resolve(type, |
||||
|
new NamedParameter("id", id), |
||||
|
new NamedParameter("version", 0)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace PinkParrot.Infrastructure.CQRS.GetEventStore |
||||
|
{ |
||||
|
public class GetEventStoreDomainObjectRepository |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -1,15 +0,0 @@ |
|||||
using System; |
|
||||
|
|
||||
namespace PinkParrot.Infrastructure.CQRS.Commands |
|
||||
{ |
|
||||
public interface ICommandContext |
|
||||
{ |
|
||||
ICommand Command { get; } |
|
||||
Exception Exception { get; } |
|
||||
IDomainObjectFactory Factory { get; } |
|
||||
bool IsFailed { get; } |
|
||||
bool IsHandled { get; } |
|
||||
bool IsSucceeded { get; } |
|
||||
IDomainObjectRepository Repository { get; } |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,16 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace PinkParrot.Read.Models |
||||
|
{ |
||||
|
public sealed class ModelSchemaRM |
||||
|
{ |
||||
|
public string Id { get; set; } |
||||
|
|
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
public Guid SchemaId { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<Project ToolsVersion="14.0.25420" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
|
<PropertyGroup> |
||||
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.25420</VisualStudioVersion> |
||||
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> |
||||
|
</PropertyGroup> |
||||
|
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" /> |
||||
|
<PropertyGroup Label="Globals"> |
||||
|
<ProjectGuid>a92b4734-2587-4f6f-97a3-741be48709a5</ProjectGuid> |
||||
|
<RootNamespace>PinkParrot.Read</RootNamespace> |
||||
|
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath> |
||||
|
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<SchemaVersion>2.0</SchemaVersion> |
||||
|
</PropertyGroup> |
||||
|
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" /> |
||||
|
</Project> |
||||
@ -0,0 +1,19 @@ |
|||||
|
// ==========================================================================
|
||||
|
// IModelSchemaRepository.cs
|
||||
|
// PinkParrot Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) PinkParrot Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using PinkParrot.Read.Models; |
||||
|
|
||||
|
namespace PinkParrot.Read.Repositories |
||||
|
{ |
||||
|
public interface IModelSchemaRepository |
||||
|
{ |
||||
|
Task<List<ModelSchemaRM>> QueryAllAsync(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,42 @@ |
|||||
|
// ==========================================================================
|
||||
|
// MongoDbModelSchemaRepository.cs
|
||||
|
// PinkParrot Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) PinkParrot Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Bson; |
||||
|
using MongoDB.Driver; |
||||
|
using PinkParrot.Read.Models; |
||||
|
using PinkParrot.Read.Repositories.MongoDb.Utils; |
||||
|
|
||||
|
namespace PinkParrot.Read.Repositories.MongoDb |
||||
|
{ |
||||
|
public sealed class MongoDbModelSchemaRepository : BaseRepository<ModelSchemaRM>, IModelSchemaRepository |
||||
|
{ |
||||
|
public MongoDbModelSchemaRepository(IMongoDatabase database) |
||||
|
: base(database, "ModelSchemas") |
||||
|
{ |
||||
|
CreateIndicesAsync().Wait(); |
||||
|
} |
||||
|
|
||||
|
private async Task CreateIndicesAsync() |
||||
|
{ |
||||
|
await Collection.Indexes.CreateOneAsync(IndexKeys.Ascending(x => x.SchemaId)); |
||||
|
} |
||||
|
|
||||
|
public IQueryable<ModelSchemaRM> QuerySchemas() |
||||
|
{ |
||||
|
return Collection.AsQueryable(); |
||||
|
} |
||||
|
|
||||
|
public Task<List<ModelSchemaRM>> QueryAllAsync() |
||||
|
{ |
||||
|
return Collection.Find(s => true).ToListAsync(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Driver; |
||||
|
using PinkParrot.Infrastructure; |
||||
|
|
||||
|
namespace PinkParrot.Read.Repositories.MongoDb.Utils |
||||
|
{ |
||||
|
public abstract class BaseRepository<T> |
||||
|
{ |
||||
|
private readonly IMongoCollection<T> collection; |
||||
|
private readonly IndexKeysDefinitionBuilder<T> indexKeys = new IndexKeysDefinitionBuilder<T>(); |
||||
|
|
||||
|
protected IMongoCollection<T> Collection |
||||
|
{ |
||||
|
get { return collection; } |
||||
|
} |
||||
|
|
||||
|
protected IndexKeysDefinitionBuilder<T> IndexKeys |
||||
|
{ |
||||
|
get { return indexKeys; } |
||||
|
} |
||||
|
|
||||
|
protected BaseRepository(IMongoDatabase database, string collectioName) |
||||
|
{ |
||||
|
Guard.NotNull(database, nameof(database)); |
||||
|
Guard.NotNullOrEmpty(collectioName, nameof(collectioName)); |
||||
|
|
||||
|
collection = database.GetCollection<T>(collectioName); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
{ |
||||
|
"version": "1.0.0-*", |
||||
|
|
||||
|
"dependencies": { |
||||
|
"MongoDB.Driver": "2.3.0-rc1", |
||||
|
"NETStandard.Library": "1.6.0", |
||||
|
"NodaTime": "2.0.0-alpha20160729", |
||||
|
"PinkParrot.Core": "1.0.0-*", |
||||
|
"PinkParrot.Events": "1.0.0-*", |
||||
|
"PinkParrot.Infrastructure": "1.0.0-*" |
||||
|
}, |
||||
|
|
||||
|
"frameworks": { |
||||
|
"netcoreapp1.0": { |
||||
|
"dependencies": { |
||||
|
"Microsoft.NETCore.App": { |
||||
|
"type": "platform", |
||||
|
"version": "1.0.0" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
"tooling": { |
||||
|
"defaultNamespace": "PinkParrot.Read" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
// ==========================================================================
|
||||
|
// ISchemaIdProvider.cs
|
||||
|
// PinkParrot Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) PinkParrot Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace PinkParrot.Write.Schema |
||||
|
{ |
||||
|
public interface ISchemaIdProvider |
||||
|
{ |
||||
|
Task<Guid> FindSchemaId(string name); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,70 @@ |
|||||
|
// ==========================================================================
|
||||
|
// ModelSchemaNameMap.cs
|
||||
|
// PinkParrot Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) PinkParrot Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using PinkParrot.Events.Schema; |
||||
|
using PinkParrot.Infrastructure.CQRS; |
||||
|
using PinkParrot.Infrastructure.CQRS.Events; |
||||
|
using PinkParrot.Infrastructure.Dispatching; |
||||
|
// ReSharper disable InvertIf
|
||||
|
|
||||
|
namespace PinkParrot.Write.Schema |
||||
|
{ |
||||
|
public class ModelSchemaNameMap : DomainObject |
||||
|
{ |
||||
|
private readonly Dictionary<string, Guid> schemaIdsByName = new Dictionary<string, Guid>(); |
||||
|
private readonly Dictionary<Guid, string> schemaNamesByIds = new Dictionary<Guid, string>(); |
||||
|
|
||||
|
public ModelSchemaNameMap(Guid id, int version) |
||||
|
: base(id, version) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
protected void On(ModelSchemaDeleted @event, EnvelopeHeaders headers) |
||||
|
{ |
||||
|
var aggregateId = headers.AggregateId(); |
||||
|
|
||||
|
string oldName; |
||||
|
|
||||
|
if (schemaNamesByIds.TryGetValue(aggregateId, out oldName)) |
||||
|
{ |
||||
|
schemaIdsByName.Remove(oldName); |
||||
|
schemaNamesByIds.Remove(aggregateId); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected void On(ModelSchemaUpdated @event, EnvelopeHeaders headers) |
||||
|
{ |
||||
|
var aggregateId = headers.AggregateId(); |
||||
|
|
||||
|
string oldName; |
||||
|
|
||||
|
if (schemaNamesByIds.TryGetValue(aggregateId, out oldName)) |
||||
|
{ |
||||
|
schemaIdsByName.Remove(oldName); |
||||
|
schemaIdsByName[@event.NewName] = aggregateId; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected void On(ModelSchemaCreated @event, EnvelopeHeaders headers) |
||||
|
{ |
||||
|
schemaIdsByName[@event.Name] = headers.AggregateId(); |
||||
|
} |
||||
|
|
||||
|
public void Apply(Envelope<IEvent> @event) |
||||
|
{ |
||||
|
ApplyEvent(@event); |
||||
|
} |
||||
|
|
||||
|
protected override void ApplyEvent(Envelope<IEvent> @event) |
||||
|
{ |
||||
|
this.DispatchAction(@event.Payload, @event.Headers); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue