|
|
|
@@ -7,13 +7,53 @@ import ( |
|
|
|
"code.gitea.io/gitea/modules/redis/redis_key" |
|
|
|
) |
|
|
|
|
|
|
|
func GetLimitConfigList(limitType models.LimitType) ([]*models.LimitConfigVO, error) { |
|
|
|
r, err := GetLimitersByLimitType(limitType) |
|
|
|
func GetSingleDailyPointLimitConfig() (*models.LimitConfigVO, error) { |
|
|
|
r, err := GetLimitConfigList(models.LimitConfigQueryOpts{ |
|
|
|
RefreshRate: models.PeriodDaily, |
|
|
|
Scope: models.LimitScopeSingleUser, |
|
|
|
LimitCode: "", |
|
|
|
LimitType: models.LimitTypeRewardPoint, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
if r == nil || len(r) == 0 { |
|
|
|
return nil, nil |
|
|
|
} |
|
|
|
return r[0], nil |
|
|
|
} |
|
|
|
|
|
|
|
func SetSingleDailyPointLimitConfig(limitNum int64, doer *models.User) error { |
|
|
|
l := &models.LimitConfigVO{ |
|
|
|
RefreshRate: models.PeriodDaily, |
|
|
|
Scope: models.LimitScopeSingleUser.Name(), |
|
|
|
LimitCode: "", |
|
|
|
LimitType: models.LimitTypeRewardPoint.Name(), |
|
|
|
LimitNum: limitNum, |
|
|
|
} |
|
|
|
return AddLimitConfig(l, doer) |
|
|
|
} |
|
|
|
|
|
|
|
func GetLimitConfigList(opts models.LimitConfigQueryOpts) ([]*models.LimitConfigVO, error) { |
|
|
|
r, err := GetLimitersByLimitType(opts.LimitType) |
|
|
|
if err != nil { |
|
|
|
log.Error("GetLimitConfigList error when getting limiters by limit type.err=%v", err) |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
result := make([]*models.LimitConfigVO, 0) |
|
|
|
for _, v := range r { |
|
|
|
if opts.LimitCode != "" && opts.LimitCode != v.LimitCode { |
|
|
|
continue |
|
|
|
} |
|
|
|
if opts.Scope != "" && opts.Scope.Name() != v.Scope { |
|
|
|
continue |
|
|
|
} |
|
|
|
if opts.RefreshRate != "" && opts.RefreshRate != v.RefreshRate { |
|
|
|
continue |
|
|
|
} |
|
|
|
if opts.LimitType != "" && opts.LimitType.Name() != v.LimitType { |
|
|
|
continue |
|
|
|
} |
|
|
|
result = append(result, v.ToLimitConfigVO()) |
|
|
|
} |
|
|
|
return result, nil |
|
|
|
@@ -22,14 +62,14 @@ func GetLimitConfigById(id int64) (*models.LimitConfig, error) { |
|
|
|
return models.GetLimitConfigById(id) |
|
|
|
} |
|
|
|
|
|
|
|
func AddLimitConfig(config *models.LimitConfigVO, doer *models.User, limitType models.LimitType) error { |
|
|
|
func AddLimitConfig(config *models.LimitConfigVO, doer *models.User) error { |
|
|
|
r := &models.LimitConfig{ |
|
|
|
Tittle: config.Tittle, |
|
|
|
RefreshRate: config.RefreshRate, |
|
|
|
Scope: config.Scope, |
|
|
|
LimitNum: config.LimitNum, |
|
|
|
LimitCode: config.LimitCode, |
|
|
|
LimitType: limitType.Name(), |
|
|
|
LimitType: config.LimitType, |
|
|
|
CreatorId: doer.ID, |
|
|
|
CreatorName: doer.Name, |
|
|
|
} |
|
|
|
@@ -39,7 +79,7 @@ func AddLimitConfig(config *models.LimitConfigVO, doer *models.User, limitType m |
|
|
|
log.Error("add limit config error,config:%v err:%v", config, err) |
|
|
|
return err |
|
|
|
} |
|
|
|
redis_client.Del(redis_key.LimitConfig(limitType.Name())) |
|
|
|
redis_client.Del(redis_key.LimitConfig(config.LimitType)) |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
|