Skip to content

Commit ce3f70f

Browse files
author
Cem Küçük
authored
Merge pull request #39 from opsgenie/implement-change-end-date-endpoint
Added change-end-date endpoint for maintenance
2 parents cf7378a + 7c7e2da commit ce3f70f

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

maintenance/maintenance.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ func (c *Client) Update(context context.Context, request *UpdateRequest) (*Updat
4444
return result, nil
4545
}
4646

47+
func (c *Client) ChangeEndDate(context context.Context, request *ChangeEndDateRequest) (*ChangeEndDateResult, error) {
48+
result := &ChangeEndDateResult{}
49+
err := c.client.Exec(context, request, result)
50+
if err != nil {
51+
return nil, err
52+
}
53+
return result, nil
54+
}
55+
4756
func (c *Client) Delete(context context.Context, request *DeleteRequest) (*DeleteResult, error) {
4857
result := &DeleteResult{}
4958
err := c.client.Exec(context, request, result)

maintenance/maintenance_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ func TestUpdateRequest_Validate(t *testing.T) {
7474
assert.Nil(t, err)
7575
}
7676

77+
func TestChangeEndDateRequest_Validate(t *testing.T) {
78+
now := time.Now()
79+
after := now.Add(time.Minute)
80+
request := &ChangeEndDateRequest{}
81+
err := request.Validate()
82+
assert.Equal(t, err.Error(), errors.New("Maintenance ID cannot be blank.").Error())
83+
request.Id = "e14dda76-488e-4e98-a1c7-78cda1900e27"
84+
err = request.Validate()
85+
assert.Equal(t, err.Error(), errors.New("Maintenance End Date cannot be blank.").Error())
86+
request.EndDate = &after
87+
err = request.Validate()
88+
assert.Nil(t, err)
89+
}
90+
7791
func TestDeleteRequest_Validate(t *testing.T) {
7892
request := &DeleteRequest{}
7993
err := request.Validate()

maintenance/request.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,30 @@ func (r *UpdateRequest) Method() string {
9292
return http.MethodPut
9393
}
9494

95+
type ChangeEndDateRequest struct {
96+
client.BaseRequest
97+
Id string
98+
EndDate *time.Time `json:"endDate"`
99+
}
100+
101+
func (r *ChangeEndDateRequest) Validate() error {
102+
if r.Id == "" {
103+
return errors.New("Maintenance ID cannot be blank.")
104+
}
105+
if r.EndDate == nil {
106+
return errors.New("Maintenance End Date cannot be blank.")
107+
}
108+
return nil
109+
}
110+
111+
func (r *ChangeEndDateRequest) ResourcePath() string {
112+
return "/v1/maintenance/" + r.Id + "/change-end-date"
113+
}
114+
115+
func (r *ChangeEndDateRequest) Method() string {
116+
return http.MethodPost
117+
}
118+
95119
type DeleteRequest struct {
96120
client.BaseRequest
97121
Id string

maintenance/result.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ type UpdateResult struct {
1919
Maintenance
2020
}
2121

22+
type ChangeEndDateResult struct {
23+
client.ResultMetadata
24+
Maintenance
25+
}
26+
2227
type GetResult struct {
2328
client.ResultMetadata
2429
Id string `json:"id"`

0 commit comments

Comments
 (0)