Skip to content

Commit

Permalink
Merge pull request #114 from J-Tech-Japan/92-read-model-updater-basic
Browse files Browse the repository at this point in the history
improving document and read model updator
  • Loading branch information
tomohisa authored Sep 29, 2023
2 parents e739095 + 096a4bf commit c156042
Show file tree
Hide file tree
Showing 34 changed files with 286 additions and 124 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"azureFunctions.projectSubpath": "src\\Sekiban.Testing"
"azureFunctions.projectSubpath": "src\\Sekiban.Testing",
"cSpell.words": [
"Stöckl"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Sekiban.Testing" Version="0.14.4" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Sekiban.Core" Version="0.14.4" />
<PackageReference Include="Sekiban.Core" Version="0.14.5" />
</ItemGroup>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.11" />
<PackageReference Include="Sekiban.Infrastructure.Cosmos" Version="0.14.4" />
<PackageReference Include="Sekiban.Web" Version="0.14.4" />
<PackageReference Include="Sekiban.Infrastructure.Cosmos" Version="0.14.5" />
<PackageReference Include="Sekiban.Web" Version="0.14.5" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.11" />
<PackageReference Include="Sekiban.Infrastructure.Dynamo" Version="0.14.4" />
<PackageReference Include="Sekiban.Web" Version="0.14.4" />
<PackageReference Include="Sekiban.Infrastructure.Dynamo" Version="0.14.5" />
<PackageReference Include="Sekiban.Web" Version="0.14.5" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
using Sekiban.Core.Dependency;
using Sekiban.Infrastructure.Cosmos;
using Sekiban.Web.Dependency;
using SekibanEventSourcingBasics.Cosmos.Web;
using SekibanEventSourcingBasics.Domain;
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Sekiban Core Setting
builder.Services.AddSekibanCoreWithDependency(new DomainDependency(), configuration: builder.Configuration);
// Sekiban Cosmos Setting
builder.Services.AddSekibanCosmosDB();
// Sekiban Web Setting
builder.Services.AddSekibanWeb(new SekibanWebDependency());

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.11" />
<PackageReference Include="Sekiban.Infrastructure.Cosmos" Version="0.14.5" />
<PackageReference Include="Sekiban.Web" Version="0.14.5" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SekibanEventSourcingBasics.Domain\SekibanEventSourcingBasics.Domain.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Sekiban.Web.Authorizations;
using Sekiban.Web.Common;
using Sekiban.Web.Dependency;
using SekibanEventSourcingBasics.Domain;
namespace SekibanEventSourcingBasics.Cosmos.Web;

public class SekibanWebDependency : DomainDependency, IWebDependencyDefinition
{
public bool ShouldMakeSimpleAggregateListQueries => true;
public bool ShouldMakeSimpleSingleProjectionListQueries => true;
public AuthorizeDefinitionCollection AuthorizationDefinitions => new();
public SekibanControllerOptions Options => new();
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,17 @@
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Sekiban": {
"Default": {
"AggregateEventCosmosDbContainer": "events",
"AggregateEventCosmosDbContainerDissolvable": "dissolvableevents",
"BlobConnectionString": "[Set your blob connection string here. (not necessary for just running the sample)]",
"CosmosDbEndPointUrl": "[Set your CosmosDb endpoint url here.]",
"CosmosDbAuthorizationKey": "[Set your CosmosDb authorization key here.]",
"CosmosDbDatabase": "SekibanBasics",
"CosmosDbContainer": "items",
"CosmosDbContainerDissolvable": "dissolvableitems"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sekiban.Core.Aggregate;
using Sekiban.Core.Command;
using Sekiban.Core.Events;

namespace SekibanEventSourcingBasics.Domain.Aggregates.UserPoints;


public record CreateUserPoint(
[property: Required]string Name,
[property:Required, EmailAddress]string Email,
[property:Range(0,10000)] int Point) : ICommand<UserPoint>
{
// Assign new Aggregate Id by NewGuid()
public Guid GetAggregateId() => Guid.NewGuid();

public class Handler : ICommandHandler<UserPoint, CreateUserPoint>
{
public IEnumerable<IEventPayloadApplicableTo<UserPoint>> HandleCommand(Func<AggregateState<UserPoint>> getAggregateState, CreateUserPoint command)
{
yield return new UserPointCreated(command.Name, command.Email, command.Point);
}
}
}
using SekibanEventSourcingBasics.Domain.Aggregates.UserPoints.Events;
using System.ComponentModel.DataAnnotations;
namespace SekibanEventSourcingBasics.Domain.Aggregates.UserPoints.Commands;

public record ChangeUserPointName(
[property: Required] Guid UserPointId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Sekiban.Core.Aggregate;
using Sekiban.Core.Command;
using Sekiban.Core.Events;
using SekibanEventSourcingBasics.Domain.Aggregates.UserPoints.Events;
using System.ComponentModel.DataAnnotations;
namespace SekibanEventSourcingBasics.Domain.Aggregates.UserPoints.Commands;


public record CreateUserPoint(
[property: Required]string Name,
[property:Required, EmailAddress]string Email,
[property:Range(0,10000)] int Point) : ICommand<UserPoint>
{
// Assign new Aggregate Id by NewGuid()
public Guid GetAggregateId() => Guid.NewGuid();

public class Handler : ICommandHandler<UserPoint, CreateUserPoint>
{
public IEnumerable<IEventPayloadApplicableTo<UserPoint>> HandleCommand(Func<AggregateState<UserPoint>> getAggregateState, CreateUserPoint command)
{
yield return new UserPointCreated(command.Name, command.Email, command.Point);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Sekiban.Core.Events;
namespace SekibanEventSourcingBasics.Domain.Aggregates.UserPoints.Events;

public record UserPointCreated(string Name, string Email, int Point) : IEventPayload<UserPoint, UserPointCreated>
{
public static UserPoint OnEvent(UserPoint aggregatePayload, Event<UserPointCreated> ev) =>
new(ev.Payload.Name, ev.Payload.Email, ev.Payload.Point);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Sekiban.Core.Events;
namespace SekibanEventSourcingBasics.Domain.Aggregates.UserPoints.Events;

public record UserPointNameChanged(string ChangedName) : IEventPayload<UserPoint, UserPointNameChanged>
{
public static UserPoint OnEvent(UserPoint aggregatePayload, Event<UserPointNameChanged> ev) =>
aggregatePayload with { Name = ev.Payload.ChangedName };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Sekiban.Core.Events;
namespace SekibanEventSourcingBasics.Domain.Aggregates.UserPoints.Events;

public record UserPointReceived(int Point, string Note) : IEventPayload<UserPoint, UserPointReceived>
{
public static UserPoint OnEvent(UserPoint aggregatePayload, Event<UserPointReceived> ev) =>
aggregatePayload with { Point = aggregatePayload.Point + ev.Payload.Point };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Sekiban.Core.Events;
namespace SekibanEventSourcingBasics.Domain.Aggregates.UserPoints.Events;

public record UserPointUsed(int Point, string Note) : IEventPayload<UserPoint, UserPointUsed>
{
public static UserPoint OnEvent(UserPoint aggregatePayload, Event<UserPointUsed> ev) =>
aggregatePayload with { Point = aggregatePayload.Point - ev.Payload.Point };
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,10 @@
using System.Text;
using System.Threading.Tasks;
using Sekiban.Core.Aggregate;
using Sekiban.Core.Events;

namespace SekibanEventSourcingBasics.Domain.Aggregates.UserPoints;

public record UserPoint(string Name, string Email, int Point) : IAggregatePayload<UserPoint>
{
public static UserPoint CreateInitialPayload(UserPoint? _) => new UserPoint(string.Empty,string.Empty,0);
}

public record UserPointCreated(string Name, string Email, int Point) : IEventPayload<UserPoint, UserPointCreated>
{
public static UserPoint OnEvent(UserPoint aggregatePayload, Event<UserPointCreated> ev) =>
new(ev.Payload.Name, ev.Payload.Email, ev.Payload.Point);
}

public record UserPointNameChanged(string ChangedName) : IEventPayload<UserPoint, UserPointNameChanged>
{
public static UserPoint OnEvent(UserPoint aggregatePayload, Event<UserPointNameChanged> ev) =>
aggregatePayload with { Name = ev.Payload.ChangedName };
}

public record UserPointReceived(int Point, string Note) : IEventPayload<UserPoint, UserPointReceived>
{
public static UserPoint OnEvent(UserPoint aggregatePayload, Event<UserPointReceived> ev) =>
aggregatePayload with { Point = aggregatePayload.Point + ev.Payload.Point };
}

public record UserPointUsed(int Point, string Note) : IEventPayload<UserPoint, UserPointUsed>
{
public static UserPoint OnEvent(UserPoint aggregatePayload, Event<UserPointUsed> ev) =>
aggregatePayload with { Point = aggregatePayload.Point - ev.Payload.Point };
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
using System.Threading.Tasks;
using Sekiban.Core.Dependency;
using SekibanEventSourcingBasics.Domain.Aggregates.UserPoints;
using SekibanEventSourcingBasics.Domain.Aggregates.UserPoints.Commands;

namespace SekibanEventSourcingBasics.Domain;

internal class DomainDependency : DomainDependencyDefinitionBase
public class DomainDependency : DomainDependencyDefinitionBase
{
public override Assembly GetExecutingAssembly()
{
return Assembly.GetExecutingAssembly();
}
public override Assembly GetExecutingAssembly() => Assembly.GetExecutingAssembly();

public override void Define()
{
AddAggregate<UserPoint>();
AddAggregate<UserPoint>()
.AddCommandHandler<CreateUserPoint, CreateUserPoint.Handler>()
.AddCommandHandler<ChangeUserPointName, ChangeUserPointName.Handler>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
Loading

0 comments on commit c156042

Please sign in to comment.