feat: add type and default fields to rule group requests and update related logic
This commit is contained in:
committed by
Leif Draven
parent
40c24fbc85
commit
994cc4bebb
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Create rule group
|
||||
// CreateRuleGroupHandler Create rule group
|
||||
func CreateRuleGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.CreateRuleGroupRequest
|
||||
|
||||
@@ -55,11 +55,13 @@ func (l *CreateRuleGroupLogic) CreateRuleGroup(req *types.CreateRuleGroupRequest
|
||||
}
|
||||
|
||||
err = l.svcCtx.ServerModel.InsertRuleGroup(l.ctx, &server.RuleGroup{
|
||||
Name: req.Name,
|
||||
Icon: req.Icon,
|
||||
Tags: tool.StringSliceToString(req.Tags),
|
||||
Rules: strings.Join(rs, "\n"),
|
||||
Enable: req.Enable,
|
||||
Name: req.Name,
|
||||
Icon: req.Icon,
|
||||
Type: req.Type,
|
||||
Tags: tool.StringSliceToString(req.Tags),
|
||||
Rules: strings.Join(rs, "\n"),
|
||||
Default: req.Default,
|
||||
Enable: req.Enable,
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("[CreateRuleGroup] Insert Database Error: ", logger.Field("error", err.Error()))
|
||||
|
||||
@@ -36,12 +36,14 @@ func (l *UpdateRuleGroupLogic) UpdateRuleGroup(req *types.UpdateRuleGroupRequest
|
||||
return err
|
||||
}
|
||||
err = l.svcCtx.ServerModel.UpdateRuleGroup(l.ctx, &server.RuleGroup{
|
||||
Id: req.Id,
|
||||
Icon: req.Icon,
|
||||
Name: req.Name,
|
||||
Tags: tool.StringSliceToString(req.Tags),
|
||||
Rules: strings.Join(rs, "\n"),
|
||||
Enable: req.Enable,
|
||||
Id: req.Id,
|
||||
Icon: req.Icon,
|
||||
Type: req.Type,
|
||||
Name: req.Name,
|
||||
Tags: tool.StringSliceToString(req.Tags),
|
||||
Rules: strings.Join(rs, "\n"),
|
||||
Default: req.Default,
|
||||
Enable: req.Enable,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), err.Error())
|
||||
|
||||
@@ -12,6 +12,8 @@ const (
|
||||
RelayModeNone = "none"
|
||||
RelayModeAll = "all"
|
||||
RelayModeRandom = "random"
|
||||
RuleGroupType = "ban"
|
||||
RuleGroupAuto = "auto"
|
||||
)
|
||||
|
||||
type ServerFilter struct {
|
||||
@@ -178,9 +180,11 @@ type RuleGroup struct {
|
||||
Id int64 `gorm:"primary_key"`
|
||||
Icon string `gorm:"type:MEDIUMTEXT;comment:Rule Group Icon"`
|
||||
Name string `gorm:"type:varchar(100);not null;default:'';comment:Rule Group Name"`
|
||||
Type string `gorm:"type:varchar(100);not null;default:'';comment:Rule Group Type"`
|
||||
Tags string `gorm:"type:text;comment:Selected Node Tags"`
|
||||
Rules string `gorm:"type:MEDIUMTEXT;comment:Rules"`
|
||||
Enable bool `gorm:"type:tinyint(1);not null;default:1;comment:Rule Group Enable"`
|
||||
Default bool `gorm:"type:tinyint(1);not null;default:0;comment:Rule Group is Default"`
|
||||
CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"`
|
||||
UpdatedAt time.Time `gorm:"comment:Update Time"`
|
||||
}
|
||||
|
||||
+20
-11
@@ -32,6 +32,11 @@ type Announcement struct {
|
||||
UpdatedAt int64 `json:"updated_at"`
|
||||
}
|
||||
|
||||
type AnyTLS struct {
|
||||
Port int `json:"port" validate:"required"`
|
||||
SecurityConfig SecurityConfig `json:"security_config"`
|
||||
}
|
||||
|
||||
type AppAuthCheckRequest struct {
|
||||
Method string `json:"method" validate:"required" validate:"required,oneof=device email mobile"`
|
||||
Account string `json:"account"`
|
||||
@@ -441,11 +446,13 @@ type CreatePaymentMethodRequest struct {
|
||||
}
|
||||
|
||||
type CreateRuleGroupRequest struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
Icon string `json:"icon"`
|
||||
Tags []string `json:"tags"`
|
||||
Rules string `json:"rules"`
|
||||
Enable bool `json:"enable"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
Icon string `json:"icon"`
|
||||
Type string `json:"type"`
|
||||
Tags []string `json:"tags"`
|
||||
Rules string `json:"rules"`
|
||||
Default bool `json:"default"`
|
||||
Enable bool `json:"enable"`
|
||||
}
|
||||
|
||||
type CreateSubscribeGroupRequest struct {
|
||||
@@ -1955,12 +1962,14 @@ type UpdatePaymentMethodRequest struct {
|
||||
}
|
||||
|
||||
type UpdateRuleGroupRequest struct {
|
||||
Id int64 `json:"id" validate:"required"`
|
||||
Icon string `json:"icon"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
Tags []string `json:"tags"`
|
||||
Rules string `json:"rules"`
|
||||
Enable bool `json:"enable"`
|
||||
Id int64 `json:"id" validate:"required"`
|
||||
Icon string `json:"icon"`
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
Tags []string `json:"tags"`
|
||||
Rules string `json:"rules"`
|
||||
Default bool `json:"default"`
|
||||
Enable bool `json:"enable"`
|
||||
}
|
||||
|
||||
type UpdateSubscribeGroupRequest struct {
|
||||
|
||||
Reference in New Issue
Block a user