This commit is contained in:
2023-03-14 14:45:51 +03:00
parent 42800ac4fe
commit f3a1a4c83f
202 changed files with 6199 additions and 155 deletions

View File

@@ -6,7 +6,7 @@ import (
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for grant access to resource group

View File

@@ -0,0 +1,87 @@
package rg
// FilterByID returns ListRG with specified ID.
func (lrg ListRG) FilterByID(id uint64) ListRG {
predicate := func(irg ItemRG) bool {
return irg.ID == id
}
return lrg.FilterFunc(predicate)
}
// FilterByName returns ListRG with specified Name.
func (lrg ListRG) FilterByName(name string) ListRG {
predicate := func(irg ItemRG) bool {
return irg.Name == name
}
return lrg.FilterFunc(predicate)
}
// FilterByCreatedBy return ListRG created by specified user.
func (lrg ListRG) FilterByCreatedBy(createdBy string) ListRG {
predicate := func(irg ItemRG) bool {
return irg.CreatedBy == createdBy
}
return lrg.FilterFunc(predicate)
}
// FilterByStatus returns ListRG with specified Status.
func (lrg ListRG) FilterByStatus(status string) ListRG {
predicate := func(irg ItemRG) bool {
return irg.Status == status
}
return lrg.FilterFunc(predicate)
}
// FilterByLockStatus return ListRG with specified LockStatus.
func (lrg ListRG) FilterByLockStatus(lockStatus string) ListRG {
predicate := func(irg ItemRG) bool {
return irg.LockStatus == lockStatus
}
return lrg.FilterFunc(predicate)
}
// FilterByDefNetType returns ListRG with specified DefNetType.
func (lrg ListRG) FilterByDefNetType(defNetType string) ListRG {
predicate := func(irg ItemRG) bool {
return irg.DefNetType == defNetType
}
return lrg.FilterFunc(predicate)
}
// FilterByDefNetID returns ListRG with specified DefNetID.
func (lrg ListRG) FilterByDefNetID(defNetID int64) ListRG {
predicate := func(irg ItemRG) bool {
return irg.DefNetID == defNetID
}
return lrg.FilterFunc(predicate)
}
// FilterFunc allows filtering ListRG based on a user-specified predicate.
func (lrg ListRG) FilterFunc(predicate func(ItemRG) bool) ListRG {
var result ListRG
for _, item := range lrg {
if predicate(item) {
result = append(result, item)
}
}
return result
}
// FindOne returns first found ItemRG.
// If none was found, returns an empty struct.
func (lrg ListRG) FindOne() ItemRG {
if len(lrg) == 0 {
return ItemRG{}
}
return lrg[0]
}

View File

@@ -138,7 +138,7 @@ type ItemRG struct {
CreatedTime uint64 `json:"createdTime"`
// DefNet ID
DefNetID uint64 `json:"def_net_id"`
DefNetID int64 `json:"def_net_id"`
// DefNet type
DefNetType string `json:"def_net_type"`

View File

@@ -2,7 +2,7 @@
package rg
import (
"github.com/rudecs/decort-sdk/interfaces"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
)
// Structure for creating request to resource group

View File

@@ -0,0 +1,43 @@
package rg
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 (lrg ListRG) Serialize(params ...string) (serialization.Serialized, error) {
if len(lrg) == 0 {
return []byte{}, nil
}
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(lrg, prefix, indent)
}
return json.Marshal(lrg)
}
// 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 (irg ItemRG) Serialize(params ...string) (serialization.Serialized, error) {
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(irg, prefix, indent)
}
return json.Marshal(irg)
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for set default network

View File

@@ -0,0 +1,60 @@
package rg
import "sort"
// SortByCreatedTime sorts ListRG by the CreatedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lrg ListRG) SortByCreatedTime(inverse bool) ListRG {
if len(lrg) < 2 {
return lrg
}
sort.Slice(lrg, func(i, j int) bool {
if inverse {
return lrg[i].CreatedTime > lrg[j].CreatedTime
}
return lrg[i].CreatedTime < lrg[j].CreatedTime
})
return lrg
}
// SortByUpdatedTime sorts ListRG by the UpdatedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lrg ListRG) SortByUpdatedTime(inverse bool) ListRG {
if len(lrg) < 2 {
return lrg
}
sort.Slice(lrg, func(i, j int) bool {
if inverse {
return lrg[i].UpdatedTime > lrg[j].UpdatedTime
}
return lrg[i].UpdatedTime < lrg[j].UpdatedTime
})
return lrg
}
// SortByDeletedTime sorts ListRG by the DeletedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lrg ListRG) SortByDeletedTime(inverse bool) ListRG {
if len(lrg) < 2 {
return lrg
}
sort.Slice(lrg, func(i, j int) bool {
if inverse {
return lrg[i].DeletedTime > lrg[j].DeletedTime
}
return lrg[i].DeletedTime < lrg[j].DeletedTime
})
return lrg
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for update resource types in account