-
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.
offers cmd and qry endpoints, namespace fixing, http file
- Loading branch information
1 parent
2bc6c84
commit aa3f7c0
Showing
12 changed files
with
158 additions
and
18 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
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; | ||
} | ||
} |
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