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

@@ -0,0 +1,51 @@
package grid
// FilterByID returns ListGrids with specified ID.
func (lg ListGrids) FilterByID(id uint64) ListGrids {
predicate := func(rg RecordGrid) bool {
return rg.ID == id
}
return lg.FilterFunc(predicate)
}
// FilterByName returns ListGrids with specified Name.
func (lg ListGrids) FilterByName(name string) ListGrids {
predicate := func(rg RecordGrid) bool {
return rg.Name == name
}
return lg.FilterFunc(predicate)
}
// FilterByLocationCode returns ListGrids with specified LocationCode.
func (lg ListGrids) FilterByLocationCode(locationCode string) ListGrids {
predicate := func(rg RecordGrid) bool {
return rg.LocationCode == locationCode
}
return lg.FilterFunc(predicate)
}
// FilterFunc allows filtering ListGrids based on a user-specified predicate.
func (lg ListGrids) FilterFunc(predicate func(RecordGrid) bool) ListGrids {
var result ListGrids
for _, item := range lg {
if predicate(item) {
result = append(result, item)
}
}
return result
}
// FindOne returns first found RecordGrid.
// If none was found, returns an empty struct.
func (lg ListGrids) FindOne() RecordGrid {
if len(lg) == 0 {
return RecordGrid{}
}
return lg[0]
}

View File

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

View File

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