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 + +}