v1.5.0-gamma
This commit is contained in:
@@ -31,21 +31,23 @@ func (ll ListLocations) FilterByGID(gid uint64) ListLocations {
|
||||
func (ll ListLocations) FilterFunc(predicate func(ItemLocation) bool) ListLocations {
|
||||
var result ListLocations
|
||||
|
||||
for _, item := range ll {
|
||||
for _, item := range ll.Data {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
result.Data = append(result.Data, item)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(result.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemLocation
|
||||
// If none was found, returns an empty struct.
|
||||
func (ll ListLocations) FindOne() ItemLocation {
|
||||
if len(ll) == 0 {
|
||||
if len(ll.Data) == 0 {
|
||||
return ItemLocation{}
|
||||
}
|
||||
|
||||
return ll[0]
|
||||
return ll.Data[0]
|
||||
}
|
||||
|
||||
@@ -3,48 +3,51 @@ package locations
|
||||
import "testing"
|
||||
|
||||
var locationItems = ListLocations{
|
||||
{
|
||||
GID: 212,
|
||||
ID: 1,
|
||||
GUID: 1,
|
||||
LocationCode: "alfa",
|
||||
Name: "alfa",
|
||||
Flag: "",
|
||||
Meta: []interface{}{
|
||||
"cloudbroker",
|
||||
"location",
|
||||
1,
|
||||
Data: []ItemLocation{
|
||||
{
|
||||
GID: 212,
|
||||
ID: 1,
|
||||
GUID: 1,
|
||||
LocationCode: "alfa",
|
||||
Name: "alfa",
|
||||
Flag: "",
|
||||
Meta: []interface{}{
|
||||
"cloudbroker",
|
||||
"location",
|
||||
1,
|
||||
},
|
||||
CKey: "",
|
||||
},
|
||||
CKey: "",
|
||||
},
|
||||
{
|
||||
GID: 222,
|
||||
ID: 2,
|
||||
GUID: 2,
|
||||
LocationCode: "beta",
|
||||
Name: "beta",
|
||||
Flag: "",
|
||||
Meta: []interface{}{
|
||||
"cloudbroker",
|
||||
"location",
|
||||
1,
|
||||
{
|
||||
GID: 222,
|
||||
ID: 2,
|
||||
GUID: 2,
|
||||
LocationCode: "beta",
|
||||
Name: "beta",
|
||||
Flag: "",
|
||||
Meta: []interface{}{
|
||||
"cloudbroker",
|
||||
"location",
|
||||
1,
|
||||
},
|
||||
CKey: "",
|
||||
},
|
||||
CKey: "",
|
||||
},
|
||||
{
|
||||
GID: 232,
|
||||
ID: 3,
|
||||
GUID: 3,
|
||||
LocationCode: "gamma",
|
||||
Name: "gamma",
|
||||
Flag: "",
|
||||
Meta: []interface{}{
|
||||
"cloudbroker",
|
||||
"location",
|
||||
1,
|
||||
{
|
||||
GID: 232,
|
||||
ID: 3,
|
||||
GUID: 3,
|
||||
LocationCode: "gamma",
|
||||
Name: "gamma",
|
||||
Flag: "",
|
||||
Meta: []interface{}{
|
||||
"cloudbroker",
|
||||
"location",
|
||||
1,
|
||||
},
|
||||
CKey: "",
|
||||
},
|
||||
CKey: "",
|
||||
},
|
||||
EntryCount: 3,
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
|
||||
@@ -15,10 +15,26 @@ type ListRequest struct {
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
|
||||
// Find by flag
|
||||
// Required: false
|
||||
Flag string `url:"flag,omitempty" json:"flag,omitempty"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by ID
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by code location
|
||||
// Required: false
|
||||
LocationCode string `url:"locationCode,omitempty" json:"locationCode,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list all locations
|
||||
func (l Locations) List(ctx context.Context, req ListRequest) (ListLocations, error) {
|
||||
func (l Locations) List(ctx context.Context, req ListRequest) (*ListLocations, error) {
|
||||
url := "/cloudapi/locations/list"
|
||||
|
||||
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -33,5 +49,5 @@ func (l Locations) List(ctx context.Context, req ListRequest) (ListLocations, er
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -28,4 +28,10 @@ type ItemLocation struct {
|
||||
}
|
||||
|
||||
// List of locations
|
||||
type ListLocations []ItemLocation
|
||||
type ListLocations struct {
|
||||
// Data
|
||||
Data []ItemLocation `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ll ListLocations) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(ll) == 0 {
|
||||
if len(ll.Data) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user