修复(#8): 分组管理核心缺陷与测试覆盖 (#11)

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
2026-06-04 03:13:38 -07:00
committed by GitHub
parent 377f13da48
commit 34cd1c524e
10 changed files with 510 additions and 74 deletions
+37
View File
@@ -0,0 +1,37 @@
package group
import (
"fmt"
"github.com/perfect-panel/server/internal/model/node"
"gorm.io/gorm"
)
const (
defaultPageSize = 20
maxPageSize = 100
)
func normalizePagination(page, size int) (int, int) {
if page <= 0 {
page = 1
}
if size <= 0 {
size = defaultPageSize
}
if size > maxPageSize {
size = maxPageSize
}
return page, size
}
func countNodesInGroup(db *gorm.DB, nodeGroupId int64) (int, error) {
var count int64
err := db.Model(&node.Node{}).
Where("JSON_CONTAINS(node_group_ids, ?)", fmt.Sprintf("[%d]", nodeGroupId)).
Count(&count).Error
if err != nil {
return 0, err
}
return int(count), nil
}