Skip to content

Commit

Permalink
Merge pull request #352 from J-Tech-Japan/351-tenant-command-and-quer…
Browse files Browse the repository at this point in the history
…y-need-to-be-gettenantid-not-tenantid-get

Fixed TenantId {get;} to GetTenantId()
  • Loading branch information
tomohisa authored Aug 15, 2024
2 parents f457346 + 747fb40 commit 8f4139c
Show file tree
Hide file tree
Showing 275 changed files with 2,842 additions and 1,258 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using ResultBoxes;
using Sekiban.Core.Aggregate;
using Sekiban.Core.Query.MultiProjections.Projections;
using Sekiban.Core.Query.QueryModel;
Expand All @@ -17,14 +16,4 @@ public record Parameter(Guid BranchId) : IQueryParameter<Response>, IQueryParame
}

public record Response(bool Exists) : IQueryResponse;
}
public record BranchExistsQueryN(Guid BranchId)
: INextAggregateQuery<Branch, bool>, IQueryParameterMultiProjectionOptionSettable
{
public ResultBox<bool> HandleFilter(IEnumerable<AggregateState<Branch>> list, IQueryContext context)
{
return ResultBox.FromValue(list.Any(b => b.AggregateId == BranchId));
}

public MultiProjectionRetrievalOptions? MultiProjectionRetrievalOptions { get; init; } = null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using ResultBoxes;
using Sekiban.Core.Aggregate;
using Sekiban.Core.Query.MultiProjections.Projections;
using Sekiban.Core.Query.QueryModel;
namespace FeatureCheck.Domain.Aggregates.Branches.Queries;

public record BranchExistsQueryN(Guid BranchId)
: INextAggregateQuery<Branch, bool>, IQueryParameterMultiProjectionOptionSettable
{
public ResultBox<bool> HandleFilter(IEnumerable<AggregateState<Branch>> list, IQueryContext context)
{
return ResultBox.FromValue(list.Any(b => b.AggregateId == BranchId));
}

public MultiProjectionRetrievalOptions? MultiProjectionRetrievalOptions { get; init; } = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ public Response HandleFilter(Parameter queryParam, IEnumerable<AggregateState<Te
return list.Any(m => m.Payload.Email == queryParam.Email) ? new Response(true) : new Response(false);
}

public record Parameter(string TenantId, string Email) : ITenantQueryParameter<Response>;
public record Parameter(string TenantId, string Email) : ITenantQueryParameter<Response>
{
public string GetTenantId() => TenantId;
}

public record Response(bool IsDuplicate) : IQueryResponse;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
using Sekiban.Core.Query.QueryModel;
namespace MultiTenant.Domain.Aggregates.Clients.Queries;

public class ClientListQuery : ITenantAggregateListQuery<ClientPayload, ClientListQuery.Parameter, ClientListQuery.Response>
public class
ClientListQuery : ITenantAggregateListQuery<ClientPayload, ClientListQuery.Parameter, ClientListQuery.Response>
{
public IEnumerable<Response> HandleFilter(Parameter queryParam, IEnumerable<AggregateState<ClientPayload>> list) =>
list.Select(m => new Response(m.Payload.Name));
public IEnumerable<Response> HandleSort(Parameter queryParam, IEnumerable<Response> filteredList) => filteredList.OrderBy(m => m.Name);
public record Parameter(string TenantId) : ITenantListQueryParameter<Response>;
public IEnumerable<Response> HandleSort(Parameter queryParam, IEnumerable<Response> filteredList) =>
filteredList.OrderBy(m => m.Name);
public record Parameter(string TenantId) : ITenantListQueryParameter<Response>
{
public string GetTenantId() => TenantId;
}

public record Response(string Name) : IQueryResponse;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>Sekiban.Aspire.Infrastructure.Cosmos</PackageId>
<Version>0.20.7</Version>
<Version>0.21.0</Version>
<Authors>J-Tech Group</Authors>
<Company>J-Tech-Japan</Company>
<PackageDescription>Sekiban - Event Sourcing Framework Cosmos Aspire Connector</PackageDescription>
<PackageVersion>0.20.7</PackageVersion>
<PackageVersion>0.21.0</PackageVersion>
<Description>Beta Support for F#</Description>
<RepositoryUrl>https://github.com/J-Tech-Japan/Sekiban</RepositoryUrl>
<RootNamespace>Sekiban.Aspire.Infrastructure.Cosmos</RootNamespace>
Expand All @@ -23,8 +23,8 @@

<ItemGroup>
<PackageReference Include="Aspire.Azure.Storage.Blobs" Version="8.1.0" />
<PackageReference Include="Sekiban.Infrastructure.Cosmos" Version="0.20.7"/>
<PackageReference Include="Sekiban.Web" Version="0.20.7"/>
<PackageReference Include="Sekiban.Infrastructure.Cosmos" Version="0.21.0"/>
<PackageReference Include="Sekiban.Web" Version="0.21.0"/>
<ProjectReference Include="..\Sekiban.Infrastructure.Cosmos\Sekiban.Infrastructure.Cosmos.csproj"/>
<ProjectReference Include="..\Sekiban.Web\Sekiban.Web.csproj"/>
<None Include="..\README.md" Pack="true" PackagePath="\"/>
Expand Down
12 changes: 5 additions & 7 deletions src/Sekiban.Core/Aggregate/AggregateCommon.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using Sekiban.Core.Documents.ValueObjects;
using Sekiban.Core.Events;
using Sekiban.Core.Exceptions;
using Sekiban.Core.Query.SingleProjections;
using Sekiban.Core.Snapshot.Aggregate;
using Sekiban.Core.Types;
using System.Reflection;
namespace Sekiban.Core.Aggregate;

/// <summary>
Expand Down Expand Up @@ -126,10 +123,11 @@ public static TAggregatePayload CreatePayload<TAggregatePayload>() where TAggreg
}
if (typeof(TAggregatePayload).IsAggregatePayloadType())
{
var method = typeof(TAggregatePayload).GetMethodInfoForCreateInstanceFromAggregatePayload()
?? typeof(TAggregatePayload).GetMethods()
.FirstOrDefault(m =>
m.Name.EndsWith(
var method = typeof(TAggregatePayload).GetMethodInfoForCreateInstanceFromAggregatePayload() ??
typeof(TAggregatePayload)
.GetMethods()
.FirstOrDefault(
m => m.Name.EndsWith(
$".{nameof(IAggregatePayloadGeneratable<TAggregatePayload>.CreateInitialPayload)}"));
var created = method?.Invoke(typeof(TAggregatePayload), [null]);
var converted = created is TAggregatePayload payload ? payload : default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class AggregateContainerGroupAttribute : Attribute
{

public AggregateContainerGroup Group { get; init; }
public AggregateContainerGroupAttribute(AggregateContainerGroup group = AggregateContainerGroup.Default) => Group = group;
public AggregateContainerGroupAttribute(AggregateContainerGroup group = AggregateContainerGroup.Default) =>
Group = group;

public static AggregateContainerGroup FindAggregateContainerGroup(Type type)
{
Expand All @@ -41,7 +42,9 @@ public static AggregateContainerGroup FindAggregateContainerGroup(Type type)
continue;
}

var attributes = (AggregateContainerGroupAttribute[])type.GetCustomAttributes(typeof(AggregateContainerGroupAttribute), true);
var attributes = (AggregateContainerGroupAttribute[])type.GetCustomAttributes(
typeof(AggregateContainerGroupAttribute),
true);
var max = attributes.Max(m => m.Group);
return max;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Sekiban.Core/Aggregate/IAggregatePayloadGeneratable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Sekiban.Core.Aggregate;

public interface IAggregatePayloadGeneratable<TAggregatePayload> : IAggregatePayloadCommon where TAggregatePayload : IAggregatePayloadCommon
public interface IAggregatePayloadGeneratable<TAggregatePayload> : IAggregatePayloadCommon
where TAggregatePayload : IAggregatePayloadCommon
{
public static abstract TAggregatePayload CreateInitialPayload(TAggregatePayload? _);
}
5 changes: 3 additions & 2 deletions src/Sekiban.Core/Aggregate/IAggregateSubtypePayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Sekiban.Core.Aggregate;
/// <typeparam name="TParentAggregatePayload">Parent Aggregate Payload</typeparam>
/// <typeparam name="TSubtypeAggregatePayload">Subtype Aggregate Payload (This record itself)</typeparam>
public interface
IAggregateSubtypePayload<TParentAggregatePayload, TSubtypeAggregatePayload> : IAggregateSubtypePayloadParentApplicable<TParentAggregatePayload>,
IAggregatePayloadGeneratable<TSubtypeAggregatePayload> where TParentAggregatePayload : IAggregatePayloadCommon
IAggregateSubtypePayload<TParentAggregatePayload, TSubtypeAggregatePayload> :
IAggregateSubtypePayloadParentApplicable<TParentAggregatePayload>,
IAggregatePayloadGeneratable<TSubtypeAggregatePayload> where TParentAggregatePayload : IAggregatePayloadCommon
where TSubtypeAggregatePayload : IAggregateSubtypePayload<TParentAggregatePayload, TSubtypeAggregatePayload>;
13 changes: 9 additions & 4 deletions src/Sekiban.Core/Aggregate/IParentAggregatePayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ namespace Sekiban.Core.Aggregate;
/// CartAggregate : IParentAggregatePayload<CartAggregate>
/// ]]></code>
/// </typeparam>
public interface IParentAggregatePayload<TParentAggregatePayload> : IParentAggregatePayload<TParentAggregatePayload, TParentAggregatePayload>,
IAggregatePayloadGeneratable<TParentAggregatePayload> where TParentAggregatePayload : IAggregatePayloadGeneratable<TParentAggregatePayload>;
public interface
IParentAggregatePayload<TParentAggregatePayload> :
IParentAggregatePayload<TParentAggregatePayload, TParentAggregatePayload>,
IAggregatePayloadGeneratable<TParentAggregatePayload>
where TParentAggregatePayload : IAggregatePayloadGeneratable<TParentAggregatePayload>;
/// <summary>
/// Parent Aggregate Payload
/// Developer can implement this interface to define the state of your aggregate.
Expand All @@ -32,5 +35,7 @@ public interface IParentAggregatePayload<TParentAggregatePayload> : IParentAggre
/// aggregate. In other words, it refers to types when they initiate or start for the first time.
/// </typeparam>
// ReSharper disable once UnusedTypeParameter
public interface IParentAggregatePayload<TParentAggregatePayload, TFirstAggregatePayload> : IParentAggregatePayloadCommon<TParentAggregatePayload>
where TParentAggregatePayload : IAggregatePayloadCommon where TFirstAggregatePayload : IAggregatePayloadGeneratable<TFirstAggregatePayload>;
public interface
IParentAggregatePayload<TParentAggregatePayload, TFirstAggregatePayload> : IParentAggregatePayloadCommon<
TParentAggregatePayload> where TParentAggregatePayload : IAggregatePayloadCommon
where TFirstAggregatePayload : IAggregatePayloadGeneratable<TFirstAggregatePayload>;
3 changes: 2 additions & 1 deletion src/Sekiban.Core/Aggregate/IParentAggregatePayloadCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ namespace Sekiban.Core.Aggregate;
/// Note : No need to implement this interface. It is used internally.
/// </summary>
/// <typeparam name="TParentAggregatePayload">Refers Parent Aggregate Itself</typeparam>
public interface IParentAggregatePayloadCommon<TParentAggregatePayload> : IApplicableAggregatePayload<TParentAggregatePayload>
public interface
IParentAggregatePayloadCommon<TParentAggregatePayload> : IApplicableAggregatePayload<TParentAggregatePayload>
where TParentAggregatePayload : IAggregatePayloadCommon;
7 changes: 5 additions & 2 deletions src/Sekiban.Core/Aggregate/SekibanAggregateTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public SekibanAggregateTypes(params Assembly[] assemblies)
}
_registeredTypes.Add(aggregateType);
}
var subtypes = assembly.DefinedTypes.Where(m => m.IsAggregatePayloadType() && m.IsAggregateSubtypePayload());
var subtypes
= assembly.DefinedTypes.Where(m => m.IsAggregatePayloadType() && m.IsAggregateSubtypePayload());
foreach (var type in subtypes)
{
var aggregateSubType = new AggregateSubType(type);
Expand All @@ -45,7 +46,9 @@ public SekibanAggregateTypes(params Assembly[] assemblies)
var customProjectors = assembly.DefinedTypes.GetSingleProjectorTypes();
foreach (var type in customProjectors)
{
var projectorType = new SingleProjectionAggregateType(type.GetAggregatePayloadTypeFromSingleProjectionPayload(), type);
var projectorType = new SingleProjectionAggregateType(
type.GetAggregatePayloadTypeFromSingleProjectionPayload(),
type);
if (_registeredCustomProjectorTypes.Contains(projectorType))
{
continue;
Expand Down
32 changes: 18 additions & 14 deletions src/Sekiban.Core/Cache/IMultiProjectionCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public interface IMultiProjectionCache
/// <typeparam name="TProjectionPayload"></typeparam>
public void Set<TProjection, TProjectionPayload>(
string rootPartitionKey,
MultipleMemoryProjectionContainer<TProjection, TProjectionPayload> container) where TProjection : IMultiProjector<TProjectionPayload>, new()
MultipleMemoryProjectionContainer<TProjection, TProjectionPayload> container)
where TProjection : IMultiProjector<TProjectionPayload>, new()
where TProjectionPayload : IMultiProjectionPayloadCommon;

/// <summary>
Expand All @@ -30,8 +31,10 @@ public void Set<TProjection, TProjectionPayload>(
/// <typeparam name="TProjection"></typeparam>
/// <typeparam name="TProjectionPayload"></typeparam>
/// <returns></returns>
public MultipleMemoryProjectionContainer<TProjection, TProjectionPayload>? Get<TProjection, TProjectionPayload>(string rootPartitionKey)
where TProjection : IMultiProjector<TProjectionPayload>, new() where TProjectionPayload : IMultiProjectionPayloadCommon;
public MultipleMemoryProjectionContainer<TProjection, TProjectionPayload>?
Get<TProjection, TProjectionPayload>(string rootPartitionKey)
where TProjection : IMultiProjector<TProjectionPayload>, new()
where TProjectionPayload : IMultiProjectionPayloadCommon;

/// <summary>
/// Get aggregate list from cache
Expand All @@ -41,24 +44,25 @@ public void Set<TProjection, TProjectionPayload>(
/// <returns></returns>
public MultipleMemoryProjectionContainer<SingleProjectionListProjector<Aggregate<TAggregatePayload>,
AggregateState<TAggregatePayload>, DefaultSingleProjector<TAggregatePayload>>,
SingleProjectionListState<AggregateState<TAggregatePayload>>>?
GetAggregateList<TAggregatePayload>(string rootPartitionKey) where TAggregatePayload : IAggregatePayloadCommon =>
Get<SingleProjectionListProjector<Aggregate<TAggregatePayload>, AggregateState<TAggregatePayload>, DefaultSingleProjector<TAggregatePayload>>,
SingleProjectionListState<AggregateState<TAggregatePayload>>>(rootPartitionKey);
SingleProjectionListState<AggregateState<TAggregatePayload>>>? GetAggregateList<TAggregatePayload>(
string rootPartitionKey) where TAggregatePayload : IAggregatePayloadCommon =>
Get<SingleProjectionListProjector<Aggregate<TAggregatePayload>, AggregateState<TAggregatePayload>,
DefaultSingleProjector<TAggregatePayload>>, SingleProjectionListState<AggregateState<TAggregatePayload>>>(
rootPartitionKey);

/// <summary>
/// Get single projection list from cache
/// </summary>
/// <param name="rootPartitionKey"></param>
/// <typeparam name="TSingleProjectionPayload"></typeparam>
/// <returns></returns>
public
MultipleMemoryProjectionContainer<
SingleProjectionListProjector<SingleProjection<TSingleProjectionPayload>, SingleProjectionState<TSingleProjectionPayload>,
SingleProjection<TSingleProjectionPayload>>, SingleProjectionListState<SingleProjectionState<TSingleProjectionPayload>>>?
public MultipleMemoryProjectionContainer<
SingleProjectionListProjector<SingleProjection<TSingleProjectionPayload>,
SingleProjectionState<TSingleProjectionPayload>, SingleProjection<TSingleProjectionPayload>>,
SingleProjectionListState<SingleProjectionState<TSingleProjectionPayload>>>?
GetSingleProjectionList<TSingleProjectionPayload>(string rootPartitionKey)
where TSingleProjectionPayload : class, ISingleProjectionPayloadCommon =>
Get<SingleProjectionListProjector<SingleProjection<TSingleProjectionPayload>, SingleProjectionState<TSingleProjectionPayload>,
SingleProjection<TSingleProjectionPayload>>, SingleProjectionListState<SingleProjectionState<TSingleProjectionPayload>>>(
rootPartitionKey);
Get<SingleProjectionListProjector<SingleProjection<TSingleProjectionPayload>,
SingleProjectionState<TSingleProjectionPayload>, SingleProjection<TSingleProjectionPayload>>,
SingleProjectionListState<SingleProjectionState<TSingleProjectionPayload>>>(rootPartitionKey);
}
4 changes: 3 additions & 1 deletion src/Sekiban.Core/Cache/ISingleProjectionCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public interface ISingleProjectionCache
/// <param name="container"></param>
/// <typeparam name="TAggregate"></typeparam>
/// <typeparam name="TState"></typeparam>
public void SetContainer<TAggregate, TState>(Guid aggregateId, SingleMemoryCacheProjectionContainer<TAggregate, TState> container)
public void SetContainer<TAggregate, TState>(
Guid aggregateId,
SingleMemoryCacheProjectionContainer<TAggregate, TState> container)
where TAggregate : IAggregateCommon, ISingleProjection where TState : IAggregateStateCommon;

/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion src/Sekiban.Core/Cache/ISnapshotDocumentCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ public interface ISnapshotDocumentCache
/// <param name="projectionPayloadType"></param>
/// <param name="rootPartitionKey"></param>
/// <returns></returns>
public SnapshotDocument? Get(Guid aggregateId, Type aggregatePayloadType, Type projectionPayloadType, string rootPartitionKey);
public SnapshotDocument? Get(
Guid aggregateId,
Type aggregatePayloadType,
Type projectionPayloadType,
string rootPartitionKey);
}
2 changes: 1 addition & 1 deletion src/Sekiban.Core/Cache/MemoryCacheSettingsSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ namespace Sekiban.Core.Cache;

public record MemoryCacheSettingsSection(int AbsoluteExpirationMinutes = 120, int SlidingExpirationMinutes = 15)
{
}
}
Loading

0 comments on commit 8f4139c

Please sign in to comment.