Skip to content

Commit

Permalink
unify coding style for optional parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
okeyaki committed Nov 18, 2024
1 parent d6ec15d commit dbe49ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
10 changes: 5 additions & 5 deletions internal/client/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ type CreateUserInput struct {
Email string `json:"email"`
Password string `json:"password"`
Role string `json:"role"`
CanUseAuditLog *bool `json:"can_use_audit_log"`
IsRestrictedConnectionModify *bool `json:"is_restricted_connection_modify"`
CanUseAuditLog *bool `json:"can_use_audit_log,omitempty"`
IsRestrictedConnectionModify *bool `json:"is_restricted_connection_modify,omitempty"`
}

type CreateUserOutput struct {
Expand All @@ -117,9 +117,9 @@ func (client *TroccoClient) CreateUser(input *CreateUserInput) (*CreateUserOutpu
// Update a User

type UpdateUserInput struct {
Role *string `json:"role"`
CanUseAuditLog *bool `json:"can_use_audit_log"`
IsRestrictedConnectionModify *bool `json:"is_restricted_connection_modify"`
Role *string `json:"role,omitempty"`
CanUseAuditLog *bool `json:"can_use_audit_log,omitempty"`
IsRestrictedConnectionModify *bool `json:"is_restricted_connection_modify,omitempty"`
}

type UpdateUserOutput struct {
Expand Down
27 changes: 9 additions & 18 deletions internal/provider/user_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,11 @@ func (r *userResource) Create(ctx context.Context, req resource.CreateRequest, r
}

input := client.CreateUserInput{
Email: plan.Email.ValueString(),
Password: plan.Password.ValueString(),
Role: plan.Role.ValueString(),
}
if !plan.CanUseAuditLog.IsNull() {
input.CanUseAuditLog = plan.CanUseAuditLog.ValueBoolPointer()
}
if !plan.IsRestrictedConnectionModify.IsNull() {
input.IsRestrictedConnectionModify = plan.IsRestrictedConnectionModify.ValueBoolPointer()
Email: plan.Email.ValueString(),
Password: plan.Password.ValueString(),
Role: plan.Role.ValueString(),
CanUseAuditLog: plan.CanUseAuditLog.ValueBoolPointer(),
IsRestrictedConnectionModify: plan.IsRestrictedConnectionModify.ValueBoolPointer(),
}

user, err := r.client.CreateUser(&input)
Expand Down Expand Up @@ -208,15 +204,10 @@ func (r *userResource) Update(ctx context.Context, req resource.UpdateRequest, r
return
}

input := client.UpdateUserInput{}
if !plan.Role.IsNull() {
input.Role = plan.Role.ValueStringPointer()
}
if !plan.CanUseAuditLog.IsNull() {
input.CanUseAuditLog = plan.CanUseAuditLog.ValueBoolPointer()
}
if !plan.IsRestrictedConnectionModify.IsNull() {
input.IsRestrictedConnectionModify = plan.IsRestrictedConnectionModify.ValueBoolPointer()
input := client.UpdateUserInput{
Role: plan.Role.ValueStringPointer(),
CanUseAuditLog: plan.CanUseAuditLog.ValueBoolPointer(),
IsRestrictedConnectionModify: plan.IsRestrictedConnectionModify.ValueBoolPointer(),
}

user, err := r.client.UpdateUser(state.ID.ValueInt64(), &input)
Expand Down

0 comments on commit dbe49ec

Please sign in to comment.