Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 服务列表接口新增指定ID置顶 --bug=133998467 #97

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions cmd/config-server/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ package service

import (
"context"
"sort"
"strconv"
"strings"

Expand All @@ -23,7 +22,6 @@ import (

iamauth "github.com/TencentBlueKing/bk-bscp/internal/iam/auth"
"github.com/TencentBlueKing/bk-bscp/internal/rest/view/webannotation"
"github.com/TencentBlueKing/bk-bscp/internal/runtime/natsort"
"github.com/TencentBlueKing/bk-bscp/internal/space"
"github.com/TencentBlueKing/bk-bscp/pkg/iam/client"
"github.com/TencentBlueKing/bk-bscp/pkg/iam/meta"
Expand Down Expand Up @@ -288,6 +286,7 @@ func (s *Service) ListAppsBySpaceRest(ctx context.Context,
Operator: req.Operator,
Name: req.Name,
All: req.All,
TopIds: req.TopIds,
}
rp, err := s.client.DS.ListAppsRest(kt.RpcCtx(), r)
if err != nil {
Expand Down Expand Up @@ -333,10 +332,6 @@ func (s *Service) ListAppsBySpaceRest(ctx context.Context,
}
}

sort.SliceStable(rp.Details, func(i, j int) bool {
return natsort.NaturalLess(rp.Details[i].Spec.Name, rp.Details[j].Spec.Name)
})

resp := &pbcs.ListAppsResp{
Count: rp.Count,
Details: rp.Details,
Expand Down
9 changes: 6 additions & 3 deletions cmd/data-service/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,13 @@ func (s *Service) ListAppsRest(ctx context.Context, req *pbds.ListAppsRestReq) (
limit = 50
}

// StrToUint32Slice the comma separated string goes to uint32 slice
topIds, _ := tools.StrToUint32Slice(req.TopIds)
opt := &types.BasePage{
Start: req.Start,
Limit: limit,
All: req.All,
Start: req.Start,
Limit: limit,
All: req.All,
TopIds: topIds,
}
if err := opt.Validate(types.DefaultPageOption); err != nil {
return nil, err
Expand Down
5 changes: 5 additions & 0 deletions internal/dal/dao/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
rawgen "gorm.io/gen"

"github.com/TencentBlueKing/bk-bscp/internal/dal/gen"
"github.com/TencentBlueKing/bk-bscp/internal/dal/utils"
"github.com/TencentBlueKing/bk-bscp/pkg/criteria/errf"
"github.com/TencentBlueKing/bk-bscp/pkg/dal/table"
"github.com/TencentBlueKing/bk-bscp/pkg/i18n"
Expand Down Expand Up @@ -103,6 +104,10 @@ func (dao *appDao) List(kit *kit.Kit, bizList []uint32, name, operator string, o
err error
)

if len(opt.TopIds) != 0 {
q = q.Order(utils.NewCustomExpr(`CASE WHEN id IN (?) THEN 0 ELSE 1 END,name ASC`, []interface{}{opt.TopIds}))
}

if opt.All {
result, err = q.Where(conds...).Find()
count = int64(len(result))
Expand Down
11,027 changes: 5,519 additions & 5,508 deletions pkg/protocol/config-server/config_service.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/protocol/config-server/config_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,7 @@ message ListAppsBySpaceRestReq {
string name = 5 [(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = { description: "服务名称" }];
bool all = 6
[(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = { description: "是否获取所有", default: "false" }];
string top_ids = 7 [(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = { description: "需要置顶ID" }];
}

message ListAppsResp {
Expand Down
4 changes: 2 additions & 2 deletions pkg/protocol/config-server/config_service_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6,304 changes: 3,157 additions & 3,147 deletions pkg/protocol/data-service/data_service.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/protocol/data-service/data_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ message ListAppsRestReq {
string operator = 4;
string name = 5;
bool all = 6;
string top_ids = 7;
}

message ListAppsResp {
Expand Down