-
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.
Catalog - Offers initial (2024-06-21) (#45)
* new terms in the dict! 📖 * scaffold of initial Offer modeling * chore; namespacing for catalog API endpoints * offers cmd and qry endpoints, namespace fixing, http file * moved existing catalog projections to namespace schema * feat; offer projection
- Loading branch information
1 parent
717c943
commit 402f4f5
Showing
28 changed files
with
423 additions
and
57 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,46 @@ | ||
# curl -X 'GET' | ||
# 'http://localhost:5252/offers/0190421a-1466-4f1b-8261-a22a528aadae' | ||
# -H 'accept: text/plain' | ||
GET http://localhost:5252/offers/0190421a-1466-4f1b-8261-a22a528aadae | ||
accept: text/plain | ||
|
||
### | ||
|
||
# curl -X 'POST' | ||
# 'http://localhost:5252/offer/draft' | ||
# -H 'accept: text/plain' | ||
# -H 'Content-Type: application/json' | ||
# -d '{ | ||
# "sku": "36606-001", | ||
# "createdBy": "erik" | ||
#}' | ||
POST http://localhost:5252/offer/draft | ||
accept: text/plain | ||
Content-Type: application/json | ||
|
||
{ | ||
"sku": "36606-001", | ||
"createdBy": "erik" | ||
} | ||
|
||
### | ||
|
||
# curl -X 'POST' | ||
# 'http://localhost:5252/offer/activate' | ||
# -H 'accept: text/plain' | ||
# -H 'Content-Type: application/json' | ||
# -d '{ | ||
# "offerId": "0190421a-1466-4f1b-8261-a22a528aada", | ||
# "activatedBy": "erik" | ||
#}' | ||
POST http://localhost:5252/offer/activate | ||
accept: text/plain | ||
Content-Type: application/json | ||
|
||
{ | ||
"offerId": "0190421a-1466-4f1b-8261-a22a528aadae", | ||
"activatedBy": "erik" | ||
} | ||
|
||
### | ||
|
33 changes: 33 additions & 0 deletions
33
src/Catalog/Catalog.Api/Commands/Offers/OfferCommandService.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,33 @@ | ||
using Catalog.Offers; | ||
using Ecommerce.Core.Identities; | ||
using Eventuous; | ||
using MongoDB.Bson.Serialization; | ||
|
||
namespace Catalog.Api.Commands.Offers; | ||
|
||
public class OfferCommandService : CommandService<Offer, OfferState, OfferId> | ||
{ | ||
[Obsolete("Obsolete usage of OnNewAsync per Eventuous; use new API instead (TODO)")] | ||
public OfferCommandService( | ||
IAggregateStore store, | ||
Services.IsSkuAvailable isSkuAvailable, | ||
Services.IsUserAuthorized isUserAuthorized, | ||
ICombIdGenerator idGenerator) | ||
: base(store) | ||
{ | ||
var generatedId = idGenerator.New(); | ||
OnNewAsync<OfferCommands.Draft>(cmd => new OfferId(generatedId), | ||
((offer, cmd, _) => offer.Draft( | ||
generatedId, | ||
cmd.Sku, | ||
DateTimeOffset.Now, | ||
cmd.CreatedBy, | ||
isSkuAvailable, | ||
isUserAuthorized))); | ||
|
||
OnExisting<OfferCommands.Activate>(cmd => new OfferId(cmd.OfferId), | ||
((offer, cmd) => offer.Activate( | ||
DateTimeOffset.Now, | ||
cmd.ActivatedBy))); | ||
} | ||
} |
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,14 @@ | ||
namespace Catalog.Api.Commands.Offers; | ||
|
||
public class OfferCommands | ||
{ | ||
public record Draft( | ||
string Sku, | ||
string CreatedBy | ||
); | ||
|
||
public record Activate( | ||
string OfferId, | ||
string ActivatedBy | ||
); | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...log/Catalog.Api/Commands/PriceCommands.cs → ...alog.Api/Commands/Prices/PriceCommands.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 Catalog.Api.Commands; | ||
namespace Catalog.Api.Commands.Prices; | ||
|
||
public static class PriceCommands | ||
{ | ||
|
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
2 changes: 1 addition & 1 deletion
2
...g/Catalog.Api/Commands/ProductCommands.cs → ....Api/Commands/Products/ProductCommands.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 Catalog.Api.Commands; | ||
namespace Catalog.Api.Commands.Products; | ||
|
||
public static class ProductCommands | ||
{ | ||
|
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.Api.Commands.Offers; | ||
using Catalog.Offers; | ||
using Eventuous; | ||
using Eventuous.AspNetCore.Web; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Catalog.Api.HttpApi.Offers; | ||
|
||
[Route("/offer")] | ||
public class OfferCommandApi(ICommandService<Offer> service) : CommandHttpApiBase<Offer>(service) | ||
{ | ||
[HttpPost] | ||
[Route("draft")] | ||
public Task<ActionResult<Result>> Draft([FromBody] OfferCommands.Draft cmd, CancellationToken ct) | ||
=> Handle(cmd, ct); | ||
|
||
[HttpPost] | ||
[Route("activate")] | ||
public Task<ActionResult<Result>> Activate([FromBody] OfferCommands.Activate 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.Offers; | ||
using Eventuous; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Catalog.Api.HttpApi.Offers; | ||
|
||
[Route("/offers")] | ||
public class OfferQueryApi : ControllerBase | ||
{ | ||
private readonly IAggregateStore _store; | ||
|
||
public OfferQueryApi(IAggregateStore store) => _store = store; | ||
|
||
[HttpGet] | ||
[Route("{id}")] | ||
public async Task<OfferState> GetProduct(string id, CancellationToken ct) | ||
{ | ||
var product = await _store.Load<Offer>(StreamName.For<Offer>(id), ct); | ||
return product.State; | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
...og/Catalog.Api/HttpApi/PriceCommandApi.cs → ...log.Api/HttpApi/Prices/PriceCommandApi.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,26 +1,26 @@ | ||
using Catalog.Api.Commands.Prices; | ||
using Catalog.Prices; | ||
using Eventuous; | ||
using Eventuous.AspNetCore.Web; | ||
using Microsoft.AspNetCore.Mvc; | ||
using static Catalog.Api.Commands.PriceCommands; | ||
|
||
namespace Catalog.Api.HttpApi; | ||
namespace Catalog.Api.HttpApi.Prices; | ||
|
||
[Route("/price")] | ||
public class PriceCommandApi(ICommandService<Price> service) : CommandHttpApiBase<Price>(service) | ||
{ | ||
[HttpPost] | ||
[Route("initialize")] | ||
public Task<ActionResult<Result>> Draft([FromBody] Initialize cmd, CancellationToken ct) | ||
public Task<ActionResult<Result>> Draft([FromBody] PriceCommands.Initialize cmd, CancellationToken ct) | ||
=> Handle(cmd, ct); | ||
|
||
[HttpPost] | ||
[Route("activate")] | ||
public Task<ActionResult<Result>> Activate([FromBody] Activate cmd, CancellationToken ct) | ||
public Task<ActionResult<Result>> Activate([FromBody] PriceCommands.Activate cmd, CancellationToken ct) | ||
=> Handle(cmd, ct); | ||
|
||
[HttpPost] | ||
[Route("deprecate")] | ||
public Task<ActionResult<Result>> Deprecate([FromBody] Deprecate cmd, CancellationToken ct) | ||
public Task<ActionResult<Result>> Deprecate([FromBody] PriceCommands.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
24 changes: 12 additions & 12 deletions
24
.../Catalog.Api/HttpApi/ProductCommandApi.cs → ...Api/HttpApi/Products/ProductCommandApi.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,61 +1,61 @@ | ||
using Catalog.Api.Commands.Products; | ||
using Catalog.Products; | ||
using Eventuous; | ||
using Eventuous.AspNetCore.Web; | ||
using Microsoft.AspNetCore.Mvc; | ||
using static Catalog.Api.Commands.ProductCommands; | ||
|
||
namespace Catalog.Api.HttpApi; | ||
namespace Catalog.Api.HttpApi.Products; | ||
|
||
[Route("/product")] | ||
public class ProductCommandApi(ICommandService<Product> service) : CommandHttpApiBase<Product>(service) | ||
{ | ||
[HttpPost] | ||
[Route("draft-with-id")] | ||
public Task<ActionResult<Result>> Draft([FromBody] DraftWithProvidedId cmd, CancellationToken ct) | ||
public Task<ActionResult<Result>> Draft([FromBody] ProductCommands.DraftWithProvidedId cmd, CancellationToken ct) | ||
=> Handle(cmd, ct); | ||
|
||
[HttpPost] | ||
[Route("draft")] | ||
public Task<ActionResult<Result>> Draft([FromBody] Draft cmd, CancellationToken ct) | ||
public Task<ActionResult<Result>> Draft([FromBody] ProductCommands.Draft cmd, CancellationToken ct) | ||
=> Handle(cmd, ct); | ||
|
||
[HttpPost] | ||
[Route("activate")] | ||
public Task<ActionResult<Result>> Activate([FromBody] Activate cmd, CancellationToken ct) | ||
public Task<ActionResult<Result>> Activate([FromBody] ProductCommands.Activate cmd, CancellationToken ct) | ||
=> Handle(cmd, ct); | ||
|
||
[HttpPost] | ||
[Route("archive")] | ||
public Task<ActionResult<Result>> Archive([FromBody] Archive cmd, CancellationToken ct) | ||
public Task<ActionResult<Result>> Archive([FromBody] ProductCommands.Archive cmd, CancellationToken ct) | ||
=> Handle(cmd, ct); | ||
|
||
[HttpPost] | ||
[Route("cancel")] | ||
public Task<ActionResult<Result>> Cancel([FromBody] Cancel cmd, CancellationToken ct) | ||
public Task<ActionResult<Result>> Cancel([FromBody] ProductCommands.Cancel cmd, CancellationToken ct) | ||
=> Handle(cmd, ct); | ||
|
||
[HttpPost] | ||
[Route("adjust-description")] | ||
public Task<ActionResult<Result>> AdjustDescription([FromBody] AdjustDescription cmd, CancellationToken ct) | ||
public Task<ActionResult<Result>> AdjustDescription([FromBody] ProductCommands.AdjustDescription cmd, CancellationToken ct) | ||
=> Handle(cmd, ct); | ||
|
||
[HttpPost] | ||
[Route("adjust-name")] | ||
public Task<ActionResult<Result>> AdjustName([FromBody] AdjustName cmd, CancellationToken ct) | ||
public Task<ActionResult<Result>> AdjustName([FromBody] ProductCommands.AdjustName cmd, CancellationToken ct) | ||
=> Handle(cmd, ct); | ||
|
||
[HttpPost] | ||
[Route("adjust-brand")] | ||
public Task<ActionResult<Result>> AdjustBrand([FromBody] AdjustBrand cmd, CancellationToken ct) | ||
public Task<ActionResult<Result>> AdjustBrand([FromBody] ProductCommands.AdjustBrand cmd, CancellationToken ct) | ||
=> Handle(cmd, ct); | ||
|
||
[HttpPost] | ||
[Route("take-measurement")] | ||
public Task<ActionResult<Result>> TakeMeasurement([FromBody] TakeMeasurement cmd, CancellationToken ct) | ||
public Task<ActionResult<Result>> TakeMeasurement([FromBody] ProductCommands.TakeMeasurement cmd, CancellationToken ct) | ||
=> Handle(cmd, ct); | ||
|
||
[HttpPost] | ||
[Route("remove-measurement")] | ||
public Task<ActionResult<Result>> RemoveMeasurement([FromBody] RemoveMeasurement cmd, CancellationToken ct) | ||
public Task<ActionResult<Result>> RemoveMeasurement([FromBody] ProductCommands.RemoveMeasurement 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
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,15 @@ | ||
using Eventuous.Projections.MongoDB.Tools; | ||
|
||
namespace Catalog.Api.Queries.Offers; | ||
|
||
public record OfferDocument : ProjectedDocument | ||
{ | ||
public OfferDocument(string Id) : base(Id) | ||
{ | ||
} | ||
|
||
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.MinValue; | ||
public string CreatedBy { get; set; } = null!; | ||
public string Sku { get; set; } = null!; | ||
public string Status { get; set; } = null!; | ||
} |
Oops, something went wrong.