Skip to content

Commit

Permalink
Merge pull request #7 from zaphiro-technologies/fix-iproute-struct-in…
Browse files Browse the repository at this point in the history
…-ip-services

reuse Route struct in IPservice for Responses
  • Loading branch information
arslanbekov authored Apr 24, 2024
2 parents 8fdba4f + 0ed9426 commit 043d29f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
35 changes: 20 additions & 15 deletions cloudconnexa/ip_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@ type IPService struct {
Config *IPServiceConfig `json:"config"`
}

type IPServiceResponse struct {
IPService
Routes []*Route `json:"routes"`
}

type IPServicePageResponse struct {
Content []IPService `json:"content"`
NumberOfElements int `json:"numberOfElements"`
Page int `json:"page"`
Size int `json:"size"`
Success bool `json:"success"`
TotalElements int `json:"totalElements"`
TotalPages int `json:"totalPages"`
Content []IPServiceResponse `json:"content"`
NumberOfElements int `json:"numberOfElements"`
Page int `json:"page"`
Size int `json:"size"`
Success bool `json:"success"`
TotalElements int `json:"totalElements"`
TotalPages int `json:"totalPages"`
}

type IPServicesService service
Expand All @@ -73,8 +78,8 @@ func (c *IPServicesService) GetIPByPage(page int, pageSize int) (IPServicePageRe
return response, nil
}

func (c *IPServicesService) List() ([]IPService, error) {
var allIPServices []IPService
func (c *IPServicesService) List() ([]IPServiceResponse, error) {
var allIPServices []IPServiceResponse
page := 0
pageSize := 10

Expand All @@ -93,7 +98,7 @@ func (c *IPServicesService) List() ([]IPService, error) {
return allIPServices, nil
}

func (c *IPServicesService) Get(serviceID string) (*IPService, error) {
func (c *IPServicesService) Get(serviceID string) (*IPServiceResponse, error) {
endpoint := fmt.Sprintf("%s/api/beta/ip-services/single?serviceId=%s", c.client.BaseURL, serviceID)
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
if err != nil {
Expand All @@ -105,15 +110,15 @@ func (c *IPServicesService) Get(serviceID string) (*IPService, error) {
return nil, err
}

var service IPService
var service IPServiceResponse
err = json.Unmarshal(body, &service)
if err != nil {
return nil, err
}
return &service, nil
}

func (c *IPServicesService) Create(ipService *IPService) (*IPService, error) {
func (c *IPServicesService) Create(ipService *IPService) (*IPServiceResponse, error) {
ipServiceJson, err := json.Marshal(ipService)
if err != nil {
return nil, err
Expand All @@ -132,15 +137,15 @@ func (c *IPServicesService) Create(ipService *IPService) (*IPService, error) {
return nil, err
}

var s IPService
var s IPServiceResponse
err = json.Unmarshal(body, &s)
if err != nil {
return nil, err
}
return &s, nil
}

func (c *IPServicesService) Update(id string, service *IPService) (*IPService, error) {
func (c *IPServicesService) Update(id string, service *IPService) (*IPServiceResponse, error) {
serviceJson, err := json.Marshal(service)
if err != nil {
return nil, err
Expand All @@ -158,7 +163,7 @@ func (c *IPServicesService) Update(id string, service *IPService) (*IPService, e
return nil, err
}

var s IPService
var s IPServiceResponse
err = json.Unmarshal(body, &s)
if err != nil {
return nil, err
Expand Down
1 change: 0 additions & 1 deletion cloudconnexa/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func (c *RoutesService) GetByPage(networkId string, page int, size int) (RoutePa

var response RoutePageResponse
err = json.Unmarshal(body, &response)
fmt.Printf("response: %+v\n", response)
if err != nil {
return RoutePageResponse{}, err
}
Expand Down

0 comments on commit 043d29f

Please sign in to comment.