implement remote call for remote action
This commit is contained in:
parent
f4603e4171
commit
e51377eeb3
@ -18,6 +18,7 @@ import (
|
|||||||
"cloud.o-forge.io/core/oc-lib/models/workspace"
|
"cloud.o-forge.io/core/oc-lib/models/workspace"
|
||||||
shared_workspace "cloud.o-forge.io/core/oc-lib/models/workspace/shared"
|
shared_workspace "cloud.o-forge.io/core/oc-lib/models/workspace/shared"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/workspace/shared/rules/rule"
|
"cloud.o-forge.io/core/oc-lib/models/workspace/shared/rules/rule"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -96,59 +97,87 @@ func GetLogger() zerolog.Logger {
|
|||||||
return logs.GetLogger()
|
return logs.GetLogger()
|
||||||
}
|
}
|
||||||
|
|
||||||
func Search(filters *dbs.Filters, word string, collection LibDataEnum) LibDataShallow {
|
func Search(filters *dbs.Filters, word string, collection LibDataEnum, c ...*tools.HTTPCaller) LibDataShallow {
|
||||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(nil).Search(filters, word)
|
var caller *tools.HTTPCaller
|
||||||
|
if len(c) > 0 {
|
||||||
|
caller = c[0]
|
||||||
|
}
|
||||||
|
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(caller).Search(filters, word)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return LibDataShallow{Data: d, Code: code, Err: err.Error()}
|
return LibDataShallow{Data: d, Code: code, Err: err.Error()}
|
||||||
}
|
}
|
||||||
return LibDataShallow{Data: d, Code: code}
|
return LibDataShallow{Data: d, Code: code}
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadAll(collection LibDataEnum) LibDataShallow {
|
func LoadAll(collection LibDataEnum, c ...*tools.HTTPCaller) LibDataShallow {
|
||||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(nil).LoadAll()
|
var caller *tools.HTTPCaller
|
||||||
|
if len(c) > 0 {
|
||||||
|
caller = c[0]
|
||||||
|
}
|
||||||
|
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(caller).LoadAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return LibDataShallow{Data: d, Code: code, Err: err.Error()}
|
return LibDataShallow{Data: d, Code: code, Err: err.Error()}
|
||||||
}
|
}
|
||||||
return LibDataShallow{Data: d, Code: code}
|
return LibDataShallow{Data: d, Code: code}
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadOne(collection LibDataEnum, id string) LibData {
|
func LoadOne(collection LibDataEnum, id string, c ...*tools.HTTPCaller) LibData {
|
||||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(nil).LoadOne(id)
|
var caller *tools.HTTPCaller
|
||||||
|
if len(c) > 0 {
|
||||||
|
caller = c[0]
|
||||||
|
}
|
||||||
|
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(caller).LoadOne(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return LibData{Data: d, Code: code, Err: err.Error()}
|
return LibData{Data: d, Code: code, Err: err.Error()}
|
||||||
}
|
}
|
||||||
return LibData{Data: d, Code: code}
|
return LibData{Data: d, Code: code}
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateOne(collection LibDataEnum, set map[string]interface{}, id string) LibData {
|
func UpdateOne(collection LibDataEnum, set map[string]interface{}, id string, c ...*tools.HTTPCaller) LibData {
|
||||||
|
var caller *tools.HTTPCaller
|
||||||
|
if len(c) > 0 {
|
||||||
|
caller = c[0]
|
||||||
|
}
|
||||||
model := models.Model(collection.EnumIndex())
|
model := models.Model(collection.EnumIndex())
|
||||||
d, code, err := model.GetAccessor(nil).UpdateOne(model.Deserialize(set), id)
|
d, code, err := model.GetAccessor(caller).UpdateOne(model.Deserialize(set), id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return LibData{Data: d, Code: code, Err: err.Error()}
|
return LibData{Data: d, Code: code, Err: err.Error()}
|
||||||
}
|
}
|
||||||
return LibData{Data: d, Code: code}
|
return LibData{Data: d, Code: code}
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteOne(collection LibDataEnum, id string) LibData {
|
func DeleteOne(collection LibDataEnum, id string, c ...*tools.HTTPCaller) LibData {
|
||||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(nil).DeleteOne(id)
|
var caller *tools.HTTPCaller
|
||||||
|
if len(c) > 0 {
|
||||||
|
caller = c[0]
|
||||||
|
}
|
||||||
|
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(caller).DeleteOne(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return LibData{Data: d, Code: code, Err: err.Error()}
|
return LibData{Data: d, Code: code, Err: err.Error()}
|
||||||
}
|
}
|
||||||
return LibData{Data: d, Code: code}
|
return LibData{Data: d, Code: code}
|
||||||
}
|
}
|
||||||
|
|
||||||
func StoreOne(collection LibDataEnum, object map[string]interface{}) LibData {
|
func StoreOne(collection LibDataEnum, object map[string]interface{}, c ...*tools.HTTPCaller) LibData {
|
||||||
|
var caller *tools.HTTPCaller
|
||||||
|
if len(c) > 0 {
|
||||||
|
caller = c[0]
|
||||||
|
}
|
||||||
model := models.Model(collection.EnumIndex())
|
model := models.Model(collection.EnumIndex())
|
||||||
d, code, err := model.GetAccessor(nil).StoreOne(model.Deserialize(object))
|
d, code, err := model.GetAccessor(caller).StoreOne(model.Deserialize(object))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return LibData{Data: d, Code: code, Err: err.Error()}
|
return LibData{Data: d, Code: code, Err: err.Error()}
|
||||||
}
|
}
|
||||||
return LibData{Data: d, Code: code}
|
return LibData{Data: d, Code: code}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CopyOne(collection LibDataEnum, object map[string]interface{}) LibData {
|
func CopyOne(collection LibDataEnum, object map[string]interface{}, c ...*tools.HTTPCaller) LibData {
|
||||||
|
var caller *tools.HTTPCaller
|
||||||
|
if len(c) > 0 {
|
||||||
|
caller = c[0]
|
||||||
|
}
|
||||||
model := models.Model(collection.EnumIndex())
|
model := models.Model(collection.EnumIndex())
|
||||||
d, code, err := model.GetAccessor(nil).CopyOne(model.Deserialize(object))
|
d, code, err := model.GetAccessor(caller).CopyOne(model.Deserialize(object))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return LibData{Data: d, Code: code, Err: err.Error()}
|
return LibData{Data: d, Code: code, Err: err.Error()}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user