-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Docker compose for event store
- Loading branch information
1 parent
58557b4
commit 5820fae
Showing
47 changed files
with
1,780 additions
and
1,733 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,81 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Runtime.InteropServices; | ||
using Godwit.Interfaces.Messages.Commands; | ||
using Godwit.Interfaces.Messages.Events; | ||
|
||
namespace Godwit.Grains.Domain { | ||
[Serializable] | ||
public class AccountState { | ||
private readonly IDictionary<Guid, Transaction> _transactions; | ||
|
||
public AccountState() { | ||
Status = AccountStatus.NotInitialized; | ||
Amount = 0; | ||
Version = 0; | ||
_transactions = new Dictionary<Guid, Transaction>(); | ||
} | ||
|
||
public int Version { get; private set; } | ||
public AccountStatus Status { get; private set; } | ||
public decimal Amount { get; private set; } | ||
public string CustomerNumber { get; private set; } | ||
public string BranchCode { get; private set; } | ||
public string CloseReason { get; private set; } | ||
public DateTimeOffset OpenTimeStamp { get; private set; } | ||
public DateTimeOffset? CloseTimeStamp { get; private set; } | ||
|
||
public Transaction this[Guid transactionId] => | ||
_transactions.ContainsKey(transactionId) ? _transactions[transactionId] : null; | ||
public IEnumerable<Transaction> Transactions => _transactions.Values; | ||
public void Apply(IEvent @event) { | ||
switch (@event) { | ||
case AccountOpenedEvent evt1: | ||
Apply(evt1); | ||
break; | ||
case AccountClosedEvent evt2: | ||
Apply(evt2); | ||
break; | ||
case AccountDepositedEvent evt3: | ||
Apply(evt3); | ||
break; | ||
case AccountWithDrawnEvent evt4: | ||
Apply(evt4); | ||
break; | ||
} | ||
} | ||
|
||
private void Apply(AccountOpenedEvent @event) { | ||
Status = AccountStatus.Open; | ||
Amount = @event.Amount; | ||
BranchCode = @event.BranchCode; | ||
CustomerNumber = @event.CustomerNumber; | ||
OpenTimeStamp = @event.TimeStamp; | ||
Version++; | ||
} | ||
|
||
private void Apply(AccountClosedEvent @event) { | ||
Status = AccountStatus.Closed; | ||
CloseReason = @event.Reason; | ||
CloseTimeStamp = @event.TimeStamp; | ||
Version++; | ||
} | ||
|
||
private void Apply(AccountDepositedEvent @event) { | ||
if (_transactions.ContainsKey(@event.TransactionId)) | ||
return; | ||
Amount += @event.Amount; | ||
_transactions.Add(@event.TransactionId, new Transaction(@event)); | ||
Version++; | ||
} | ||
|
||
private void Apply(AccountWithDrawnEvent @event) { | ||
if (_transactions.ContainsKey(@event.TransactionId)) | ||
return; | ||
Amount -= @event.Amount; | ||
_transactions.Add(@event.TransactionId, new Transaction(@event)); | ||
Version++; | ||
} | ||
} | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Runtime.InteropServices; | ||
using Godwit.Interfaces.Messages.Commands; | ||
using Godwit.Interfaces.Messages.Events; | ||
|
||
namespace Godwit.Grains.Domain { | ||
[Serializable] | ||
public class AccountState { | ||
private readonly IDictionary<Guid, Transaction> _transactions; | ||
|
||
public AccountState() { | ||
Status = AccountStatus.NotInitialized; | ||
Amount = 0; | ||
Version = 0; | ||
_transactions = new Dictionary<Guid, Transaction>(); | ||
} | ||
|
||
public int Version { get; private set; } | ||
public AccountStatus Status { get; private set; } | ||
public decimal Amount { get; private set; } | ||
public string CustomerNumber { get; private set; } | ||
public string BranchCode { get; private set; } | ||
public string CloseReason { get; private set; } | ||
public DateTimeOffset OpenTimeStamp { get; private set; } | ||
public DateTimeOffset? CloseTimeStamp { get; private set; } | ||
|
||
public Transaction this[Guid transactionId] => | ||
_transactions.ContainsKey(transactionId) ? _transactions[transactionId] : null; | ||
public IEnumerable<Transaction> Transactions => _transactions.Values; | ||
public void Apply(IEvent @event) { | ||
switch (@event) { | ||
case AccountOpenedEvent evt1: | ||
Apply(evt1); | ||
break; | ||
case AccountClosedEvent evt2: | ||
Apply(evt2); | ||
break; | ||
case AccountDepositedEvent evt3: | ||
Apply(evt3); | ||
break; | ||
case AccountWithDrawnEvent evt4: | ||
Apply(evt4); | ||
break; | ||
} | ||
} | ||
|
||
private void Apply(AccountOpenedEvent @event) { | ||
Status = AccountStatus.Open; | ||
Amount = @event.Amount; | ||
BranchCode = @event.BranchCode; | ||
CustomerNumber = @event.CustomerNumber; | ||
OpenTimeStamp = @event.TimeStamp; | ||
Version++; | ||
} | ||
|
||
private void Apply(AccountClosedEvent @event) { | ||
Status = AccountStatus.Closed; | ||
CloseReason = @event.Reason; | ||
CloseTimeStamp = @event.TimeStamp; | ||
Version++; | ||
} | ||
|
||
private void Apply(AccountDepositedEvent @event) { | ||
if (_transactions.ContainsKey(@event.TransactionId)) | ||
return; | ||
Amount += @event.Amount; | ||
_transactions.Add(@event.TransactionId, new Transaction(@event)); | ||
Version++; | ||
} | ||
|
||
private void Apply(AccountWithDrawnEvent @event) { | ||
if (_transactions.ContainsKey(@event.TransactionId)) | ||
return; | ||
Amount -= @event.Amount; | ||
_transactions.Add(@event.TransactionId, new Transaction(@event)); | ||
Version++; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
namespace Godwit.Grains.Domain { | ||
public enum AccountStatus { | ||
NotInitialized, | ||
Closed, | ||
Open | ||
} | ||
namespace Godwit.Grains.Domain { | ||
public enum AccountStatus { | ||
NotInitialized, | ||
Closed, | ||
Open | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
using System; | ||
using Godwit.Interfaces.Messages.Events; | ||
|
||
namespace Godwit.Grains.Domain { | ||
public class Transaction { | ||
public Transaction(AccountDepositedEvent @event) { | ||
Type = TransactionType.Credit; | ||
Amount = @event.Amount; | ||
TransactionId = @event.TransactionId; | ||
} | ||
|
||
public Transaction(AccountWithDrawnEvent @event) { | ||
Type = TransactionType.Debit; | ||
Amount = @event.Amount; | ||
TransactionId = @event.TransactionId; | ||
} | ||
|
||
public decimal Amount { get; } | ||
public TransactionType Type { get; } | ||
public Guid TransactionId { get; } | ||
} | ||
using System; | ||
using Godwit.Interfaces.Messages.Events; | ||
|
||
namespace Godwit.Grains.Domain { | ||
public class Transaction { | ||
public Transaction(AccountDepositedEvent @event) { | ||
Type = TransactionType.Credit; | ||
Amount = @event.Amount; | ||
TransactionId = @event.TransactionId; | ||
} | ||
|
||
public Transaction(AccountWithDrawnEvent @event) { | ||
Type = TransactionType.Debit; | ||
Amount = @event.Amount; | ||
TransactionId = @event.TransactionId; | ||
} | ||
|
||
public decimal Amount { get; } | ||
public TransactionType Type { get; } | ||
public Guid TransactionId { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
namespace Godwit.Grains.Domain { | ||
public enum TransactionType { | ||
Credit, | ||
Debit | ||
} | ||
namespace Godwit.Grains.Domain { | ||
public enum TransactionType { | ||
Credit, | ||
Debit | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="EventStore.Client.Grpc.Streams" Version="20.6.1" /> | ||
<PackageReference Include="protobuf-net" Version="3.0.52" /> | ||
<ProjectReference Include="..\Godwit.Interfaces\Godwit.Interfaces.csproj" /> | ||
<PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="3.3.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="3.3.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Orleans.EventSourcing" Version="3.3.0" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="EventStore.Client.Grpc.Streams" Version="20.6.1" /> | ||
<PackageReference Include="protobuf-net" Version="3.0.52" /> | ||
<ProjectReference Include="..\Godwit.Interfaces\Godwit.Interfaces.csproj" /> | ||
<PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="3.3.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="3.3.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Orleans.EventSourcing" Version="3.3.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
using System; | ||
using System.Runtime.Serialization; | ||
|
||
namespace Godwit.Interfaces { | ||
public class AccountTransactionException : ApplicationException { | ||
public AccountTransactionException() { | ||
} | ||
|
||
public AccountTransactionException(SerializationInfo info, StreamingContext context) : base(info, context) { | ||
} | ||
|
||
public AccountTransactionException(string message) : base(message) { | ||
} | ||
|
||
public AccountTransactionException(string message, Exception innerException) : base(message, innerException) { | ||
} | ||
} | ||
using System; | ||
using System.Runtime.Serialization; | ||
|
||
namespace Godwit.Interfaces { | ||
public class AccountTransactionException : ApplicationException { | ||
public AccountTransactionException() { | ||
} | ||
|
||
public AccountTransactionException(SerializationInfo info, StreamingContext context) : base(info, context) { | ||
} | ||
|
||
public AccountTransactionException(string message) : base(message) { | ||
} | ||
|
||
public AccountTransactionException(string message, Exception innerException) : base(message, innerException) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
namespace Godwit.Interfaces.Constants { | ||
public static class StreamName { | ||
public const string AccountStream = nameof(AccountStream); | ||
} | ||
namespace Godwit.Interfaces.Constants { | ||
public static class StreamName { | ||
public const string AccountStream = nameof(AccountStream); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
namespace Godwit.Interfaces.Constants { | ||
public static class StreamProviderName { | ||
public const string Default = nameof(Default); | ||
} | ||
namespace Godwit.Interfaces.Constants { | ||
public static class StreamProviderName { | ||
public const string Default = nameof(Default); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="3.3.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="3.3.0" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="3.3.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="3.3.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.