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,42 @@
package locations
// FilterByID returns ListLocations with specified ID.
func (ll ListLocations) FilterByID(id uint64) ListLocations {
predicate := func(il ItemLocation) bool {
return il.ID == id
}
return ll.FilterFunc(predicate)
}
// FilterByName returns ListLocations with specified Name.
func (ll ListLocations) FilterByName(name string) ListLocations {
predicate := func(il ItemLocation) bool {
return il.Name == name
}
return ll.FilterFunc(predicate)
}
// FilterFunc allows filtering ListLocations based on a user-specified predicate.
func (ll ListLocations) FilterFunc(predicate func(ItemLocation) bool) ListLocations {
var result ListLocations
for _, item := range ll {
if predicate(item) {
result = append(result, item)
}
}
return result
}
// FindOne returns first found ItemLocation
// If none was found, returns an empty struct.
func (ll ListLocations) FindOne() ItemLocation {
if len(ll) == 0 {
return ItemLocation{}
}
return ll[0]
}

View File

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

View File

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