v1.2.1
This commit is contained in:
78
pkg/cloudapi/vins/filter.go
Normal file
78
pkg/cloudapi/vins/filter.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package vins
|
||||
|
||||
// FilterByID returns ListVINS with specified ID.
|
||||
func (lv ListVINS) FilterByID(id uint64) ListVINS {
|
||||
predicate := func(iv ItemVINS) bool {
|
||||
return iv.ID == id
|
||||
}
|
||||
|
||||
return lv.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListVINS with specified Name.
|
||||
func (lv ListVINS) FilterByName(name string) ListVINS {
|
||||
predicate := func(iv ItemVINS) bool {
|
||||
return iv.Name == name
|
||||
}
|
||||
|
||||
return lv.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByAccountID returns ListVINS with specified AccountID.
|
||||
func (lv ListVINS) FilterByAccountID(accountID uint64) ListVINS {
|
||||
predicate := func(iv ItemVINS) bool {
|
||||
return iv.AccountID == accountID
|
||||
}
|
||||
|
||||
return lv.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByCreatedBy returns ListVINS created by specified user.
|
||||
func (lv ListVINS) FilterByCreatedBy(createdBy string) ListVINS {
|
||||
predicate := func(iv ItemVINS) bool {
|
||||
return iv.CreatedBy == createdBy
|
||||
}
|
||||
|
||||
return lv.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByUpdatedBy returns ListVINS updated by specified user.
|
||||
func (lv ListVINS) FilterByUpdatedBy(updatedBy string) ListVINS {
|
||||
predicate := func(iv ItemVINS) bool {
|
||||
return iv.UpdatedBy == updatedBy
|
||||
}
|
||||
|
||||
return lv.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByDeletedBy returns ListVINS deleted by specified user.
|
||||
func (lv ListVINS) FilterByDeletedBy(deletedBy string) ListVINS {
|
||||
predicate := func(iv ItemVINS) bool {
|
||||
return iv.DeletedBy == deletedBy
|
||||
}
|
||||
|
||||
return lv.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListVINS based on a user-specified predicate.
|
||||
func (lv ListVINS) FilterFunc(predicate func(ItemVINS) bool) ListVINS {
|
||||
var result ListVINS
|
||||
|
||||
for _, item := range lv {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemVINS
|
||||
// If none was found, returns an empty struct.
|
||||
func (lv ListVINS) FindOne() ItemVINS {
|
||||
if len(lv) == 0 {
|
||||
return ItemVINS{}
|
||||
}
|
||||
|
||||
return lv[0]
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for IP reserve
|
||||
|
||||
43
pkg/cloudapi/vins/serialize.go
Normal file
43
pkg/cloudapi/vins/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lv ListVINS) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lv) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(lv, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(lv)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (iv ItemVINS) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(iv, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(iv)
|
||||
}
|
||||
60
pkg/cloudapi/vins/sorting.go
Normal file
60
pkg/cloudapi/vins/sorting.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package vins
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedTime sorts ListVINS by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lv ListVINS) SortByCreatedTime(inverse bool) ListVINS {
|
||||
if len(lv) < 2 {
|
||||
return lv
|
||||
}
|
||||
|
||||
sort.Slice(lv, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lv[i].CreatedTime > lv[j].CreatedTime
|
||||
}
|
||||
|
||||
return lv[i].CreatedTime < lv[j].CreatedTime
|
||||
})
|
||||
|
||||
return lv
|
||||
}
|
||||
|
||||
// SortByUpdatedTime sorts ListVINS by the UpdatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lv ListVINS) SortByUpdatedTime(inverse bool) ListVINS {
|
||||
if len(lv) < 2 {
|
||||
return lv
|
||||
}
|
||||
|
||||
sort.Slice(lv, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lv[i].UpdatedTime > lv[j].UpdatedTime
|
||||
}
|
||||
|
||||
return lv[i].UpdatedTime < lv[j].UpdatedTime
|
||||
})
|
||||
|
||||
return lv
|
||||
}
|
||||
|
||||
// SortByDeletedTime sorts ListVINS by the DeletedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lv ListVINS) SortByDeletedTime(inverse bool) ListVINS {
|
||||
if len(lv) < 2 {
|
||||
return lv
|
||||
}
|
||||
|
||||
sort.Slice(lv, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lv[i].DeletedTime > lv[j].DeletedTime
|
||||
}
|
||||
|
||||
return lv[i].DeletedTime < lv[j].DeletedTime
|
||||
})
|
||||
|
||||
return lv
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to VINS
|
||||
|
||||
Reference in New Issue
Block a user