insert uuid
This commit is contained in:
parent
f7dfbe91dd
commit
9f17532646
@ -2,7 +2,6 @@ package mongo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -161,14 +160,11 @@ func (m *MongoDB) UpdateOne(set map[string]interface{}, id string, collection_na
|
|||||||
return result.UpsertedID.(primitive.ObjectID).Hex(), 200, nil
|
return result.UpsertedID.(primitive.ObjectID).Hex(), 200, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MongoDB) StoreOne(obj interface{}, collection_name string) (string, int, error) {
|
func (m *MongoDB) StoreOne(obj interface{}, id string, collection_name string) (string, int, error) {
|
||||||
var doc interface{}
|
var doc map[string]interface{}
|
||||||
b, err := json.Marshal(obj)
|
b, _ := bson.Marshal(obj)
|
||||||
if err != nil {
|
bson.Unmarshal(b, &doc)
|
||||||
m.Logger.Error().Msg("Couldn't insert resource: " + err.Error())
|
doc["_id"] = id
|
||||||
return "", 422, err
|
|
||||||
}
|
|
||||||
bson.UnmarshalExtJSON(b, false, &doc)
|
|
||||||
targetDBCollection := CollectionMap[collection_name]
|
targetDBCollection := CollectionMap[collection_name]
|
||||||
|
|
||||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
package mongo
|
|
||||||
|
|
||||||
// func TestMongoInit(T *testing.T){
|
|
||||||
// MongoInit()
|
|
||||||
// fmt.Printf("It worked !")
|
|
||||||
// }
|
|
@ -11,7 +11,7 @@ import (
|
|||||||
var validate = validator.New(validator.WithRequiredStructEnabled())
|
var validate = validator.New(validator.WithRequiredStructEnabled())
|
||||||
|
|
||||||
type AbstractObject struct {
|
type AbstractObject struct {
|
||||||
UUID string `json:"id" required:"true" bson:"_id" validate:"required"`
|
UUID string `json:"id" required:"true" bson:"id" validate:"required"`
|
||||||
Name string `json:"name" required:"true" bson:"name" validate:"required"`
|
Name string `json:"name" required:"true" bson:"name" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ func (wfa *AbstractAccessor) GenericStoreOne(data DBObject, accessor Accessor) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 422, err
|
return nil, 422, err
|
||||||
}
|
}
|
||||||
id, code, err := mongo.MONGOService.StoreOne(data, wfa.GetType())
|
id, code, err := mongo.MONGOService.StoreOne(data, data.GetID(), wfa.GetType())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wfa.Logger.Error().Msg("Could not store " + data.GetName() + " to db. Error: " + err.Error())
|
wfa.Logger.Error().Msg("Could not store " + data.GetName() + " to db. Error: " + err.Error())
|
||||||
return nil, code, err
|
return nil, code, err
|
||||||
|
Loading…
Reference in New Issue
Block a user