mcp in cart
This commit is contained in:
+20
-12
@@ -15,6 +15,7 @@ import (
|
||||
"git.k6n.net/mats/go-cart-actor/pkg/actor"
|
||||
"git.k6n.net/mats/go-cart-actor/pkg/cart"
|
||||
"git.k6n.net/mats/go-cart-actor/pkg/promotions"
|
||||
promotionmcp "git.k6n.net/mats/go-cart-actor/pkg/promotions/mcp"
|
||||
"git.k6n.net/mats/go-cart-actor/pkg/proxy"
|
||||
"git.k6n.net/mats/go-cart-actor/pkg/voucher"
|
||||
"git.k6n.net/mats/go-redis-inventory/pkg/inventory"
|
||||
@@ -111,16 +112,18 @@ func main() {
|
||||
|
||||
controlPlaneConfig := actor.DefaultServerConfig()
|
||||
|
||||
promotionData, err := promotions.LoadStateFile("data/promotions.json")
|
||||
promotionStore, err := promotions.NewStore("data/promotions.json")
|
||||
if err != nil {
|
||||
log.Printf("Error loading promotions: %v\n", err)
|
||||
log.Fatalf("Error loading promotions: %v\n", err)
|
||||
}
|
||||
|
||||
log.Printf("loaded %d promotions", len(promotionData.State.Promotions))
|
||||
log.Printf("loaded %d promotions", len(promotionStore.List()))
|
||||
|
||||
promotionService := promotions.NewPromotionService(nil)
|
||||
promotionMCP := promotionmcp.New(promotionStore, promotionService)
|
||||
|
||||
//inventoryPubSub := actor.NewPubSub[inventory.InventoryChange]()
|
||||
|
||||
// promotionService := promotions.NewPromotionService(nil)
|
||||
// rdb := redis.NewClient(&redis.Options{
|
||||
// Addr: redisAddress,
|
||||
// Password: redisPassword,
|
||||
@@ -142,15 +145,13 @@ func main() {
|
||||
_, span := tracer.Start(ctx, "Totals and promotions")
|
||||
defer span.End()
|
||||
g.UpdateTotals()
|
||||
// Evaluate active promotions against the freshly-totalled cart and apply
|
||||
// any matched actions (e.g. the Volymrabatt volume discount), which adjust
|
||||
// TotalPrice/TotalDiscount on top of line items and vouchers.
|
||||
promotionCtx := promotions.NewContextFromCart(g, promotions.WithNow(time.Now()))
|
||||
_, actions := promotionService.EvaluateAll(promotionStore.Snapshot(), promotionCtx)
|
||||
promotions.ApplyActions(g, actions)
|
||||
g.Version++
|
||||
// promotionCtx := promotions.NewContextFromCart(g, promotions.WithNow(time.Now()), promotions.WithCustomerSegment("vip"))
|
||||
// _, actions := promotionService.EvaluateAll(promotionData.State.Promotions, promotionCtx)
|
||||
// for _, action := range actions {
|
||||
|
||||
// log.Printf("apply: %+v", action)
|
||||
|
||||
// g.UpdateTotals()
|
||||
// }
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
@@ -267,6 +268,13 @@ func main() {
|
||||
}
|
||||
|
||||
syncedServer.Serve(mux)
|
||||
|
||||
// Promotion MCP edge: list/get/upsert/status/delete promotions and preview
|
||||
// discounts. Mutations persist to data/promotions.json and are picked up by
|
||||
// the cart's totals processor on the next mutation (it reads a fresh snapshot).
|
||||
mux.Handle("/mcp", promotionMCP.Handler())
|
||||
mux.Handle("/mcp/", promotionMCP.Handler())
|
||||
|
||||
// only for local
|
||||
mux.HandleFunc("GET /add/remote/{host}", func(w http.ResponseWriter, r *http.Request) {
|
||||
pool.AddRemote(r.PathValue("host"))
|
||||
|
||||
Reference in New Issue
Block a user