fix(server): update server filtering to support multiple tags
This commit is contained in:
@@ -32,11 +32,15 @@ func NewGetNodeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetNo
|
||||
}
|
||||
|
||||
func (l *GetNodeListLogic) GetNodeList(req *types.GetNodeServerListRequest) (resp *types.GetNodeServerListResponse, err error) {
|
||||
tags := make([]string, 0)
|
||||
if req.Tags != "" {
|
||||
tags = strings.Split(req.Tags, ",")
|
||||
}
|
||||
total, list, err := l.svcCtx.ServerModel.FindServerListByFilter(l.ctx, &server.ServerFilter{
|
||||
Page: req.Page,
|
||||
Size: req.Size,
|
||||
Search: req.Search,
|
||||
Tag: req.Tag,
|
||||
Tags: tags,
|
||||
Group: req.GroupId,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -2,16 +2,10 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/perfect-panel/server/internal/model/server"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/logger"
|
||||
"github.com/perfect-panel/server/pkg/tool"
|
||||
"github.com/perfect-panel/server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type GetNodeTagListLogic struct {
|
||||
@@ -30,24 +24,8 @@ func NewGetNodeTagListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
|
||||
}
|
||||
|
||||
func (l *GetNodeTagListLogic) GetNodeTagList() (resp *types.GetNodeTagListResponse, err error) {
|
||||
var nodeTags, tags []string
|
||||
err = l.svcCtx.ServerModel.Transaction(l.ctx, func(db *gorm.DB) error {
|
||||
|
||||
return db.Model(&server.Server{}).Select("tags").Pluck("tags", &nodeTags).Error
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "get node tag list failed, %s", err.Error())
|
||||
}
|
||||
|
||||
for _, tag := range nodeTags {
|
||||
tags = append(tags, strings.Split(tag, ",")...)
|
||||
}
|
||||
|
||||
// Remove duplicate tags
|
||||
tags = tool.RemoveDuplicateElements(tags...)
|
||||
|
||||
tags, err := l.svcCtx.ServerModel.FindServerTags(l.ctx)
|
||||
return &types.GetNodeTagListResponse{
|
||||
Tags: tags,
|
||||
Tags: tool.RemoveDuplicateElements(tags...),
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user