缓存策略列表支持搜索

This commit is contained in:
GoEdgeLab
2021-06-07 08:44:19 +08:00
parent 2e4a25f762
commit cac1a08a06
2 changed files with 18 additions and 9 deletions

View File

@@ -210,16 +210,25 @@ func (this *HTTPCachePolicyDAO) ComposeCachePolicy(tx *dbs.Tx, policyId int64) (
} }
// CountAllEnabledHTTPCachePolicies 计算可用缓存策略数量 // CountAllEnabledHTTPCachePolicies 计算可用缓存策略数量
func (this *HTTPCachePolicyDAO) CountAllEnabledHTTPCachePolicies(tx *dbs.Tx) (int64, error) { func (this *HTTPCachePolicyDAO) CountAllEnabledHTTPCachePolicies(tx *dbs.Tx, keyword string) (int64, error) {
return this.Query(tx). query := this.Query(tx).
State(HTTPCachePolicyStateEnabled). State(HTTPCachePolicyStateEnabled)
Count() if len(keyword) > 0 {
query.Where("(name LIKE :keyword)").
Param("keyword", "%"+keyword+"%")
}
return query.Count()
} }
// ListEnabledHTTPCachePolicies 列出单页的缓存策略 // ListEnabledHTTPCachePolicies 列出单页的缓存策略
func (this *HTTPCachePolicyDAO) ListEnabledHTTPCachePolicies(tx *dbs.Tx, offset int64, size int64) ([]*serverconfigs.HTTPCachePolicy, error) { func (this *HTTPCachePolicyDAO) ListEnabledHTTPCachePolicies(tx *dbs.Tx, keyword string, offset int64, size int64) ([]*serverconfigs.HTTPCachePolicy, error) {
ones, err := this.Query(tx). query := this.Query(tx).
State(HTTPCachePolicyStateEnabled). State(HTTPCachePolicyStateEnabled)
if len(keyword) > 0 {
query.Where("(name LIKE :keyword)").
Param("keyword", "%"+keyword+"%")
}
ones, err := query.
ResultPk(). ResultPk().
Offset(offset). Offset(offset).
Limit(size). Limit(size).

View File

@@ -100,7 +100,7 @@ func (this *HTTPCachePolicyService) CountAllEnabledHTTPCachePolicies(ctx context
tx := this.NullTx() tx := this.NullTx()
count, err := models.SharedHTTPCachePolicyDAO.CountAllEnabledHTTPCachePolicies(tx) count, err := models.SharedHTTPCachePolicyDAO.CountAllEnabledHTTPCachePolicies(tx, req.Keyword)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -117,7 +117,7 @@ func (this *HTTPCachePolicyService) ListEnabledHTTPCachePolicies(ctx context.Con
tx := this.NullTx() tx := this.NullTx()
cachePolicies, err := models.SharedHTTPCachePolicyDAO.ListEnabledHTTPCachePolicies(tx, req.Offset, req.Size) cachePolicies, err := models.SharedHTTPCachePolicyDAO.ListEnabledHTTPCachePolicies(tx, req.Keyword, req.Offset, req.Size)
if err != nil { if err != nil {
return nil, err return nil, err
} }