Update API

* mutations now return { result, invoice, paymentMethod } due to new backend payment optimism
This commit is contained in:
ekzyis 2024-07-02 22:28:07 +02:00
parent f4c1b57c1f
commit c6f926dd8c
2 changed files with 39 additions and 22 deletions

View File

@ -7,21 +7,32 @@ import (
) )
type Invoice struct { type Invoice struct {
Id int `json:"id,string"` Id int `json:"id,string"`
Hash string `json:"hash"` Hash string `json:"hash"`
Hmac string `json:"hmac"` Hmac string `json:"hmac"`
Bolt11 string `json:"bolt11"` Bolt11 string `json:"bolt11"`
CreatedAt time.Time `json:"createdAt"` SatsRequested int `json:"satsRequested"`
ExpiresAt time.Time `json:"expiresAt"` SatsReceived int `json:"satsReceived"`
Cancelled bool `json:"cancelled"` Cancelled bool `json:"cancelled"`
ConfirmedAt time.Time `json:"confirmedAt"` ConfirmedAt time.Time `json:"createdAt"`
SatsReceived int `json:"satsReceived"` ExpiresAt time.Time `json:"expiresAt"`
SatsRequested int `json:"satsRequested"` Nostr map[string]interface{} `json:"nostr"`
Comment string `json:"nostr"` IsHeld bool `json:"isHeld"`
IsHeld int `json:"isHeld"` Comment string `json:"comment"`
ConfirmedPreimage string `json:"confirmedPreimage"` Lud18Data map[string]interface{} `json:"lud18Data"`
ConfirmedPreimage string `json:"confirmedPreimage"`
ActionState string `json:"actionState"`
ActionType string `json:"actionType"`
} }
type PaymentMethod string
const (
PaymentMethodFeeCredits PaymentMethod = "FEE_CREDIT"
PaymentMethodOptimistic PaymentMethod = "OPTIMISTIC"
PaymentMethodPessimistic PaymentMethod = "PESSIMISTIC"
)
type CreateInvoiceArgs struct { type CreateInvoiceArgs struct {
Amount int Amount int
ExpireSecs int ExpireSecs int

View File

@ -57,24 +57,30 @@ type ItemsResponse struct {
} `json:"data"` } `json:"data"`
} }
type ItemPaidAction struct {
Result Item `json:"result"`
Invoice Invoice `json:"invoice"`
PaymentMethod PaymentMethod `json:"paymentMethod"`
}
type UpsertDiscussionResponse struct { type UpsertDiscussionResponse struct {
Errors []GqlError `json:"errors"` Errors []GqlError `json:"errors"`
Data struct { Data struct {
UpsertDiscussion Item `json:"upsertDiscussion"` UpsertDiscussion ItemPaidAction `json:"upsertDiscussion"`
} `json:"data"` } `json:"data"`
} }
type UpsertLinkResponse struct { type UpsertLinkResponse struct {
Errors []GqlError `json:"errors"` Errors []GqlError `json:"errors"`
Data struct { Data struct {
UpsertLink Item `json:"upsertLink"` UpsertLink ItemPaidAction `json:"upsertLink"`
} `json:"data"` } `json:"data"`
} }
type CreateCommentsResponse struct { type CreateCommentsResponse struct {
Errors []GqlError `json:"errors"` Errors []GqlError `json:"errors"`
Data struct { Data struct {
CreateComment Comment `json:"createComment"` CreateComment ItemPaidAction `json:"createComment"`
} `json:"data"` } `json:"data"`
} }
@ -266,7 +272,7 @@ func (c *Client) PostDiscussion(title string, text string, sub string) (int, err
Query: ` Query: `
mutation upsertDiscussion($title: String!, $text: String, $sub: String) { mutation upsertDiscussion($title: String!, $text: String, $sub: String) {
upsertDiscussion(title: $title, text: $text, sub: $sub) { upsertDiscussion(title: $title, text: $text, sub: $sub) {
id result { id }
} }
}`, }`,
Variables: map[string]interface{}{ Variables: map[string]interface{}{
@ -294,7 +300,7 @@ func (c *Client) PostDiscussion(title string, text string, sub string) (int, err
return -1, err return -1, err
} }
return respBody.Data.UpsertDiscussion.Id, nil return respBody.Data.UpsertDiscussion.Result.Id, nil
} }
func (c *Client) PostLink(url string, title string, text string, sub string) (int, error) { func (c *Client) PostLink(url string, title string, text string, sub string) (int, error) {
@ -302,7 +308,7 @@ func (c *Client) PostLink(url string, title string, text string, sub string) (in
Query: ` Query: `
mutation upsertLink($url: String!, $title: String!, $text: String, $sub: String!) { mutation upsertLink($url: String!, $title: String!, $text: String, $sub: String!) {
upsertLink(url: $url, title: $title, text: $text, sub: $sub) { upsertLink(url: $url, title: $title, text: $text, sub: $sub) {
id result { id }
} }
}`, }`,
Variables: map[string]interface{}{ Variables: map[string]interface{}{
@ -331,7 +337,7 @@ func (c *Client) PostLink(url string, title string, text string, sub string) (in
return -1, err return -1, err
} }
return respBody.Data.UpsertLink.Id, nil return respBody.Data.UpsertLink.Result.Id, nil
} }
func (c *Client) CreateComment(parentId int, text string) (int, error) { func (c *Client) CreateComment(parentId int, text string) (int, error) {
@ -339,7 +345,7 @@ func (c *Client) CreateComment(parentId int, text string) (int, error) {
Query: ` Query: `
mutation upsertComment($parentId: ID!, $text: String!) { mutation upsertComment($parentId: ID!, $text: String!) {
upsertComment(parentId: $parentId, text: $text) { upsertComment(parentId: $parentId, text: $text) {
id result { id }
} }
}`, }`,
Variables: map[string]interface{}{ Variables: map[string]interface{}{
@ -366,7 +372,7 @@ func (c *Client) CreateComment(parentId int, text string) (int, error) {
return -1, err return -1, err
} }
return respBody.Data.CreateComment.Id, nil return respBody.Data.CreateComment.Result.Id, nil
} }
func (c *Client) Dupes(url string) (*[]Dupe, error) { func (c *Client) Dupes(url string) (*[]Dupe, error) {