|
@@ -346,5 +346,23 @@ func (r *orderResource) Update(ctx context.Context, req resource.UpdateRequest,
|
|
|
|
|
|
// Delete deletes the resource and removes the Terraform state on success.
|
|
|
func (r *orderResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
|
|
- return
|
|
|
+ // 1. Retrieves values from the state.
|
|
|
+ // 1.a The method will attempt to retrieve values from the state and convert it to an orderResourceModel struct
|
|
|
+ var state orderResourceModel
|
|
|
+ diags := req.State.Get(ctx, &state)
|
|
|
+ resp.Diagnostics.Append(diags...)
|
|
|
+ if resp.Diagnostics.HasError() {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. Deletes an existing order.
|
|
|
+ // The method invokes the API client's DeleteOrder method.
|
|
|
+ err := r.client.DeleteOrder(state.ID.ValueString())
|
|
|
+ if err != nil {
|
|
|
+ resp.Diagnostics.AddError(
|
|
|
+ "Error Deleting HashiCups Order",
|
|
|
+ "Could not delete order, unexpected error: "+err.Error(),
|
|
|
+ )
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|