implement remote call for remote action

This commit is contained in:
mr 2024-08-12 16:28:02 +02:00
parent f4603e4171
commit e51377eeb3

View File

@ -18,6 +18,7 @@ import (
"cloud.o-forge.io/core/oc-lib/models/workspace"
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/tools"
"github.com/rs/zerolog"
)
@ -96,59 +97,87 @@ func GetLogger() zerolog.Logger {
return logs.GetLogger()
}
func Search(filters *dbs.Filters, word string, collection LibDataEnum) LibDataShallow {
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(nil).Search(filters, word)
func Search(filters *dbs.Filters, word string, collection LibDataEnum, c ...*tools.HTTPCaller) LibDataShallow {
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 {
return LibDataShallow{Data: d, Code: code, Err: err.Error()}
}
return LibDataShallow{Data: d, Code: code}
}
func LoadAll(collection LibDataEnum) LibDataShallow {
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(nil).LoadAll()
func LoadAll(collection LibDataEnum, c ...*tools.HTTPCaller) LibDataShallow {
var caller *tools.HTTPCaller
if len(c) > 0 {
caller = c[0]
}
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(caller).LoadAll()
if err != nil {
return LibDataShallow{Data: d, Code: code, Err: err.Error()}
}
return LibDataShallow{Data: d, Code: code}
}
func LoadOne(collection LibDataEnum, id string) LibData {
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(nil).LoadOne(id)
func LoadOne(collection LibDataEnum, id string, c ...*tools.HTTPCaller) LibData {
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 {
return LibData{Data: d, Code: code, Err: err.Error()}
}
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())
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 {
return LibData{Data: d, Code: code, Err: err.Error()}
}
return LibData{Data: d, Code: code}
}
func DeleteOne(collection LibDataEnum, id string) LibData {
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(nil).DeleteOne(id)
func DeleteOne(collection LibDataEnum, id string, c ...*tools.HTTPCaller) LibData {
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 {
return LibData{Data: d, Code: code, Err: err.Error()}
}
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())
d, code, err := model.GetAccessor(nil).StoreOne(model.Deserialize(object))
d, code, err := model.GetAccessor(caller).StoreOne(model.Deserialize(object))
if err != nil {
return LibData{Data: d, Code: code, Err: err.Error()}
}
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())
d, code, err := model.GetAccessor(nil).CopyOne(model.Deserialize(object))
d, code, err := model.GetAccessor(caller).CopyOne(model.Deserialize(object))
if err != nil {
return LibData{Data: d, Code: code, Err: err.Error()}
}