all the refactor
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"git.k6n.net/mats/go-cart-actor/pkg/promotions"
|
||||
pmcp "git.k6n.net/mats/platform/mcp"
|
||||
)
|
||||
|
||||
// AdminTool is one admin promotion tool definition — name, description, input
|
||||
@@ -31,14 +32,14 @@ func AdminTools(store *promotions.Store, eval *promotions.PromotionService) []Ad
|
||||
"`promotion` is a full promotion-rule object (id, name, status, priority, conditions, actions). " +
|
||||
"For a tiered volume discount (Volymrabatt) use a cart_total condition plus a tiered_discount action " +
|
||||
"whose config.tiers each have minTotal/maxTotal (öre incl. VAT) and percent.",
|
||||
InputSchema: object(props{
|
||||
"promotion": obj("the full promotion rule object"),
|
||||
InputSchema: pmcp.Object(pmcp.Props{
|
||||
"promotion": pmcp.ObjectValue("the full promotion rule object"),
|
||||
}, []string{"promotion"}),
|
||||
Invoke: func(args json.RawMessage) (any, error) {
|
||||
var a struct {
|
||||
Promotion json.RawMessage `json:"promotion"`
|
||||
}
|
||||
if err := decode(args, &a); err != nil {
|
||||
if err := pmcp.Decode(args, &a); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var rule promotions.PromotionRule
|
||||
@@ -61,16 +62,16 @@ func AdminTools(store *promotions.Store, eval *promotions.PromotionService) []Ad
|
||||
{
|
||||
Name: "set_promotion_status",
|
||||
Description: "Set a promotion's status (active|inactive|scheduled|expired) to toggle it on or off.",
|
||||
InputSchema: object(props{
|
||||
"id": str("the promotion id"),
|
||||
"status": str("new status: active|inactive|scheduled|expired"),
|
||||
InputSchema: pmcp.Object(pmcp.Props{
|
||||
"id": pmcp.String("the promotion id"),
|
||||
"status": pmcp.String("new status: active|inactive|scheduled|expired"),
|
||||
}, []string{"id", "status"}),
|
||||
Invoke: func(args json.RawMessage) (any, error) {
|
||||
var a struct {
|
||||
ID string `json:"id"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
if err := decode(args, &a); err != nil {
|
||||
if err := pmcp.Decode(args, &a); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !validStatus(a.Status) {
|
||||
@@ -89,12 +90,12 @@ func AdminTools(store *promotions.Store, eval *promotions.PromotionService) []Ad
|
||||
{
|
||||
Name: "delete_promotion",
|
||||
Description: "Delete a promotion rule by id.",
|
||||
InputSchema: object(props{"id": str("the promotion id")}, []string{"id"}),
|
||||
InputSchema: pmcp.Object(pmcp.Props{"id": pmcp.String("the promotion id")}, []string{"id"}),
|
||||
Invoke: func(args json.RawMessage) (any, error) {
|
||||
var a struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
if err := decode(args, &a); err != nil {
|
||||
if err := pmcp.Decode(args, &a); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
found, err := store.Delete(a.ID)
|
||||
|
||||
Reference in New Issue
Block a user