-
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.
initial cart projection, cleaned up confirm process, cart services
- Loading branch information
1 parent
918ce26
commit 8d73b66
Showing
22 changed files
with
195 additions
and
32 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using MongoDb.Bson.NodaTime; | ||
using MongoDB.Driver; | ||
using MongoDB.Driver.Core.Extensions.DiagnosticSources; | ||
|
||
namespace ShoppingCart.Api.Infrastructure; | ||
|
||
public static class Mongo | ||
{ | ||
public static IMongoDatabase ConfigureMongo(IConfiguration configuration) | ||
{ | ||
NodaTimeSerializers.Register(); | ||
var config = configuration.GetSection("Mongo").Get<MongoSettings>(); | ||
|
||
var settings = MongoClientSettings.FromConnectionString(config!.ConnectionString); | ||
|
||
if (config.User != null && config.Password != null) { | ||
settings.Credential = new MongoCredential( | ||
null, | ||
new MongoInternalIdentity("admin", config.User), | ||
new PasswordEvidence(config.Password) | ||
); | ||
} | ||
|
||
settings.ClusterConfigurator = cb => cb.Subscribe(new DiagnosticsActivityEventSubscriber()); | ||
return new MongoClient(settings).GetDatabase(config.Database); | ||
} | ||
|
||
public record MongoSettings | ||
{ | ||
public string ConnectionString { get; init; } = null!; | ||
public string Database { get; init; } = null!; | ||
public string? User { get; init; } | ||
public string? Password { get; init; } | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Retail/ShoppingCart.Api/Queries/Carts/UserCartDocument.cs
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Eventuous.Projections.MongoDB.Tools; | ||
|
||
namespace ShoppingCart.Api.Queries.Carts; | ||
|
||
public record UserCartDocument : ProjectedDocument | ||
{ | ||
public UserCartDocument(string Id) : base(Id) | ||
{ | ||
} | ||
|
||
public string CustomerId { get; set; } = null!; | ||
public string Status { get; set; } = null!; | ||
} |
38 changes: 38 additions & 0 deletions
38
src/Retail/ShoppingCart.Api/Queries/Carts/UserCartProjection.cs
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Eventuous.Projections.MongoDB; | ||
using Eventuous.Subscriptions.Context; | ||
using MongoDB.Driver; | ||
using ShoppingCart.Carts; | ||
|
||
namespace ShoppingCart.Api.Queries.Carts; | ||
|
||
[Obsolete("Obsolete per Eventuous; use new API instead (TODO)")] | ||
public class UserCartProjection : MongoProjection<UserCartDocument> | ||
{ | ||
public UserCartProjection(IMongoDatabase database) : base(database) | ||
{ | ||
On<CartEvents.V1.CartOpened>(stream => stream.GetId(), Handle); | ||
|
||
On<CartEvents.V1.CartConfirmed>(builder => builder | ||
.UpdateOne | ||
.DefaultId() | ||
.Update((evt, update) => | ||
update.Set(x => x.Status, nameof(CartStatus.Confirmed)))); | ||
|
||
On<CartEvents.V1.CartCancelled>(builder => builder | ||
.UpdateOne | ||
.DefaultId() | ||
.Update((evt, update) => | ||
update.Set(x => x.Status, nameof(CartStatus.Cancelled)))); | ||
} | ||
|
||
private static UpdateDefinition<UserCartDocument> Handle( | ||
IMessageConsumeContext<CartEvents.V1.CartOpened> ctx, | ||
UpdateDefinitionBuilder<UserCartDocument> update) | ||
{ | ||
var evt = ctx.Message; | ||
|
||
return update.SetOnInsert(x => x.Id, ctx.Stream.GetId()) | ||
.Set(x => x.CustomerId, evt.CustomerId) | ||
.Set(x => x.Status, nameof(CartStatus.Opened)); | ||
} | ||
} |
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
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -4,5 +4,6 @@ public enum CartStatus | |
{ | ||
Unset = 0, | ||
Opened = 1, | ||
Confirmed = 2 | ||
Confirmed = 2, | ||
Cancelled = 4 | ||
} |
4 changes: 2 additions & 2 deletions
4
...art/Inventories/ICheckInventoryService.cs → ...pingCart/Inventories/IInventoryChecker.cs
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,8 +1,8 @@ | ||
using ShoppingCart.Carts; | ||
using ShoppingCart.Products; | ||
|
||
namespace ShoppingCart.Inventories; | ||
|
||
public interface ICheckInventoryService | ||
public interface IInventoryChecker | ||
{ | ||
IReadOnlyList<ProductItem> Check(params ProductId[] productIds); | ||
} |
4 changes: 2 additions & 2 deletions
4
...Cart/Inventories/CheckInventoryService.cs → ...ppingCart/Inventories/InventoryChecker.cs
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
4 changes: 2 additions & 2 deletions
4
...ShoppingCart/Prices/IQuotePriceService.cs → ...etail/ShoppingCart/Prices/IPriceQuoter.cs
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,8 +1,8 @@ | ||
using ShoppingCart.Carts; | ||
using ShoppingCart.Products; | ||
|
||
namespace ShoppingCart.Prices; | ||
|
||
public interface IQuotePriceService | ||
public interface IPriceQuoter | ||
{ | ||
IReadOnlyList<PricedProductItem> Quote(params ProductItem[] productItems); | ||
} |
4 changes: 2 additions & 2 deletions
4
.../ShoppingCart/Prices/QuotePriceService.cs → ...Retail/ShoppingCart/Prices/PriceQuoter.cs
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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace ShoppingCart.Products; | ||
|
||
public interface IProductValidator | ||
{ | ||
IReadOnlyList<(ProductId productId, bool isValid)> Quote(params ProductId[] productIds); | ||
} |
2 changes: 1 addition & 1 deletion
2
...l/ShoppingCart/Carts/PricedProductItem.cs → ...hoppingCart/Products/PricedProductItem.cs
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,4 +1,4 @@ | ||
namespace ShoppingCart.Carts; | ||
namespace ShoppingCart.Products; | ||
|
||
public class PricedProductItem | ||
{ | ||
|
2 changes: 1 addition & 1 deletion
2
src/Retail/ShoppingCart/Carts/ProductId.cs → ...Retail/ShoppingCart/Products/ProductId.cs
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 @@ | ||
using Eventuous; | ||
|
||
namespace ShoppingCart.Carts; | ||
namespace ShoppingCart.Products; | ||
|
||
public record ProductId(string Value) : Id(Value); |
2 changes: 1 addition & 1 deletion
2
src/Retail/ShoppingCart/Carts/ProductItem.cs → ...tail/ShoppingCart/Products/ProductItem.cs
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,4 +1,4 @@ | ||
namespace ShoppingCart.Carts; | ||
namespace ShoppingCart.Products; | ||
|
||
public record ProductItem | ||
{ | ||
|
Oops, something went wrong.