添加代理路由和配置版本的控制器与服务,更新数据库模型,完善API路由

This commit is contained in:
ryan
2026-03-09 22:53:51 +08:00
parent 34f317fe6f
commit 8f55d83b34
10 changed files with 721 additions and 1 deletions
+31
View File
@@ -0,0 +1,31 @@
package model
import "time"
type ConfigVersion struct {
ID uint `json:"id" gorm:"primaryKey"`
Version string `json:"version" gorm:"uniqueIndex;size:32;not null"`
SnapshotJSON string `json:"snapshot_json" gorm:"type:text;not null"`
RenderedConfig string `json:"rendered_config" gorm:"type:text;not null"`
Checksum string `json:"checksum" gorm:"size:64;not null"`
IsActive bool `json:"is_active" gorm:"not null;default:false;index"`
CreatedBy string `json:"created_by" gorm:"size:64;not null"`
CreatedAt time.Time `json:"created_at"`
}
func ListConfigVersions() (versions []*ConfigVersion, err error) {
err = DB.Order("id desc").Find(&versions).Error
return versions, err
}
func GetConfigVersionByID(id uint) (*ConfigVersion, error) {
version := &ConfigVersion{}
err := DB.First(version, id).Error
return version, err
}
func GetActiveConfigVersion() (*ConfigVersion, error) {
version := &ConfigVersion{}
err := DB.Where("is_active = ?", true).Order("id desc").First(version).Error
return version, err
}