mongo adjust
This commit is contained in:
@@ -3,7 +3,6 @@ package mongo
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"slices"
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -248,16 +247,11 @@ func (m *MongoDB) StoreOne(obj interface{}, id string, collection_name string) (
|
|||||||
if err := m.createClient(mngoConfig.GetUrl(), false); err != nil {
|
if err := m.createClient(mngoConfig.GetUrl(), false); err != nil {
|
||||||
return "", 503, err
|
return "", 503, err
|
||||||
}
|
}
|
||||||
doc := map[string]interface{}{}
|
|
||||||
fmt.Println("sqdqsd", obj)
|
|
||||||
b, _ := bson.Marshal(obj)
|
|
||||||
bson.Unmarshal(b, &doc)
|
|
||||||
doc["_id"] = id
|
|
||||||
targetDBCollection := CollectionMap[collection_name]
|
targetDBCollection := CollectionMap[collection_name]
|
||||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
MngoCtx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
//defer cancel()
|
//defer cancel()
|
||||||
|
|
||||||
_, err := targetDBCollection.InsertOne(MngoCtx, doc)
|
_, err := targetDBCollection.InsertOne(MngoCtx, obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// m.Logger.Error().Msg("Couldn't insert resource: " + err.Error())
|
// m.Logger.Error().Msg("Couldn't insert resource: " + err.Error())
|
||||||
return "", 409, err
|
return "", 409, err
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ const (
|
|||||||
* every data in base root model should inherit from this struct (only exception is the ResourceModel)
|
* every data in base root model should inherit from this struct (only exception is the ResourceModel)
|
||||||
*/
|
*/
|
||||||
type AbstractObject struct {
|
type AbstractObject struct {
|
||||||
|
ID string `bson:"_id"`
|
||||||
UUID string `json:"id,omitempty" bson:"id,omitempty" validate:"required"`
|
UUID string `json:"id,omitempty" bson:"id,omitempty" validate:"required"`
|
||||||
Name string `json:"name,omitempty" bson:"name,omitempty" validate:"required"`
|
Name string `json:"name,omitempty" bson:"name,omitempty" validate:"required"`
|
||||||
IsDraft bool `json:"is_draft" bson:"is_draft" default:"false"`
|
IsDraft bool `json:"is_draft" bson:"is_draft" default:"false"`
|
||||||
@@ -44,6 +45,7 @@ func (ri *AbstractObject) GetAccessor(request *tools.APIRequest) Accessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *AbstractObject) SetID(id string) {
|
func (r *AbstractObject) SetID(id string) {
|
||||||
|
r.ID = id
|
||||||
r.UUID = id
|
r.UUID = id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ func GenericStoreOne(data DBObject, a Accessor) (DBObject, int, error) {
|
|||||||
if data.GetID() == "" {
|
if data.GetID() == "" {
|
||||||
data.GenerateID()
|
data.GenerateID()
|
||||||
}
|
}
|
||||||
|
data.SetID(data.GetID())
|
||||||
data.StoreDraftDefault()
|
data.StoreDraftDefault()
|
||||||
data.UpToDate(a.GetUser(), a.GetPeerID(), true)
|
data.UpToDate(a.GetUser(), a.GetPeerID(), true)
|
||||||
f := dbs.Filters{
|
f := dbs.Filters{
|
||||||
|
|||||||
Reference in New Issue
Block a user