v1.2.1
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create FLIPGroup
|
||||
|
||||
96
pkg/cloudapi/flipgroup/filter.go
Normal file
96
pkg/cloudapi/flipgroup/filter.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package flipgroup
|
||||
|
||||
// FilterByID returns ListFLIPGroups with specified ID.
|
||||
func (lfg ListFLIPGroups) FilterByID(id uint64) ListFLIPGroups {
|
||||
predicate := func(ifg ItemFLIPGroup) bool {
|
||||
return ifg.ID == id
|
||||
}
|
||||
|
||||
return lfg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByAccountID returns ListFLIPGroups with specified AccountID.
|
||||
func (lfg ListFLIPGroups) FilterByAccountID(accountID uint64) ListFLIPGroups {
|
||||
predicate := func(ifg ItemFLIPGroup) bool {
|
||||
return ifg.AccountID == accountID
|
||||
}
|
||||
|
||||
return lfg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByRGID returns ListFLIPGroups with specified RGID.
|
||||
func (lfg ListFLIPGroups) FilterByRGID(rgID uint64) ListFLIPGroups {
|
||||
predicate := func(ifg ItemFLIPGroup) bool {
|
||||
return ifg.RGID == rgID
|
||||
}
|
||||
|
||||
return lfg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListFLIPGroups with specified Name.
|
||||
func (lfg ListFLIPGroups) FilterByName(name string) ListFLIPGroups {
|
||||
predicate := func(ifg ItemFLIPGroup) bool {
|
||||
return ifg.Name == name
|
||||
}
|
||||
|
||||
return lfg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListFLIPGroups with specified Status.
|
||||
func (lfg ListFLIPGroups) FilterByStatus(status string) ListFLIPGroups {
|
||||
predicate := func(ifg ItemFLIPGroup) bool {
|
||||
return ifg.Status == status
|
||||
}
|
||||
|
||||
return lfg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByCreatedBy returns ListFLIPGroups created by specified user.
|
||||
func (lfg ListFLIPGroups) FilterByCreatedBy(createdBy string) ListFLIPGroups {
|
||||
predicate := func(ifg ItemFLIPGroup) bool {
|
||||
return ifg.CreatedBy == createdBy
|
||||
}
|
||||
|
||||
return lfg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByUpdatedBy returns ListFLIPGroups updated by specified user.
|
||||
func (lfg ListFLIPGroups) FilterByUpdatedBy(updatedBy string) ListFLIPGroups {
|
||||
predicate := func(ifg ItemFLIPGroup) bool {
|
||||
return ifg.UpdatedBy == updatedBy
|
||||
}
|
||||
|
||||
return lfg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByDeletedBy returns ListFLIPGroups deleted by specified user.
|
||||
func (lfg ListFLIPGroups) FilterByDeletedBy(deletedBy string) ListFLIPGroups {
|
||||
predicate := func(ifg ItemFLIPGroup) bool {
|
||||
return ifg.DeletedBy == deletedBy
|
||||
}
|
||||
|
||||
return lfg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListFLIPGroups based on a user-specified predicate.
|
||||
func (lfg ListFLIPGroups) FilterFunc(predicate func(ItemFLIPGroup) bool) ListFLIPGroups {
|
||||
var result ListFLIPGroups
|
||||
|
||||
for _, item := range lfg {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemFLIPGroup
|
||||
// If none was found, returns an empty struct.
|
||||
func (lfg ListFLIPGroups) FindOne() ItemFLIPGroup {
|
||||
if len(lfg) == 0 {
|
||||
return ItemFLIPGroup{}
|
||||
}
|
||||
|
||||
return lfg[0]
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
package flipgroup
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to FLIPGroup
|
||||
|
||||
43
pkg/cloudapi/flipgroup/serialize.go
Normal file
43
pkg/cloudapi/flipgroup/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package flipgroup
|
||||
|
||||
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 (lfg ListFLIPGroups) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lfg) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(lfg, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(lfg)
|
||||
}
|
||||
|
||||
// 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 (ifg ItemFLIPGroup) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ifg, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ifg)
|
||||
}
|
||||
60
pkg/cloudapi/flipgroup/sorting.go
Normal file
60
pkg/cloudapi/flipgroup/sorting.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package flipgroup
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedTime sorts ListFLIPGroups by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lfg ListFLIPGroups) SortByCreatedTime(inverse bool) ListFLIPGroups {
|
||||
if len(lfg) < 2 {
|
||||
return lfg
|
||||
}
|
||||
|
||||
sort.Slice(lfg, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lfg[i].CreatedTime > lfg[j].CreatedTime
|
||||
}
|
||||
|
||||
return lfg[i].CreatedTime < lfg[j].CreatedTime
|
||||
})
|
||||
|
||||
return lfg
|
||||
}
|
||||
|
||||
// SortByUpdatedTime sorts ListFLIPGroups by the UpdatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lfg ListFLIPGroups) SortByUpdatedTime(inverse bool) ListFLIPGroups {
|
||||
if len(lfg) < 2 {
|
||||
return lfg
|
||||
}
|
||||
|
||||
sort.Slice(lfg, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lfg[i].UpdatedTime > lfg[j].UpdatedTime
|
||||
}
|
||||
|
||||
return lfg[i].UpdatedTime < lfg[j].UpdatedTime
|
||||
})
|
||||
|
||||
return lfg
|
||||
}
|
||||
|
||||
// SortByDeletedTime sorts ListFLIPGroups by the DeletedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lfg ListFLIPGroups) SortByDeletedTime(inverse bool) ListFLIPGroups {
|
||||
if len(lfg) < 2 {
|
||||
return lfg
|
||||
}
|
||||
|
||||
sort.Slice(lfg, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lfg[i].DeletedTime > lfg[j].DeletedTime
|
||||
}
|
||||
|
||||
return lfg[i].DeletedTime < lfg[j].DeletedTime
|
||||
})
|
||||
|
||||
return lfg
|
||||
}
|
||||
Reference in New Issue
Block a user