From 634a0dcad5c97c46d8179d1d8b905db0678e3d67 Mon Sep 17 00:00:00 2001 From: DictumMortuum Date: Sat, 14 Dec 2024 14:20:02 +0200 Subject: [PATCH] [extapi] fixed configurations not showing on the frontend due to omitempty --- cmd/servus-extapi/main.go | 2 +- pkg/model/configurations.go | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cmd/servus-extapi/main.go b/cmd/servus-extapi/main.go index 0163751..73be266 100644 --- a/cmd/servus-extapi/main.go +++ b/cmd/servus-extapi/main.go @@ -12,7 +12,7 @@ import ( func Version(c *gin.Context) { rs := map[string]any{ - "version": "v0.0.35", + "version": "v0.0.36", } c.AbortWithStatusJSON(200, rs) } diff --git a/pkg/model/configurations.go b/pkg/model/configurations.go index 07e8dc3..33bf121 100644 --- a/pkg/model/configurations.go +++ b/pkg/model/configurations.go @@ -7,9 +7,9 @@ import ( ) type Configuration struct { - Id int64 `gorm:"primaryKey" json:"id,omitempty"` - Config string `json:"config,omitempty"` - Value int `json:"value,omitempty"` + Id int64 `gorm:"primaryKey" json:"id"` + Config string `json:"config"` + Value bool `json:"value"` } func (Configuration) TableName() string { @@ -37,13 +37,17 @@ func (obj Configuration) Update(db *gorm.DB, id int64, body []byte) (any, error) Id: id, } - var payload map[string]any + var payload Configuration err := json.Unmarshal(body, &payload) if err != nil { return nil, err } - rs := db.Model(&model).Save(payload) + // https://stackoverflow.com/questions/56653423/gorm-doesnt-update-boolean-field-to-false + rs := db.Model(&model).Updates(map[string]any{ + "config": payload.Config, + "value": payload.Value, + }) if rs.Error != nil { return nil, err }