Skip to content

Commit 2fc76ed

Browse files
committed
feat: add Campaign CRUD methods and input/payload types
Adds GetCampaign, CreateCampaign, UpdateCampaign, DeleteCampaign, ScheduleCampaign, and UnscheduleCampaign client methods along with their corresponding input and payload types. These are needed by the terraform-provider-opslevel campaign resource. Made-with: Cursor
1 parent 3c76911 commit 2fc76ed

3 files changed

Lines changed: 129 additions & 0 deletions

File tree

campaign.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,76 @@ func (v *ListCampaignsVariables) AsPayloadVariables() *PayloadVariables {
2525
return &variables
2626
}
2727

28+
func (client *Client) CreateCampaign(input CampaignCreateInput) (*Campaign, error) {
29+
var m struct {
30+
Payload CampaignCreatePayload `graphql:"campaignCreate(input: $input)"`
31+
}
32+
v := PayloadVariables{
33+
"input": input,
34+
}
35+
err := client.Mutate(&m, v, WithName("CampaignCreate"))
36+
return &m.Payload.Campaign, HandleErrors(err, m.Payload.Errors)
37+
}
38+
39+
func (client *Client) GetCampaign(id ID) (*Campaign, error) {
40+
var q struct {
41+
Account struct {
42+
Campaign Campaign `graphql:"campaign(id: $id)"`
43+
}
44+
}
45+
v := PayloadVariables{
46+
"id": id,
47+
}
48+
err := client.Query(&q, v, WithName("CampaignGet"))
49+
return &q.Account.Campaign, HandleErrors(err, nil)
50+
}
51+
52+
func (client *Client) UpdateCampaign(input CampaignUpdateInput) (*Campaign, error) {
53+
var m struct {
54+
Payload CampaignUpdatePayload `graphql:"campaignUpdate(input: $input)"`
55+
}
56+
v := PayloadVariables{
57+
"input": input,
58+
}
59+
err := client.Mutate(&m, v, WithName("CampaignUpdate"))
60+
return &m.Payload.Campaign, HandleErrors(err, m.Payload.Errors)
61+
}
62+
63+
func (client *Client) DeleteCampaign(id ID) error {
64+
var m struct {
65+
Payload CampaignDeletePayload `graphql:"campaignDelete(input: $input)"`
66+
}
67+
v := PayloadVariables{
68+
"input": CampaignDeleteInput{Id: id},
69+
}
70+
err := client.Mutate(&m, v, WithName("CampaignDelete"))
71+
return HandleErrors(err, m.Payload.Errors)
72+
}
73+
74+
func (client *Client) ScheduleCampaign(input CampaignScheduleUpdateInput) (*Campaign, error) {
75+
var m struct {
76+
Payload CampaignSchedulePayload `graphql:"campaignSchedule(input: $input)"`
77+
}
78+
v := PayloadVariables{
79+
"input": input,
80+
}
81+
err := client.Mutate(&m, v, WithName("CampaignSchedule"))
82+
return &m.Payload.Campaign, HandleErrors(err, m.Payload.Errors)
83+
}
84+
85+
func (client *Client) UnscheduleCampaign(id ID) (*Campaign, error) {
86+
var m struct {
87+
Payload CampaignUnschedulePayload `graphql:"campaignUnschedule(input: $input)"`
88+
}
89+
v := PayloadVariables{
90+
"input": struct {
91+
Id ID `json:"id"`
92+
}{Id: id},
93+
}
94+
err := client.Mutate(&m, v, WithName("CampaignUnschedule"))
95+
return &m.Payload.Campaign, HandleErrors(err, m.Payload.Errors)
96+
}
97+
2898
func (client *Client) ListCampaigns(campaignVariables *ListCampaignsVariables) (*CampaignConnection, error) {
2999
if campaignVariables == nil {
30100
campaignVariables = &ListCampaignsVariables{}

input.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,35 @@ type CategoryUpdateInput struct {
9393
Name *Nullable[string] `json:"name,omitempty" yaml:"name,omitempty" example:"example_value"` // The display name of the category (Optional)
9494
}
9595

96+
// CampaignCreateInput Specifies the input fields used to create a campaign
97+
type CampaignCreateInput struct {
98+
Name string `json:"name" yaml:"name" example:"example_value"` // The name of the campaign (Required)
99+
OwnerId ID `json:"ownerId" yaml:"ownerId" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the team that owns the campaign (Required)
100+
FilterId *Nullable[ID] `json:"filterId,omitempty" yaml:"filterId,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the filter applied to the campaign (Optional)
101+
ProjectBrief *string `json:"projectBrief,omitempty" yaml:"projectBrief,omitempty" example:"example_value"` // The project brief of the campaign in Markdown (Optional)
102+
}
103+
104+
// CampaignDeleteInput Specifies the input fields used to delete a campaign
105+
type CampaignDeleteInput struct {
106+
Id ID `json:"id" yaml:"id" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the campaign to be deleted (Required)
107+
}
108+
109+
// CampaignScheduleUpdateInput Specifies the input fields used to schedule a campaign
110+
type CampaignScheduleUpdateInput struct {
111+
Id ID `json:"id" yaml:"id" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the campaign to be scheduled (Required)
112+
StartDate iso8601.Time `json:"startDate" yaml:"startDate" example:"2025-01-01T00:00:00Z"` // The start date of the campaign (Required)
113+
TargetDate iso8601.Time `json:"targetDate" yaml:"targetDate" example:"2025-06-01T00:00:00Z"` // The target end date of the campaign (Required)
114+
}
115+
116+
// CampaignUpdateInput Specifies the input fields used to update a campaign
117+
type CampaignUpdateInput struct {
118+
Id ID `json:"id" yaml:"id" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the campaign to be updated (Required)
119+
Name *string `json:"name,omitempty" yaml:"name,omitempty" example:"example_value"` // The name of the campaign (Optional)
120+
OwnerId *Nullable[ID] `json:"ownerId,omitempty" yaml:"ownerId,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the team that owns the campaign (Optional)
121+
FilterId *Nullable[ID] `json:"filterId,omitempty" yaml:"filterId,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the filter applied to the campaign (Optional)
122+
ProjectBrief *string `json:"projectBrief,omitempty" yaml:"projectBrief,omitempty" example:"example_value"` // The project brief of the campaign in Markdown (Optional)
123+
}
124+
96125
// CheckAlertSourceUsageCreateInput Specifies the input fields used to create an alert source usage check
97126
type CheckAlertSourceUsageCreateInput struct {
98127
AlertSourceNamePredicate *PredicateInput `json:"alertSourceNamePredicate,omitempty" yaml:"alertSourceNamePredicate,omitempty"` // The condition that the alert source name should satisfy to be evaluated (Optional)

payload.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,36 @@ type CategoryUpdatePayload struct {
3030
BasePayload
3131
}
3232

33+
// CampaignCreatePayload The return type of the `campaignCreate` mutation
34+
type CampaignCreatePayload struct {
35+
Campaign Campaign // The created campaign (Optional)
36+
BasePayload
37+
}
38+
39+
// CampaignUpdatePayload The return type of the `campaignUpdate` mutation
40+
type CampaignUpdatePayload struct {
41+
Campaign Campaign // The updated campaign (Optional)
42+
BasePayload
43+
}
44+
45+
// CampaignSchedulePayload The return type of the `campaignSchedule` mutation
46+
type CampaignSchedulePayload struct {
47+
Campaign Campaign // The scheduled campaign (Optional)
48+
BasePayload
49+
}
50+
51+
// CampaignUnschedulePayload The return type of the `campaignUnschedule` mutation
52+
type CampaignUnschedulePayload struct {
53+
Campaign Campaign // The unscheduled campaign (Optional)
54+
BasePayload
55+
}
56+
57+
// CampaignDeletePayload The return type of the `campaignDelete` mutation
58+
type CampaignDeletePayload struct {
59+
Id ID `graphql:"deletedCampaignId"` // The id of the deleted campaign
60+
BasePayload
61+
}
62+
3363
// CheckCopyPayload The result of a check copying operation
3464
type CheckCopyPayload struct {
3565
TargetCategory Category // The category to which the checks have been copied (Optional)

0 commit comments

Comments
 (0)