Skip to content

Commit

Permalink
basic client logic
Browse files Browse the repository at this point in the history
  • Loading branch information
luis committed Nov 9, 2023
1 parent 3b5fe53 commit 5ce51b7
Showing 1 changed file with 65 additions and 65 deletions.
130 changes: 65 additions & 65 deletions resource/account_user/account_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,70 +42,70 @@ func resourceWPEngineAccountUserCreate(ctx context.Context, d *schema.ResourceDa
return diags
}

// func resourceWPEngineAccountUserRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
// var diags diag.Diagnostics
//
// client := m.(*client.ApiClient)
//
// // Get the user ID from the resource data
// userID := d.Id()
//
// // Call the client method to get the user details
// user, err := client.GetAccountUser(userID)
// if err != nil {
// return diag.FromErr(err)
// }
//
// // Set the resource data from the user details
// d.Set("first_name", user["first_name"])
// d.Set("last_name", user["last_name"])
// d.Set("email", user["email"])
//
// return diags
// }

// func resourceWPEngineAccountUserUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
// var diags diag.Diagnostics
//
// client := m.(*client.ApiClient)
//
// userID := d.Id()
//
// // Check which fields have changed
// if d.HasChanges("first_name", "last_name", "email") {
// userData := map[string]interface{}{
// "first_name": d.Get("first_name").(string),
// "last_name": d.Get("last_name").(string),
// "email": d.Get("email").(string),
// }
//
// // Call the client method to update the user details
// _, err := client.UpdateAccountUser(userID, userData)
// if err != nil {
// return diag.FromErr(err)
// }
// }
//
// // Call read to update the state
// return resourceWPEngineAccountUserRead(ctx, d, m)
// }

// func resourceWPEngineAccountUserDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
// var diags diag.Diagnostics
//
// client := m.(*client.ApiClient)
//
// userID := d.Id()
//
// err := client.DeleteAccountUser(userID)
// if err != nil {
// return diag.FromErr(err)
// }
//
// // Remove the user ID from the state as it no longer exists
// d.SetId("")
//
// return diags
// }
func resourceWPEngineAccountUserRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
var diags diag.Diagnostics

client := m.(*client.ApiClient)

// Get the user ID from the resource data
userID := d.Id()

// Call the client method to get the user details
user, err := client.GetAccountUser(userID)
if err != nil {
return diag.FromErr(err)
}

// Set the resource data from the user details
d.Set("first_name", user["first_name"])
d.Set("last_name", user["last_name"])
d.Set("email", user["email"])

return diags
}

func resourceWPEngineAccountUserUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
// var diags diag.Diagnostics

client := m.(*client.ApiClient)

userID := d.Id()

// Check which fields have changed
if d.HasChanges("first_name", "last_name", "email") {
userData := map[string]interface{}{
"first_name": d.Get("first_name").(string),
"last_name": d.Get("last_name").(string),
"email": d.Get("email").(string),
}

// Call the client method to update the user details
_, err := client.UpdateAccountUser(userID, userData)
if err != nil {
return diag.FromErr(err)
}
}

// Call read to update the state
return resourceWPEngineAccountUserRead(ctx, d, m)
}

func resourceWPEngineAccountUserDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
var diags diag.Diagnostics

client := m.(*client.ApiClient)

userID := d.Id()

err := client.DeleteAccountUser(userID)
if err != nil {
return diag.FromErr(err)
}

// Remove the user ID from the state as it no longer exists
d.SetId("")

return diags
}

// end resourceWPEngineAccountUser

0 comments on commit 5ce51b7

Please sign in to comment.