-
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.
Migrate and Extend Price Module (#41)
* removed pricing folder and related dotnet projects * re-introduced Products directory in Catalog module * Swagger schema changes, initial price use cases impl'd, HTTP file * initial barebones state projection of Price, added HTTP calls
- Loading branch information
1 parent
04fac49
commit 6e39adb
Showing
62 changed files
with
649 additions
and
599 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
@Catalog.Api_HostAddress = http://localhost:5252 | ||
|
||
### | ||
|
||
GET {{Catalog.Api_HostAddress}}/api/ | ||
Accept: application/json | ||
|
||
### | ||
|
||
# curl -X 'POST' | ||
# 'http://localhost:5252/price/initialize' | ||
# -H 'accept: text/plain' | ||
# -H 'Content-Type: application/json' | ||
# -d '{ | ||
# "sku": "36606-001", | ||
# "minimumAdvertisedPrice": 94.00, | ||
# "manufacturerSuggestedRetailPrice": 99.99, | ||
# "bundledQuantity": 0, | ||
# "bundledPrice": 0, | ||
# "currency": "USD", | ||
# "createdAt": "2024-06-19T13:25:47.714Z", | ||
# "createdBy": "Erik" | ||
#}' | ||
POST http://localhost:5252/price/initialize | ||
accept: text/plain | ||
Content-Type: application/json | ||
|
||
{ | ||
"sku": "36606-001", | ||
"minimumAdvertisedPrice": 94.00, | ||
"manufacturerSuggestedRetailPrice": 99.99, | ||
"bundledQuantity": 0, | ||
"bundledPrice": 0, | ||
"currency": "USD", | ||
"createdAt": "2024-06-19T13:25:47.714Z", | ||
"createdBy": "Erik" | ||
} | ||
|
||
### | ||
|
||
# curl -X 'POST' | ||
# 'http://localhost:5252/price/activate' | ||
# -H 'accept: text/plain' | ||
# -H 'Content-Type: application/json' | ||
# -d '{ | ||
# "priceId": "1252983042692087808", | ||
# "activatedBy": "Erik" | ||
#}' | ||
POST http://localhost:5252/price/activate | ||
accept: text/plain | ||
Content-Type: application/json | ||
|
||
{ | ||
"priceId": "1252983042692087808", | ||
"activatedBy": "Erik" | ||
} | ||
|
||
### | ||
|
||
# curl -X 'POST' | ||
# 'http://localhost:5252/price/deprecate' | ||
# -H 'accept: text/plain' | ||
# -H 'Content-Type: application/json' | ||
# -d '{ | ||
# "priceId": "1252983042692087808", | ||
# "deprecatedBy": "Erik", | ||
# "reason": "goof" | ||
#}' | ||
POST http://localhost:5252/price/deprecate | ||
accept: text/plain | ||
Content-Type: application/json | ||
|
||
{ | ||
"priceId": "1252983042692087808", | ||
"deprecatedBy": "Erik", | ||
"reason": "goof" | ||
} | ||
|
||
### | ||
|
4 changes: 2 additions & 2 deletions
4
src/Catalog/Catalog.Api/Catalog.Api.http → ...log/Catalog.Api/Catalog.Api.Products.http
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,43 @@ | ||
using Catalog.Prices; | ||
using Ecommerce.Core.Identities; | ||
using Eventuous; | ||
|
||
namespace Catalog.Api.Commands; | ||
|
||
public class PriceCommandService : CommandService<Price, PriceState, PriceId> | ||
{ | ||
[Obsolete("Obsolete usage of OnNewAsync per Eventuous; use new API instead (TODO)")] | ||
public PriceCommandService( | ||
IAggregateStore store, | ||
Services.IsSkuAvailable isSkuAvailable, | ||
Services.IsUserAuthorized isUserAuthorized, | ||
ISnowflakeIdGenerator idGenerator) | ||
: base(store) | ||
{ | ||
var generatedId = idGenerator.New(); | ||
OnNewAsync<PriceCommands.Initialize>(cmd => new PriceId(generatedId), | ||
((price, cmd, _) => price.Draft( | ||
generatedId, | ||
cmd.Sku, | ||
cmd.MinimumAdvertisedPrice, | ||
cmd.ManufacturerSuggestedRetailPrice, | ||
cmd.BundledQuantity, | ||
cmd.BundledPrice, | ||
cmd.Currency, | ||
DateTimeOffset.Now, | ||
cmd.CreatedBy, | ||
isSkuAvailable, | ||
isUserAuthorized))); | ||
|
||
OnExisting<PriceCommands.Activate>(cmd => new PriceId(cmd.PriceId), | ||
((price, cmd) => price.Activate( | ||
DateTimeOffset.Now, | ||
cmd.ActivatedBy))); | ||
|
||
OnExisting<PriceCommands.Deprecate>(cmd => new PriceId(cmd.PriceId), | ||
((price, cmd) => price.Deprecate( | ||
DateTimeOffset.Now, | ||
cmd.DeprecatedBy, | ||
cmd.Reason))); | ||
} | ||
} |
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,26 @@ | ||
namespace Catalog.Api.Commands; | ||
|
||
public static class PriceCommands | ||
{ | ||
public record Initialize( | ||
string Sku, | ||
decimal MinimumAdvertisedPrice, | ||
decimal ManufacturerSuggestedRetailPrice, | ||
int BundledQuantity, | ||
decimal BundledPrice, | ||
string Currency, | ||
DateTimeOffset CreatedAt, | ||
string CreatedBy | ||
); | ||
|
||
public record Activate( | ||
string PriceId, | ||
string ActivatedBy | ||
); | ||
|
||
public record Deprecate( | ||
string PriceId, | ||
string DeprecatedBy, | ||
string Reason | ||
); | ||
} |
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,26 @@ | ||
using Catalog.Prices; | ||
using Eventuous; | ||
using Eventuous.AspNetCore.Web; | ||
using Microsoft.AspNetCore.Mvc; | ||
using static Catalog.Api.Commands.PriceCommands; | ||
|
||
namespace Catalog.Api.HttpApi; | ||
|
||
[Route("/price")] | ||
public class PriceCommandApi(ICommandService<Price> service) : CommandHttpApiBase<Price>(service) | ||
{ | ||
[HttpPost] | ||
[Route("initialize")] | ||
public Task<ActionResult<Result>> Draft([FromBody] Initialize cmd, CancellationToken ct) | ||
=> Handle(cmd, ct); | ||
|
||
[HttpPost] | ||
[Route("activate")] | ||
public Task<ActionResult<Result>> Activate([FromBody] Activate cmd, CancellationToken ct) | ||
=> Handle(cmd, ct); | ||
|
||
[HttpPost] | ||
[Route("deprecate")] | ||
public Task<ActionResult<Result>> Deprecate([FromBody] Deprecate cmd, CancellationToken ct) | ||
=> Handle(cmd, ct); | ||
} |
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,21 @@ | ||
using Catalog.Prices; | ||
using Eventuous; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Catalog.Api.HttpApi; | ||
|
||
[Route("/prices")] | ||
public class PriceQueryApi : ControllerBase | ||
{ | ||
private readonly IAggregateStore _store; | ||
|
||
public PriceQueryApi(IAggregateStore store) => _store = store; | ||
|
||
[HttpGet] | ||
[Route("{id}")] | ||
public async Task<PriceState> GetPrice(string id, CancellationToken ct) | ||
{ | ||
var product = await _store.Load<Price>(StreamName.For<Price>(id), ct); | ||
return product.State; | ||
} | ||
} |
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
6 changes: 3 additions & 3 deletions
6
src/Catalog/Catalog.Api/HttpApi/QueryApi.cs → ...og/Catalog.Api/HttpApi/ProductQueryApi.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
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,18 @@ | ||
using Eventuous.Projections.MongoDB.Tools; | ||
|
||
namespace Catalog.Api.Queries; | ||
|
||
public record PriceDocument : ProjectedDocument | ||
{ | ||
public PriceDocument(string Id) : base(Id) | ||
{ | ||
} | ||
|
||
public string Sku { get; set; } = null!; | ||
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.MinValue; | ||
public string CreatedBy { get; set; } = null!; | ||
public string Status { get; set; } = null!; | ||
public decimal MinimumAdvertisedPrice { get; set; } | ||
public decimal ManufacturerSuggestedRetailPrice { get; set; } | ||
// TODO: Bundled Pricing | ||
} |
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,50 @@ | ||
using Catalog.Prices; | ||
using Eventuous.Projections.MongoDB; | ||
using Eventuous.Subscriptions.Context; | ||
using MongoDB.Driver; | ||
using static Catalog.Prices.PriceEvents; | ||
|
||
namespace Catalog.Api.Queries; | ||
|
||
[Obsolete("Obsolete per Eventuous; use new API instead (TODO)")] | ||
public class PriceStateProjection : MongoProjection<PriceDocument> | ||
{ | ||
public PriceStateProjection(IMongoDatabase database) : base(database) | ||
{ | ||
On<V1.PriceInitialized>(stream => stream.GetId(), Handle); | ||
} | ||
|
||
private static UpdateDefinition<PriceDocument> Handle( | ||
IMessageConsumeContext<V1.PriceInitialized> ctx, | ||
UpdateDefinitionBuilder<PriceDocument> update) | ||
{ | ||
var evt = ctx.Message; | ||
|
||
return update.SetOnInsert(x => x.Id, ctx.Stream.GetId()) | ||
.Set(x => x.Sku, evt.Sku) | ||
.Set(x => x.CreatedAt, evt.CreatedAt) | ||
.Set(x => x.CreatedBy, evt.CreatedBy) | ||
.Set(x => x.Status, nameof(PriceStatus.Initialized)) | ||
.Set(x => x.MinimumAdvertisedPrice, evt.MinimumAdvertisedPrice) | ||
.Set(x => x.ManufacturerSuggestedRetailPrice, evt.ManufacturerSuggestedRetailPrice); | ||
// TODO: bundled pricing, etc | ||
} | ||
|
||
private static UpdateDefinition<PriceDocument> Handle( | ||
IMessageConsumeContext<V1.PriceActivated> ctx, | ||
UpdateDefinition<PriceDocument> update) | ||
{ | ||
var @event = ctx.Message; | ||
|
||
return update.Set(x => x.Status, nameof(PriceStatus.Activated)); | ||
} | ||
|
||
private static UpdateDefinition<PriceDocument> Handle( | ||
IMessageConsumeContext<V1.PriceDeprecated> ctx, | ||
UpdateDefinition<PriceDocument> update) | ||
{ | ||
var @event = ctx.Message; | ||
|
||
return update.Set(x => x.Status, nameof(PriceStatus.Deprecated)); | ||
} | ||
} |
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
Oops, something went wrong.