Skip to content

Commit

Permalink
[extapi] fixed configurations not showing on the frontend due to omit…
Browse files Browse the repository at this point in the history
…empty
  • Loading branch information
DictumMortuum committed Dec 14, 2024
1 parent 50845af commit 634a0dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/servus-extapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 9 additions & 5 deletions pkg/model/configurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 634a0dc

Please sign in to comment.