Update Resource
This commit is contained in:
parent
ac2111a365
commit
357d79e68b
@ -14,7 +14,7 @@ func (dma *DataMongoAccessor) DeleteOne(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)
|
||||
return dma.GenericUpdateOne(set, id, dma, &DataResource{})
|
||||
}
|
||||
|
||||
func (dma *DataMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
|
@ -14,7 +14,7 @@ func (dca *DatacenterMongoAccessor) DeleteOne(id string) (utils.DBObject, int, e
|
||||
}
|
||||
|
||||
func (dca *DatacenterMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
return dca.GenericUpdateOne(set, id, dca)
|
||||
return dca.GenericUpdateOne(set, id, dca, &DatacenterResource{})
|
||||
}
|
||||
|
||||
func (dca *DatacenterMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
|
@ -14,7 +14,7 @@ func (pma *ProcessingMongoAccessor) DeleteOne(id string) (utils.DBObject, int, e
|
||||
}
|
||||
|
||||
func (pma *ProcessingMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
return pma.GenericUpdateOne(set, id, pma)
|
||||
return pma.GenericUpdateOne(set, id, pma, &ProcessingResource{})
|
||||
}
|
||||
|
||||
func (pma *ProcessingMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
|
@ -14,7 +14,7 @@ func (sma *StorageMongoAccessor) DeleteOne(id string) (utils.DBObject, int, erro
|
||||
}
|
||||
|
||||
func (sma *StorageMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
return sma.GenericUpdateOne(set, id, sma)
|
||||
return sma.GenericUpdateOne(set, id, sma, &StorageResource{})
|
||||
}
|
||||
|
||||
func (sma *StorageMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
|
@ -14,7 +14,7 @@ func (wfa *WorkflowResourceMongoAccessor) DeleteOne(id string) (utils.DBObject,
|
||||
}
|
||||
|
||||
func (wfa *WorkflowResourceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
return wfa.GenericUpdateOne(set, id, wfa)
|
||||
return wfa.GenericUpdateOne(set, id, wfa, &WorkflowResource{})
|
||||
}
|
||||
|
||||
func (wfa *WorkflowResourceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
@ -28,7 +28,7 @@ func (wfa *WorkflowResourceMongoAccessor) CopyOne(data utils.DBObject) (utils.DB
|
||||
return wfa.GenericStoreOne(data, wfa)
|
||||
} else {
|
||||
data.(*WorkflowResource).UUID = res.GetID()
|
||||
return wfa.GenericUpdateOne(data, res.GetID(), wfa)
|
||||
return wfa.GenericUpdateOne(data, res.GetID(), wfa, &WorkflowResource{})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
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"
|
||||
@ -71,13 +69,18 @@ func (dma *AbstractAccessor) GenericDeleteOne(id string, accessor Accessor) (DBO
|
||||
return res, 200, nil
|
||||
}
|
||||
|
||||
func (dma *AbstractAccessor) GenericUpdateOne(set DBObject, id string, accessor Accessor) (DBObject, int, error) {
|
||||
func (dma *AbstractAccessor) GenericUpdateOne(set DBObject, id string, accessor Accessor, new DBObject) (DBObject, int, error) {
|
||||
r, c, err := accessor.LoadOne(id)
|
||||
if err != nil {
|
||||
return nil, c, err
|
||||
}
|
||||
fmt.Println(set.Serialize(), r.Deserialize(set.Serialize()).Serialize())
|
||||
id, code, err := mongo.MONGOService.UpdateOne(r.Deserialize(set.Serialize()), id, accessor.GetType())
|
||||
change := set.Serialize()
|
||||
loaded := r.Serialize()
|
||||
|
||||
for k, v := range change {
|
||||
loaded[k] = v
|
||||
}
|
||||
id, code, err := mongo.MONGOService.UpdateOne(new.Deserialize(loaded), id, accessor.GetType())
|
||||
if err != nil {
|
||||
dma.Logger.Error().Msg("Could not update " + id + " to db. Error: " + err.Error())
|
||||
return nil, code, err
|
||||
|
@ -63,7 +63,7 @@ func (wfa *WorkflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (util
|
||||
if code, err := wfa.execution(set.(*Workflow), true); err != nil {
|
||||
return nil, code, err
|
||||
}
|
||||
return wfa.GenericUpdateOne(set, id, wfa)
|
||||
return wfa.GenericUpdateOne(set, id, wfa, &Workflow{})
|
||||
}
|
||||
|
||||
func (wfa *WorkflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
|
@ -14,7 +14,7 @@ func (wfa *WorkflowExecutionMongoAccessor) DeleteOne(id string) (utils.DBObject,
|
||||
}
|
||||
|
||||
func (wfa *WorkflowExecutionMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
return wfa.GenericUpdateOne(set, id, wfa)
|
||||
return wfa.GenericUpdateOne(set, id, wfa, &WorkflowExecution{})
|
||||
}
|
||||
|
||||
func (wfa *WorkflowExecutionMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user