From d6a2a416c1ce48891742174ac89a570f542e666b Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 31 Jul 2024 09:52:57 +0200 Subject: [PATCH] debug automation workspace --- models/workspace/workspace_mongo_accessor.go | 28 +++++++++++--------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/models/workspace/workspace_mongo_accessor.go b/models/workspace/workspace_mongo_accessor.go index 8778f84..6a4932d 100644 --- a/models/workspace/workspace_mongo_accessor.go +++ b/models/workspace/workspace_mongo_accessor.go @@ -53,15 +53,7 @@ func (wfa *WorkspaceMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, return wfa.GenericStoreOne(data, wfa) } -func (wfa *WorkspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) { - var workflow Workspace - res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType()) - if err != nil { - wfa.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error()) - return nil, code, err - } - res_mongo.Decode(&workflow) - +func (wfa *WorkspaceMongoAccessor) fill(workflow *Workspace) *Workspace { if workflow.Datas != nil && len(workflow.Datas) > 0 { dataAccessor := (&data.DataResource{}).GetAccessor() for _, id := range workflow.Datas { @@ -107,7 +99,19 @@ func (wfa *WorkspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, erro } } } - return &workflow, 200, nil + return workflow +} + +func (wfa *WorkspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) { + var workflow Workspace + res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType()) + if err != nil { + wfa.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error()) + return nil, code, err + } + res_mongo.Decode(&workflow) + + return wfa.fill(&workflow), 200, nil } func (wfa WorkspaceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) { @@ -122,7 +126,7 @@ func (wfa WorkspaceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error return nil, 404, err } for _, r := range results { - objs = append(objs, &r) + objs = append(objs, wfa.fill(&r)) } return objs, 200, nil } @@ -139,7 +143,7 @@ func (wfa *WorkspaceMongoAccessor) Search(word string) ([]utils.ShallowDBObject, return nil, 404, err } for _, r := range results { - objs = append(objs, &r) + objs = append(objs, wfa.fill(&r)) } return objs, 200, nil }