-
Notifications
You must be signed in to change notification settings - Fork 1
/
create.go
56 lines (47 loc) · 2 KB
/
create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package webuserresponse
import (
"context"
"fmt"
"github.com/CheckPointSW/terraform-provider-infinity-next/internal/api"
models "github.com/CheckPointSW/terraform-provider-infinity-next/internal/models/web-user-response"
"github.com/CheckPointSW/terraform-provider-infinity-next/internal/utils"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func CreateWebUserResponseBehaviorInputFromResourceData(d *schema.ResourceData) (models.CreateWebUserResponseBehaviorInput, error) {
var input models.CreateWebUserResponseBehaviorInput
input.Name = d.Get("name").(string)
input.Visibility = "Shared"
input.Mode = d.Get("mode").(string)
input.MessageTitle = d.Get("message_title").(string)
input.MessageBody = d.Get("message_body").(string)
input.HTTPResponseCode = d.Get("http_response_code").(int)
input.RedirectURL = d.Get("redirect_url").(string)
input.XEventID = d.Get("x_event_id").(bool)
return input, nil
}
func NewWebUserResponseBehavior(ctx context.Context, c *api.Client, input models.CreateWebUserResponseBehaviorInput) (models.WebUserResponseBehavior, error) {
vars := map[string]any{"ownerId": nil, "practiceId": nil, "behaviorInput": input}
res, err := c.MakeGraphQLRequest(ctx, `
mutation newWebUserResponseBehavior($ownerId: ID, $practiceId: ID, $behaviorInput: WebUserResponseBehaviorInput)
{
newWebUserResponseBehavior(ownerId: $ownerId, practiceId: $practiceId, behaviorInput: $behaviorInput) {
id
name
mode
messageTitle
messageBody
httpResponseCode
redirectURL
xEventId
}
}
`, "newWebUserResponseBehavior", vars)
if err != nil {
return models.WebUserResponseBehavior{}, fmt.Errorf("failed to create new WebUserResponseBehavior: %w", err)
}
behavior, err := utils.UnmarshalAs[models.WebUserResponseBehavior](res)
if err != nil {
return models.WebUserResponseBehavior{}, fmt.Errorf("failed to convert response to CreateWebUserResponseBehaviorResponse struct. Error: %w", err)
}
return behavior, err
}