mirror of
https://github.com/komari-monitor/komari.git
synced 2026-11-11 08:42:39 +00:00
29 lines
853 B
Go
29 lines
853 B
Go
package admin
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/komari-monitor/komari/api"
|
|
"github.com/komari-monitor/komari/database/dbcore"
|
|
"github.com/komari-monitor/komari/database/logOperation"
|
|
"github.com/komari-monitor/komari/database/models"
|
|
)
|
|
|
|
func OrderWeight(c *gin.Context) {
|
|
var req = make(map[string]int)
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
api.RespondError(c, 400, "Invalid or missing request body: "+err.Error())
|
|
return
|
|
}
|
|
db := dbcore.GetDBInstance()
|
|
for uuid, weight := range req {
|
|
err := db.Model(&models.Client{}).Where("uuid = ?", uuid).Update("weight", weight).Error
|
|
if err != nil {
|
|
api.RespondError(c, 500, "Failed to update client weight: "+err.Error())
|
|
return
|
|
}
|
|
}
|
|
uuid, _ := c.Get("uuid")
|
|
logOperation.Log(c.ClientIP(), uuid.(string), "order clients", "info")
|
|
api.RespondSuccess(c, nil)
|
|
}
|