You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
914 B
53 lines
914 B
package grid
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
// Request struct for rename grid
|
|
type RenameRequest struct {
|
|
// Grid (platform) ID
|
|
// Required: true
|
|
GID uint64 `url:"gid"`
|
|
|
|
// New name
|
|
// Required: true
|
|
Name string `url:"Name"`
|
|
}
|
|
|
|
func (grq RenameRequest) validate() error {
|
|
if grq.GID == 0 {
|
|
return errors.New("validation-error: field GID must be set")
|
|
}
|
|
if grq.Name == "" {
|
|
return errors.New("validation-error: field Name must be set")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Rename renames a grid
|
|
func (g Grid) Rename(ctx context.Context, req RenameRequest) (bool, error) {
|
|
err := req.validate()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
url := "/cloudbroker/grid/rename"
|
|
|
|
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
result, err := strconv.ParseBool(string(res))
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return result, nil
|
|
}
|