feat(api): add reset sort endpoints for server and node
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
@@ -25,6 +26,17 @@ func (*Server) TableName() string {
|
||||
return "servers"
|
||||
}
|
||||
|
||||
func (m *Server) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.Sort == 0 {
|
||||
var maxSort int
|
||||
if err := tx.Model(&Server{}).Select("COALESCE(MAX(sort), 0)").Scan(&maxSort).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
m.Sort = maxSort + 1
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalProtocols Marshal server protocols to json
|
||||
func (m *Server) MarshalProtocols(list []Protocol) error {
|
||||
var validate = make(map[string]bool)
|
||||
|
||||
Reference in New Issue
Block a user