github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/api/cloudcontroller/ccv3/space.go (about)

     1  package ccv3
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
     5  	"code.cloudfoundry.org/cli/resources"
     6  )
     7  
     8  func (client *Client) CreateSpace(space resources.Space) (resources.Space, Warnings, error) {
     9  	var responseBody resources.Space
    10  
    11  	_, warnings, err := client.MakeRequest(RequestParams{
    12  		RequestName:  internal.PostSpaceRequest,
    13  		RequestBody:  space,
    14  		ResponseBody: &responseBody,
    15  	})
    16  
    17  	return responseBody, warnings, err
    18  }
    19  
    20  func (client *Client) DeleteSpace(spaceGUID string) (JobURL, Warnings, error) {
    21  	jobURL, warnings, err := client.MakeRequest(RequestParams{
    22  		RequestName: internal.DeleteSpaceRequest,
    23  		URIParams:   internal.Params{"space_guid": spaceGUID},
    24  	})
    25  
    26  	return jobURL, warnings, err
    27  }
    28  
    29  // GetSpaces lists spaces with optional filters.
    30  func (client *Client) GetSpaces(query ...Query) ([]resources.Space, IncludedResources, Warnings, error) {
    31  	var returnedResources []resources.Space
    32  
    33  	includedResources, warnings, err := client.MakeListRequest(RequestParams{
    34  		RequestName:  internal.GetSpacesRequest,
    35  		Query:        query,
    36  		ResponseBody: resources.Space{},
    37  		AppendToList: func(item interface{}) error {
    38  			returnedResources = append(returnedResources, item.(resources.Space))
    39  			return nil
    40  		},
    41  	})
    42  
    43  	return returnedResources, includedResources, warnings, err
    44  }
    45  
    46  func (client *Client) UpdateSpace(space resources.Space) (resources.Space, Warnings, error) {
    47  	spaceGUID := space.GUID
    48  	space.GUID = ""
    49  	space.Relationships = nil
    50  
    51  	var responseBody resources.Space
    52  
    53  	_, warnings, err := client.MakeRequest(RequestParams{
    54  		RequestName:  internal.PatchSpaceRequest,
    55  		URIParams:    internal.Params{"space_guid": spaceGUID},
    56  		RequestBody:  space,
    57  		ResponseBody: &responseBody,
    58  	})
    59  
    60  	return responseBody, warnings, err
    61  }