mengstack-api/internal/modules/settings/domain/setting.go
MengStack Dev 0eb6a96057 feat(settings): M5 配置管理模块
DB-backed runtime settings with global/tenant scope, key-value store,
type support (string/number/bool/json), tenant-level overrides with
global fallback.
2026-10-03 01:02:53 +08:00

49 lines
1.3 KiB
Go

package domain
import "time"
type Setting struct {
ID uint `json:"id" gorm:"primaryKey"`
TenantID string `json:"tenant_id" gorm:"type:uuid;index:idx_tenant_key,unique;default:''"`
Key string `json:"key" gorm:"size:128;not null;index:idx_tenant_key,unique"`
Value string `json:"value" gorm:"type:text"`
Type string `json:"type" gorm:"size:16;default:string"`
Scope string `json:"scope" gorm:"size:16;default:tenant"`
UpdatedBy uint `json:"updated_by"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (Setting) TableName() string {
return "settings"
}
type SettingDTO struct {
ID uint `json:"id"`
TenantID string `json:"tenant_id"`
Key string `json:"key"`
Value string `json:"value"`
Type string `json:"type"`
Scope string `json:"scope"`
UpdatedBy uint `json:"updated_by"`
UpdatedAt time.Time `json:"updated_at"`
}
func ToSettingDTO(s *Setting) SettingDTO {
return SettingDTO{
ID: s.ID,
TenantID: s.TenantID,
Key: s.Key,
Value: s.Value,
Type: s.Type,
Scope: s.Scope,
UpdatedBy: s.UpdatedBy,
UpdatedAt: s.UpdatedAt,
}
}
type UpdateSettingRequest struct {
Value string `json:"value" binding:"required"`
Type string `json:"type"`
}