v1.5.0-gamma
This commit is contained in:
@@ -58,21 +58,23 @@ func (lv ListVINS) FilterByDeletedBy(deletedBy string) ListVINS {
|
||||
func (lv ListVINS) FilterFunc(predicate func(ItemVINS) bool) ListVINS {
|
||||
var result ListVINS
|
||||
|
||||
for _, item := range lv {
|
||||
for _, item := range lv.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 ItemVINS
|
||||
// If none was found, returns an empty struct.
|
||||
func (lv ListVINS) FindOne() ItemVINS {
|
||||
if len(lv) == 0 {
|
||||
if len(lv.Data) == 0 {
|
||||
return ItemVINS{}
|
||||
}
|
||||
|
||||
return lv[0]
|
||||
return lv.Data[0]
|
||||
}
|
||||
|
||||
@@ -3,60 +3,64 @@ package vins
|
||||
import "testing"
|
||||
|
||||
var vinsItems = ListVINS{
|
||||
{
|
||||
AccountID: 1,
|
||||
AccountName: "std",
|
||||
CreatedBy: "sample_user_1@decs3o",
|
||||
CreatedTime: 1676898844,
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
ExternalIP: "",
|
||||
ID: 1,
|
||||
Name: "vins01",
|
||||
Network: "192.168.1.0/24",
|
||||
RGID: 7971,
|
||||
RGName: "rg_01",
|
||||
Status: "ENABLED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VXLANID: 3544,
|
||||
},
|
||||
{
|
||||
AccountID: 2,
|
||||
AccountName: "std2",
|
||||
CreatedBy: "sample_user_1@decs3o",
|
||||
CreatedTime: 1676898948,
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
ExternalIP: "",
|
||||
ID: 2,
|
||||
Name: "vins02",
|
||||
Network: "192.168.2.0/24",
|
||||
RGID: 7972,
|
||||
RGName: "rg_02",
|
||||
Status: "ENABLED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VXLANID: 3545,
|
||||
},
|
||||
{
|
||||
AccountID: 3,
|
||||
AccountName: "std3",
|
||||
CreatedBy: "sample_user_2@decs3o",
|
||||
CreatedTime: 1676899026,
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
ExternalIP: "",
|
||||
ID: 3,
|
||||
Name: "vins03",
|
||||
Network: "192.168.3.0/24",
|
||||
RGID: 7973,
|
||||
RGName: "rg_03",
|
||||
Status: "DISABLED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VXLANID: 3546,
|
||||
Data: []ItemVINS{
|
||||
{
|
||||
AccountID: 1,
|
||||
AccountName: "std",
|
||||
CreatedBy: "sample_user_1@decs3o",
|
||||
CreatedTime: 1676898844,
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
ExternalIP: "",
|
||||
ID: 1,
|
||||
Name: "vins01",
|
||||
Network: "192.168.1.0/24",
|
||||
RGID: 7971,
|
||||
RGName: "rg_01",
|
||||
Status: "ENABLED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VXLANID: 3544,
|
||||
},
|
||||
{
|
||||
AccountID: 2,
|
||||
AccountName: "std2",
|
||||
CreatedBy: "sample_user_1@decs3o",
|
||||
CreatedTime: 1676898948,
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
ExternalIP: "",
|
||||
ID: 2,
|
||||
Name: "vins02",
|
||||
Network: "192.168.2.0/24",
|
||||
RGID: 7972,
|
||||
RGName: "rg_02",
|
||||
Status: "ENABLED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VXLANID: 3545,
|
||||
},
|
||||
{
|
||||
AccountID: 3,
|
||||
AccountName: "std3",
|
||||
CreatedBy: "sample_user_2@decs3o",
|
||||
CreatedTime: 1676899026,
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
ExternalIP: "",
|
||||
ID: 3,
|
||||
Name: "vins03",
|
||||
Network: "192.168.3.0/24",
|
||||
RGID: 7973,
|
||||
RGName: "rg_03",
|
||||
Status: "DISABLED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VXLANID: 3546,
|
||||
},
|
||||
},
|
||||
|
||||
EntryCount: 3,
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
@@ -86,11 +90,11 @@ func TestFilterByAccountID(t *testing.T) {
|
||||
func TestFilterByCreatedBy(t *testing.T) {
|
||||
actual := vinsItems.FilterByCreatedBy("sample_user_1@decs3o")
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
for _, item := range actual.Data {
|
||||
if item.CreatedBy != "sample_user_1@decs3o" {
|
||||
t.Fatal("expected CreatedBy 'sample_user_1@decs3o', found: ", item.CreatedBy)
|
||||
}
|
||||
@@ -111,7 +115,7 @@ func TestFilterFunc(t *testing.T) {
|
||||
func TestSortByCreatedTime(t *testing.T) {
|
||||
actual := vinsItems.SortByCreatedTime(false)
|
||||
|
||||
if actual[0].CreatedTime != 1676898844 || actual[2].CreatedTime != 1676899026 {
|
||||
if actual.Data[0].CreatedTime != 1676898844 || actual.Data[2].CreatedTime != 1676899026 {
|
||||
t.Fatal("expected ascending order, found descending")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,26 @@ import (
|
||||
|
||||
// Request struct for get list of VINSes
|
||||
type ListRequest struct {
|
||||
// Find by ID
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by account ID
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// Find by resource group id
|
||||
// Required: false
|
||||
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
||||
|
||||
// Find by external network IP
|
||||
// Required: false
|
||||
ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"`
|
||||
|
||||
// Include deleted
|
||||
// Required: false
|
||||
IncludeDeleted bool `url:"includeDeleted,omitempty" json:"includeDeleted,omitempty"`
|
||||
@@ -22,7 +42,7 @@ type ListRequest struct {
|
||||
}
|
||||
|
||||
// List gets list of VINSes available for current user
|
||||
func (v VINS) List(ctx context.Context, req ListRequest) (ListVINS, error) {
|
||||
func (v VINS) List(ctx context.Context, req ListRequest) (*ListVINS, error) {
|
||||
url := "/cloudapi/vins/list"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -37,5 +57,5 @@ func (v VINS) List(ctx context.Context, req ListRequest) (ListVINS, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ type ListDeletedRequest struct {
|
||||
}
|
||||
|
||||
// ListDeleted gets list of deleted VINSes available for current user
|
||||
func (v VINS) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListVINS, error) {
|
||||
func (v VINS) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListVINS, error) {
|
||||
url := "/cloudapi/vins/listDeleted"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -33,5 +33,5 @@ func (v VINS) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListVINS
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -52,7 +52,14 @@ type ItemVINS struct {
|
||||
}
|
||||
|
||||
// List of VINSes
|
||||
type ListVINS []ItemVINS
|
||||
type ListVINS struct {
|
||||
Data []ItemVINS `json:"data"`
|
||||
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// List of VINSes search result
|
||||
type SearchListVINS []ItemVINS
|
||||
|
||||
// Main information about audit
|
||||
type ItemAudit struct {
|
||||
@@ -620,6 +627,12 @@ type RecordVINS struct {
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// User managed
|
||||
UserManaged bool `json:"userManaged"`
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ type SearchRequest struct {
|
||||
}
|
||||
|
||||
// Search search VINSes
|
||||
func (v VINS) Search(ctx context.Context, req SearchRequest) (ListVINS, error) {
|
||||
func (v VINS) Search(ctx context.Context, req SearchRequest) (SearchListVINS, error) {
|
||||
url := "/cloudapi/vins/search"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -34,7 +34,7 @@ func (v VINS) Search(ctx context.Context, req SearchRequest) (ListVINS, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListVINS{}
|
||||
list := SearchListVINS{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lv ListVINS) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lv) == 0 {
|
||||
if len(lv.Data) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -6,16 +6,16 @@ import "sort"
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lv ListVINS) SortByCreatedTime(inverse bool) ListVINS {
|
||||
if len(lv) < 2 {
|
||||
if len(lv.Data) < 2 {
|
||||
return lv
|
||||
}
|
||||
|
||||
sort.Slice(lv, func(i, j int) bool {
|
||||
sort.Slice(lv.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lv[i].CreatedTime > lv[j].CreatedTime
|
||||
return lv.Data[i].CreatedTime > lv.Data[j].CreatedTime
|
||||
}
|
||||
|
||||
return lv[i].CreatedTime < lv[j].CreatedTime
|
||||
return lv.Data[i].CreatedTime < lv.Data[j].CreatedTime
|
||||
})
|
||||
|
||||
return lv
|
||||
@@ -25,16 +25,16 @@ func (lv ListVINS) SortByCreatedTime(inverse bool) ListVINS {
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lv ListVINS) SortByUpdatedTime(inverse bool) ListVINS {
|
||||
if len(lv) < 2 {
|
||||
if len(lv.Data) < 2 {
|
||||
return lv
|
||||
}
|
||||
|
||||
sort.Slice(lv, func(i, j int) bool {
|
||||
sort.Slice(lv.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lv[i].UpdatedTime > lv[j].UpdatedTime
|
||||
return lv.Data[i].UpdatedTime > lv.Data[j].UpdatedTime
|
||||
}
|
||||
|
||||
return lv[i].UpdatedTime < lv[j].UpdatedTime
|
||||
return lv.Data[i].UpdatedTime < lv.Data[j].UpdatedTime
|
||||
})
|
||||
|
||||
return lv
|
||||
@@ -44,16 +44,16 @@ func (lv ListVINS) SortByUpdatedTime(inverse bool) ListVINS {
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lv ListVINS) SortByDeletedTime(inverse bool) ListVINS {
|
||||
if len(lv) < 2 {
|
||||
if len(lv.Data) < 2 {
|
||||
return lv
|
||||
}
|
||||
|
||||
sort.Slice(lv, func(i, j int) bool {
|
||||
sort.Slice(lv.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lv[i].DeletedTime > lv[j].DeletedTime
|
||||
return lv.Data[i].DeletedTime > lv.Data[j].DeletedTime
|
||||
}
|
||||
|
||||
return lv[i].DeletedTime < lv[j].DeletedTime
|
||||
return lv.Data[i].DeletedTime < lv.Data[j].DeletedTime
|
||||
})
|
||||
|
||||
return lv
|
||||
|
||||
Reference in New Issue
Block a user