From be3f38e715cfecd06fc7d71f3e122a94a50e45fe Mon Sep 17 00:00:00 2001 From: Laurent Le Houerou Date: Tue, 16 Apr 2024 15:00:33 +0400 Subject: [PATCH] add buyShopItem mutation --- mutations/buy_shop_item.go | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 mutations/buy_shop_item.go diff --git a/mutations/buy_shop_item.go b/mutations/buy_shop_item.go new file mode 100644 index 0000000..cbdbe18 --- /dev/null +++ b/mutations/buy_shop_item.go @@ -0,0 +1,52 @@ +package mutations + +package mutations + +import ( + "context" + + gql "github.com/llehouerou/go-graphql-client" + "github.com/pkg/errors" + + "git.lehouerou.net/laurent/sorare/graphql" +) + +type buyShopItemInput struct { + ClientMutationId string `json:"clientMutationId"` + ShopItemId gql.ID `json:"shopItemId"` +} + +type BuyShopItemParams struct { + Input buyDeliverableShopItemInput `graphql:"input"` +} + +func (m *Mutations) newBuyShopItemMutation() *graphql.Mutation[BaseMutationPayload, BuyShopItemParams] { + return graphql.NewMutation[BaseMutationPayload, BuyShopItemParams]( + m.c, + "buyShopItem", + ) +} + +func (m *Mutations) BuyShopItem( + ctx context.Context, + shopItemId string, +) error { + res, err := m.newBuyShopItemMutation().Execute(ctx, BuyShopItemParams{ + Input: buyShopItemInput{ + ClientMutationId: GetRandomId(), + ShopItemId: gql.ID(shopItemId), + }, + }) + if err != nil { + return errors.Wrap(err, "executing buyShopItem mutation") + } + if res.Errors != nil { + return errors.Wrap( + errors.New(res.Errors[0].Message), + "executing buyShopItem mutation", + ) + } + + return nil + +}