robocanic commented on code in PR #1325:
URL: https://github.com/apache/dubbo-admin/pull/1325#discussion_r2365931424
##########
pkg/console/handler/tag_rule.go:
##########
@@ -20,66 +20,80 @@ package handler
import (
"fmt"
"net/http"
- "strconv"
"strings"
+ "github.com/apache/dubbo-admin/pkg/core/manager"
+ meshresource
"github.com/apache/dubbo-admin/pkg/core/resource/apis/mesh/v1alpha1"
+ coremodel "github.com/apache/dubbo-admin/pkg/core/resource/model"
+ "github.com/apache/dubbo-admin/pkg/core/store/index"
+ "github.com/duke-git/lancet/v2/strutil"
"github.com/gin-gonic/gin"
- meshproto "github.com/apache/dubbo-admin/api/mesh/v1alpha1"
consolectx "github.com/apache/dubbo-admin/pkg/console/context"
"github.com/apache/dubbo-admin/pkg/console/model"
"github.com/apache/dubbo-admin/pkg/console/service"
"github.com/apache/dubbo-admin/pkg/core/consts"
- "github.com/apache/dubbo-admin/pkg/core/store"
)
func TagRuleSearch(ctx consolectx.Context) gin.HandlerFunc {
return func(c *gin.Context) {
+
req := model.NewSearchReq()
if err := c.ShouldBindQuery(req); err != nil {
c.JSON(http.StatusBadRequest,
model.NewErrorResp(err.Error()))
return
}
- resList := &mesh.TagRouteResourceList{}
- if req.Keywords == "" {
- if err := ctx.ResourceManager().List(ctx.AppContext(),
resList, store.ListByPage(req.PageSize, strconv.Itoa(req.PageOffset))); err !=
nil {
- c.JSON(http.StatusBadRequest,
model.NewErrorResp(err.Error()))
- return
- }
+ var pageData *coremodel.PageData[*meshresource.TagRouteResource]
+ var err error
+ if strutil.IsBlank(req.Keywords) {
+ pageData, err =
manager.PageListByIndexes[*meshresource.TagRouteResource](
+ ctx.ResourceManager(),
+ meshresource.TagRouteKind,
+ map[string]interface{}{
+ index.ByMeshIndex: req.Mesh,
+ },
+ req.PageReq)
+
} else {
- if err := ctx.ResourceManager().List(ctx.AppContext(),
resList, store.ListByNameContains(req.Keywords), store.ListByPage(req.PageSize,
strconv.Itoa(req.PageOffset))); err != nil {
- c.JSON(http.StatusBadRequest,
model.NewErrorResp(err.Error()))
- return
- }
+ pageData, err =
manager.PageSearchResourceByConditions[*meshresource.TagRouteResource](
+ ctx.ResourceManager(),
+ meshresource.TagRouteKind,
+ []string{"name=" + req.Keywords},
+ req.PageReq,
+ )
+
+ }
+ if err != nil {
+ c.JSON(http.StatusInternalServerError,
model.NewErrorResp(err.Error()))
+ return
}
- var respList []model.TagRuleSearchResp
- for _, item := range resList.Items {
- time := item.Meta.GetCreationTime().String()
- name := item.Meta.GetName()
- respList = append(respList, model.TagRuleSearchResp{
- CreateTime: &time,
- Enabled: &item.Spec.Enabled,
- RuleName: &name,
+ resp := model.NewSearchPaginationResult()
+ var list []*model.TagRuleSearchResp
+ for _, item := range pageData.Data {
+ list = append(list, &model.TagRuleSearchResp{
+ CreateTime: "",
Review Comment:
CreateTime is a todo. There is no datasource for CreateTime yet. Will be
filled in next prs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]