From bde70dec9b57431c59c759323cc65701475b2775 Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 24 Jul 2024 08:35:41 +0200 Subject: [PATCH] Debugging Put / GET ALL --- models/resources/data/data_mongo_accessor.go | 10 ++++++---- .../resources/datacenter/datacenter_mongo_accessor.go | 10 ++++++---- .../resources/processing/processing_mongo_accessor.go | 10 ++++++---- models/resources/storage/storage_mongo_accessor.go | 10 ++++++---- models/resources/workflow/workflow_mongo_accessor.go | 10 ++++++---- models/utils/abstracts.go | 5 ++++- models/workflow/workflow_mongo_accessor.go | 10 ++++++---- .../workflow_execution_mongo_accessor.go | 10 ++++++---- 8 files changed, 46 insertions(+), 29 deletions(-) diff --git a/models/resources/data/data_mongo_accessor.go b/models/resources/data/data_mongo_accessor.go index 59f8da9..b670bdb 100644 --- a/models/resources/data/data_mongo_accessor.go +++ b/models/resources/data/data_mongo_accessor.go @@ -44,10 +44,12 @@ func (wfa DataMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) { wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error()) return nil, code, err } - for res_mongo.Next(mongo.MngoCtx) { - var obj DataResource - res_mongo.Decode(&obj) - objs = append(objs, &obj.AbstractResource) + var results []DataResource + if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { + return nil, 404, err + } + for _, r := range results { + objs = append(objs, &r.AbstractResource) } return objs, 200, nil } diff --git a/models/resources/datacenter/datacenter_mongo_accessor.go b/models/resources/datacenter/datacenter_mongo_accessor.go index 452e542..f500e0b 100644 --- a/models/resources/datacenter/datacenter_mongo_accessor.go +++ b/models/resources/datacenter/datacenter_mongo_accessor.go @@ -46,10 +46,12 @@ func (wfa DatacenterMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, erro wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error()) return nil, code, err } - for res_mongo.Next(mongo.MngoCtx) { - var obj DatacenterResource - res_mongo.Decode(&obj) - objs = append(objs, &obj.AbstractResource) + var results []DatacenterResource + if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { + return nil, 404, err + } + for _, r := range results { + objs = append(objs, &r.AbstractResource) } return objs, 200, nil } diff --git a/models/resources/processing/processing_mongo_accessor.go b/models/resources/processing/processing_mongo_accessor.go index 9f7c44a..c0efa0a 100644 --- a/models/resources/processing/processing_mongo_accessor.go +++ b/models/resources/processing/processing_mongo_accessor.go @@ -47,10 +47,12 @@ func (wfa ProcessingMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, erro wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error()) return nil, code, err } - for res_mongo.Next(mongo.MngoCtx) { - var obj ProcessingResource - res_mongo.Decode(&obj) - objs = append(objs, &obj.AbstractResource) + var results []ProcessingResource + if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { + return nil, 404, err + } + for _, r := range results { + objs = append(objs, &r.AbstractResource) } return objs, 200, nil } diff --git a/models/resources/storage/storage_mongo_accessor.go b/models/resources/storage/storage_mongo_accessor.go index a42d410..7cbe404 100644 --- a/models/resources/storage/storage_mongo_accessor.go +++ b/models/resources/storage/storage_mongo_accessor.go @@ -47,10 +47,12 @@ func (wfa StorageMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error()) return nil, code, err } - for res_mongo.Next(mongo.MngoCtx) { - var obj StorageResource - res_mongo.Decode(&obj) - objs = append(objs, &obj.AbstractResource) + var results []StorageResource + if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { + return nil, 404, err + } + for _, r := range results { + objs = append(objs, &r.AbstractResource) } return objs, 200, nil } diff --git a/models/resources/workflow/workflow_mongo_accessor.go b/models/resources/workflow/workflow_mongo_accessor.go index 2f6c364..3b5239f 100644 --- a/models/resources/workflow/workflow_mongo_accessor.go +++ b/models/resources/workflow/workflow_mongo_accessor.go @@ -50,10 +50,12 @@ func (wfa WorkflowResourceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error()) return nil, code, err } - for res_mongo.Next(mongo.MngoCtx) { - var obj WorkflowResource - res_mongo.Decode(&obj) - objs = append(objs, &obj.AbstractResource) + var results []WorkflowResource + if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { + return nil, 404, err + } + for _, r := range results { + objs = append(objs, &r.AbstractResource) } return objs, 200, nil } diff --git a/models/utils/abstracts.go b/models/utils/abstracts.go index 31d416e..62792f7 100644 --- a/models/utils/abstracts.go +++ b/models/utils/abstracts.go @@ -1,6 +1,8 @@ package utils import ( + "fmt" + "cloud.o-forge.io/core/oc-lib/dbs/mongo" "cloud.o-forge.io/core/oc-lib/logs" "github.com/go-playground/validator/v10" @@ -79,7 +81,8 @@ func (dma *AbstractAccessor) GenericUpdateOne(set DBObject, id string, accessor for k, v := range changeMap { original[k] = v } - id, code, err := mongo.MONGOService.UpdateOne(set.Deserialize(original), id, accessor.GetType()) + fmt.Println(original) + id, code, err := mongo.MONGOService.UpdateOne(r.Deserialize(original), id, accessor.GetType()) if err != nil { dma.Logger.Error().Msg("Could not update " + id + " to db. Error: " + err.Error()) return nil, code, err diff --git a/models/workflow/workflow_mongo_accessor.go b/models/workflow/workflow_mongo_accessor.go index 71f3576..8ca39aa 100644 --- a/models/workflow/workflow_mongo_accessor.go +++ b/models/workflow/workflow_mongo_accessor.go @@ -99,10 +99,12 @@ func (wfa WorkflowMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error()) return nil, code, err } - for res_mongo.Next(mongo.MngoCtx) { - var obj Workflow - res_mongo.Decode(&obj) - objs = append(objs, &obj.AbstractObject) + var results []Workflow + if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { + return nil, 404, err + } + for _, r := range results { + objs = append(objs, &r.AbstractObject) } return objs, 200, nil } diff --git a/models/workflow_execution/workflow_execution_mongo_accessor.go b/models/workflow_execution/workflow_execution_mongo_accessor.go index 7edb8ee..09fc142 100644 --- a/models/workflow_execution/workflow_execution_mongo_accessor.go +++ b/models/workflow_execution/workflow_execution_mongo_accessor.go @@ -43,10 +43,12 @@ func (wfa WorkflowExecutionMongoAccessor) LoadAll() ([]utils.ShallowDBObject, in wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error()) return nil, code, err } - for res_mongo.Next(mongo.MngoCtx) { - var obj utils.AbstractObject - res_mongo.Decode(&obj) - objs = append(objs, &obj) + var results []WorkflowExecution + if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { + return nil, 404, err + } + for _, r := range results { + objs = append(objs, &r) } return objs, 200, nil }