mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
check for empty Properties of update
This commit is contained in:
parent
5eb1487239
commit
9c809e526a
1 changed files with 13 additions and 2 deletions
|
@ -1,7 +1,9 @@
|
|||
package simulator
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/jinzhu/gorm/dialects/postgres"
|
||||
"github.com/nsf/jsondiff"
|
||||
"gopkg.in/go-playground/validator.v9"
|
||||
)
|
||||
|
||||
|
@ -75,8 +77,17 @@ func (r *updateSimulatorRequest) updatedSimulator(oldSimulator Simulator) (Simul
|
|||
if r.State != "" {
|
||||
s.State = r.State
|
||||
}
|
||||
// TODO check for empty properties?
|
||||
s.Properties = r.Properties
|
||||
|
||||
// only update props if not empty
|
||||
var emptyJson postgres.Jsonb
|
||||
// Serialize empty json and params
|
||||
emptyJson_ser, _ := json.Marshal(emptyJson)
|
||||
startParams_ser, _ := json.Marshal(r.Properties)
|
||||
opts := jsondiff.DefaultConsoleOptions()
|
||||
diff, _ := jsondiff.Compare(emptyJson_ser, startParams_ser, &opts)
|
||||
if diff.String() != "FullMatch" {
|
||||
s.Properties = r.Properties
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue