From e32ba1e37aabe770a6f92076a9b146f69553403f Mon Sep 17 00:00:00 2001 From: mr Date: Thu, 5 Feb 2026 14:54:41 +0100 Subject: [PATCH] test --- dbs/mongo/mongo.go | 2 ++ models/utils/abstracts.go | 2 +- models/utils/common.go | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dbs/mongo/mongo.go b/dbs/mongo/mongo.go index 22ee69e..f732fa1 100644 --- a/dbs/mongo/mongo.go +++ b/dbs/mongo/mongo.go @@ -3,6 +3,7 @@ package mongo import ( "context" "errors" + "fmt" "slices" "time" @@ -248,6 +249,7 @@ func (m *MongoDB) StoreOne(obj interface{}, id string, collection_name string) ( return "", 503, err } doc := map[string]interface{}{} + fmt.Println("sqdqsd", obj) b, _ := bson.Marshal(obj) bson.Unmarshal(b, &doc) doc["_id"] = id diff --git a/models/utils/abstracts.go b/models/utils/abstracts.go index d6694f2..5fcc525 100755 --- a/models/utils/abstracts.go +++ b/models/utils/abstracts.go @@ -91,7 +91,7 @@ func (ao *AbstractObject) UpToDate(user string, peer string, create bool) { ao.UpdateDate = time.Now() ao.UpdaterID = peer ao.UserUpdaterID = user - if create { + if create && ao.CreatorID != "" { ao.CreationDate = time.Now() ao.CreatorID = peer ao.UserCreatorID = user diff --git a/models/utils/common.go b/models/utils/common.go index c8bd25a..7953f22 100755 --- a/models/utils/common.go +++ b/models/utils/common.go @@ -2,6 +2,7 @@ package utils import ( "errors" + "fmt" "os" "cloud.o-forge.io/core/oc-lib/dbs" @@ -28,7 +29,9 @@ func VerifyAccess(a Accessor, id string) error { // GenericLoadOne loads one object from the database (generic) func GenericStoreOne(data DBObject, a Accessor) (DBObject, int, error) { - data.GenerateID() + if data.GetID() == "" { + data.GenerateID() + } data.StoreDraftDefault() data.UpToDate(a.GetUser(), a.GetPeerID(), true) f := dbs.Filters{ @@ -53,6 +56,7 @@ func GenericStoreOne(data DBObject, a Accessor) (DBObject, int, error) { if err != nil { return nil, 422, errors.New("error when validating the received struct: " + err.Error()) } + fmt.Println(data.GetName(), data.GetCreatorID()) id, code, err := mongo.MONGOService.StoreOne(data, data.GetID(), a.GetType().String()) if err != nil { a.GetLogger().Error().Msg("Could not store " + data.GetName() + " to db. Error: " + err.Error())