feat: config presets
This commit is contained in:
48
local/model/config_preset.go
Normal file
48
local/model/config_preset.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ConfigPreset struct {
|
||||
ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key;"`
|
||||
Name string `json:"name" gorm:"not null"`
|
||||
Description string `json:"description"`
|
||||
Configuration string `json:"configuration" gorm:"type:text"`
|
||||
AssistRules string `json:"assistRules" gorm:"type:text"`
|
||||
Event string `json:"event" gorm:"type:text"`
|
||||
EventRules string `json:"eventRules" gorm:"type:text"`
|
||||
Settings string `json:"settings" gorm:"type:text"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (p *ConfigPreset) BeforeCreate(tx *gorm.DB) error {
|
||||
if p.ID == uuid.Nil {
|
||||
p.ID = uuid.New()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ConfigPresetCreateRequest struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Configuration *map[string]interface{} `json:"configuration"`
|
||||
AssistRules *map[string]interface{} `json:"assistRules"`
|
||||
Event *map[string]interface{} `json:"event"`
|
||||
EventRules *map[string]interface{} `json:"eventRules"`
|
||||
Settings *map[string]interface{} `json:"settings"`
|
||||
}
|
||||
|
||||
type ConfigPresetUpdateRequest struct {
|
||||
Name *string `json:"name"`
|
||||
Description *string `json:"description"`
|
||||
Configuration *map[string]interface{} `json:"configuration"`
|
||||
AssistRules *map[string]interface{} `json:"assistRules"`
|
||||
Event *map[string]interface{} `json:"event"`
|
||||
EventRules *map[string]interface{} `json:"eventRules"`
|
||||
Settings *map[string]interface{} `json:"settings"`
|
||||
}
|
||||
@@ -30,6 +30,18 @@ type ConfigFilter struct {
|
||||
ChangedAt time.Time `query:"changed_at" time_format:"2006-01-02T15:04:05Z07:00"`
|
||||
}
|
||||
|
||||
type ConfigPresetFilter struct {
|
||||
BaseFilter
|
||||
Name string `query:"name"`
|
||||
}
|
||||
|
||||
func (f *ConfigPresetFilter) ApplyFilter(query *gorm.DB) *gorm.DB {
|
||||
if f.Name != "" {
|
||||
query = query.Where("name LIKE ?", "%"+f.Name+"%")
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
type ServiceControlFilter struct {
|
||||
BaseFilter
|
||||
ServiceControl string `query:"serviceControl"`
|
||||
|
||||
@@ -24,6 +24,11 @@ const (
|
||||
MembershipCreate = "membership.create"
|
||||
MembershipView = "membership.view"
|
||||
MembershipEdit = "membership.edit"
|
||||
|
||||
PresetView = "preset.view"
|
||||
PresetCreate = "preset.create"
|
||||
PresetUpdate = "preset.update"
|
||||
PresetDelete = "preset.delete"
|
||||
)
|
||||
|
||||
func AllPermissions() []string {
|
||||
@@ -47,5 +52,9 @@ func AllPermissions() []string {
|
||||
MembershipCreate,
|
||||
MembershipView,
|
||||
MembershipEdit,
|
||||
PresetView,
|
||||
PresetCreate,
|
||||
PresetUpdate,
|
||||
PresetDelete,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user