update set
This commit is contained in:
parent
4a90d3379c
commit
ebdbd97ce6
@ -145,13 +145,16 @@ func (m *MongoDB) DeleteOne(id string, collection_name string) (int64, int, erro
|
||||
return result.DeletedCount, 200, nil
|
||||
}
|
||||
|
||||
func (m *MongoDB) UpdateOne(set map[string]interface{}, id string, collection_name string) (string, int, error) {
|
||||
func (m *MongoDB) UpdateOne(set interface{}, id string, collection_name string) (string, int, error) {
|
||||
var doc map[string]interface{}
|
||||
b, _ := bson.Marshal(set)
|
||||
bson.Unmarshal(b, &doc)
|
||||
filter := bson.M{"_id": id}
|
||||
targetDBCollection := CollectionMap[collection_name]
|
||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
_, err := targetDBCollection.UpdateOne(MngoCtx, filter, dbs.InputToBson(set, true))
|
||||
_, err := targetDBCollection.UpdateOne(MngoCtx, filter, dbs.InputToBson(doc, true))
|
||||
if err != nil {
|
||||
m.Logger.Error().Msg("Couldn't update resource: " + err.Error())
|
||||
return "", 404, err
|
||||
|
@ -50,7 +50,7 @@ func LoadOne(collection LibDataEnum, id string) LibData {
|
||||
|
||||
func UpdateOne(collection LibDataEnum, set map[string]interface{}, id string) LibData {
|
||||
model := models.Model(collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor().UpdateOne(model.Deserialize(set).Serialize(), id)
|
||||
d, code, err := model.GetAccessor().UpdateOne(model.Deserialize(set), id)
|
||||
if err != nil {
|
||||
return LibData{Data: d, Code: code, Err: err.Error()}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ func (dma *DataMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error)
|
||||
return dma.GenericDeleteOne(id, dma)
|
||||
}
|
||||
|
||||
func (dma *DataMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) {
|
||||
func (dma *DataMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
return dma.GenericUpdateOne(set, id, dma)
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ func (dca *DatacenterMongoAccessor) DeleteOne(id string) (utils.DBObject, int, e
|
||||
return dca.GenericDeleteOne(id, dca)
|
||||
}
|
||||
|
||||
func (dca *DatacenterMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) {
|
||||
func (dca *DatacenterMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
return dca.GenericUpdateOne(set, id, dca)
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ func (pma *ProcessingMongoAccessor) DeleteOne(id string) (utils.DBObject, int, e
|
||||
return pma.GenericDeleteOne(id, pma)
|
||||
}
|
||||
|
||||
func (pma *ProcessingMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) {
|
||||
func (pma *ProcessingMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
return pma.GenericUpdateOne(set, id, pma)
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ func (sma *StorageMongoAccessor) DeleteOne(id string) (utils.DBObject, int, erro
|
||||
return sma.GenericDeleteOne(id, sma)
|
||||
}
|
||||
|
||||
func (sma *StorageMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) {
|
||||
func (sma *StorageMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
return sma.GenericUpdateOne(set, id, sma)
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ func (wfa *WorkflowResourceMongoAccessor) DeleteOne(id string) (utils.DBObject,
|
||||
return wfa.GenericDeleteOne(id, wfa)
|
||||
}
|
||||
|
||||
func (wfa *WorkflowResourceMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) {
|
||||
func (wfa *WorkflowResourceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
return wfa.GenericUpdateOne(set, id, wfa)
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ func (dma *AbstractAccessor) GenericDeleteOne(id string, accessor Accessor) (DBO
|
||||
return res, 200, nil
|
||||
}
|
||||
|
||||
func (dma *AbstractAccessor) GenericUpdateOne(set map[string]interface{}, id string, accessor Accessor) (DBObject, int, error) {
|
||||
func (dma *AbstractAccessor) GenericUpdateOne(set interface{}, id string, accessor Accessor) (DBObject, int, error) {
|
||||
id, code, err := mongo.MONGOService.UpdateOne(set, id, accessor.GetType())
|
||||
if err != nil {
|
||||
dma.Logger.Error().Msg("Could not update " + id + " to db. Error: " + err.Error())
|
||||
|
@ -16,5 +16,5 @@ type Accessor interface {
|
||||
DeleteOne(id string) (DBObject, int, error)
|
||||
CopyOne(data DBObject) (DBObject, int, error)
|
||||
StoreOne(data DBObject) (DBObject, int, error)
|
||||
UpdateOne(set map[string]interface{}, id string) (DBObject, int, error)
|
||||
UpdateOne(set DBObject, id string) (DBObject, int, error)
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ func (wfa *WorkflowMongoAccessor) DeleteOne(id string) (utils.DBObject, int, err
|
||||
return wfa.GenericDeleteOne(id, wfa)
|
||||
}
|
||||
|
||||
func (wfa *WorkflowMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) {
|
||||
func (wfa *WorkflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
return wfa.GenericUpdateOne(set, id, wfa)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user