Skip to content

Commit

Permalink
fix: environment list query issue
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJacky committed May 8, 2024
1 parent 392cac4 commit d6d7cdb
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions api/cluster/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/0xJacky/Nginx-UI/settings"
"github.com/gin-gonic/gin"
"github.com/spf13/cast"
"gorm.io/gorm"
"net/http"
)

Expand All @@ -28,12 +29,19 @@ func GetEnvironment(c *gin.Context) {
}

func GetEnvironmentList(c *gin.Context) {
cosy.Core[model.Environment](c).
SetFussy("name").
SetEqual("enabled").
SetTransformer(func(m *model.Environment) any {
return analytic.GetNode(m)
}).PagingList()
core := cosy.Core[model.Environment](c).
SetFussy("name")

// fix for sqlite
if c.Query("enabled") != "" {
core.GormScope(func(tx *gorm.DB) *gorm.DB {
return tx.Where("enabled = ?", cast.ToInt(cast.ToBool(c.Query("enabled"))))
})
}

core.SetTransformer(func(m *model.Environment) any {
return analytic.GetNode(m)
}).PagingList()
}

func AddEnvironment(c *gin.Context) {
Expand Down

0 comments on commit d6d7cdb

Please sign in to comment.