Update flatten object

This commit is contained in:
mr 2024-07-23 08:40:24 +02:00
parent a6f2556050
commit 0c825b65b0
3 changed files with 13 additions and 4 deletions

View File

@ -15,7 +15,7 @@ type ProcessingResource struct {
Arguments []string `bson:"arguments,omitempty" json:"arguments,omitempty"`
Environment []map[string]string `bson:"environment,omitempty" json:"environment,omitempty"` // a key/value struct is what ressembles the most a NAME=VALUE struct
ExecutionRequirements ExecutionRequirementsModel `json:"execution_requirements,omitempty"`
ExecutionRequirements *ExecutionRequirementsModel `json:"execution_requirements,omitempty"`
Price uint `bson:"price,omitempty" json:"price,omitempty"`
License string `bson:"license,omitempty" json:"license,omitempty"`

View File

@ -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.Serialize(), res.GetID(), wfa)
return wfa.GenericUpdateOne(data, res.GetID(), wfa)
}
}

View File

@ -65,8 +65,17 @@ func (dma *AbstractAccessor) GenericDeleteOne(id string, accessor Accessor) (DBO
return res, 200, nil
}
func (dma *AbstractAccessor) GenericUpdateOne(set interface{}, id string, accessor Accessor) (DBObject, int, error) {
id, code, err := mongo.MONGOService.UpdateOne(set, id, accessor.GetType())
func (dma *AbstractAccessor) GenericUpdateOne(set DBObject, id string, accessor Accessor) (DBObject, int, error) {
changeMap := set.Serialize()
r, c, err := accessor.LoadOne(id)
if err != nil {
return nil, c, err
}
original := r.Serialize()
for k, v := range changeMap {
original[k] = v
}
id, code, err := mongo.MONGOService.UpdateOne(set.Deserialize(original), id, accessor.GetType())
if err != nil {
dma.Logger.Error().Msg("Could not update " + id + " to db. Error: " + err.Error())
return nil, code, err