v1.5.0-gamma

This commit is contained in:
2023-06-30 11:21:47 +03:00
parent 29c7f143fe
commit f50f71ab0d
98 changed files with 2369 additions and 1150 deletions

View File

@@ -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]
}

View File

@@ -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) {

View File

@@ -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
}

View File

@@ -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"`
}

View File

@@ -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
}