Skip to content
This repository has been archived by the owner on Nov 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6 from bill-ezhao/feature/activate-template-versi…
Browse files Browse the repository at this point in the history
…on-fix

feat: addition of activate template POST api endpoint for when template versions get updated
  • Loading branch information
arslanbekov authored May 11, 2023
2 parents bf4f316 + 8a62563 commit 7fe02f2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions sdk/template_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@ func (c *Client) UpdateTemplateVersion(ctx context.Context, t TemplateVersion) (
return parseTemplateVersion(respBody)
}

// ActivateTemplateVersion activates a version of a transactional template and returns it.
func (c *Client) ActivateTemplateVersion(ctx context.Context, t TemplateVersion) (*TemplateVersion, error) {
if t.ID == "" {
return nil, ErrTemplateVersionIDRequired
}

if t.TemplateID == "" {
return nil, ErrTemplateIDRequired
}

respBody, _, err := c.Post(ctx, "POST", "/templates/"+t.TemplateID+"/versions/"+t.ID+"/activate", t)
if err != nil {
return nil, fmt.Errorf("failed activating template version: %w", err)
}

return parseTemplateVersion(respBody)
}

// DeleteTemplateVersion deletes a version of a transactional template.
func (c *Client) DeleteTemplateVersion(ctx context.Context, templateID, id string) (bool, error) {
if templateID == "" {
Expand Down
6 changes: 6 additions & 0 deletions sendgrid/resource_sendgrid_template_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ func resourceSendgridTemplateVersionUpdate(
templateVersion.Active = d.Get("active").(int)
}

if templateVersion.Active == 1 {
if _, err := c.ActivateTemplateVersion(ctx, templateVersion); err != nil {
return diag.FromErr(err)
}
}

if d.HasChange("name") {
templateVersion.Name = d.Get("name").(string)
}
Expand Down

0 comments on commit 7fe02f2

Please sign in to comment.