Skip to content

Commit

Permalink
feat: add API request body validation
Browse files Browse the repository at this point in the history
  • Loading branch information
acch committed Oct 3, 2024
1 parent 1d6651a commit c1669aa
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions internal/provider/organization_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ func (r *organizationResource) Create(ctx context.Context, req resource.CreateRe
Visibility: forgejo.VisibleType(data.Visibility.ValueString()),
}

// TODO: opts.validate()
// Validate API request body
err := opts.Validate()
if err != nil {
resp.Diagnostics.AddError("Input Validation Error", fmt.Sprintf("Error '%s'.", err))

return
}

// Use Forgejo client to create new organization
o, re, err := r.client.CreateOrg(opts)
Expand Down Expand Up @@ -273,7 +279,14 @@ func (r *organizationResource) Update(ctx context.Context, req resource.UpdateRe
Visibility: forgejo.VisibleType(data.Visibility.ValueString()),
}

// TODO: opts.validate()
// Validate API request body
err := opts.Validate()
if err != nil {

resp.Diagnostics.AddError("Input Validation Error", fmt.Sprintf("Error '%s'.", err))

return
}

// Use Forgejo client to update existing organization
re, err := r.client.EditOrg(data.Name.ValueString(), opts)
Expand Down

0 comments on commit c1669aa

Please sign in to comment.