UUID type cannot accept empty string default. Global settings use empty tenant_id, so varchar(36) is the correct type.
49 lines
1.3 KiB
Go
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:"size:36;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"`
|
|
}
|