tianyuan-api-server/apps/gateway/internal/logic/whitelistr/getwhitelistlistlogic.go

56 lines
1.3 KiB
Go
Raw Normal View History

2024-10-02 00:57:17 +08:00
package whitelistr
import (
"context"
"errors"
"tianyuan-api/apps/sentinel/client/whitelist"
"tianyuan-api/apps/gateway/internal/svc"
"tianyuan-api/apps/gateway/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetWhitelistListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetWhitelistListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWhitelistListLogic {
return &GetWhitelistListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetWhitelistListLogic) GetWhitelistList(req *types.GetWhitelistListReq) (resp *types.GetWhitelistListResp, err error) {
userId, ok := l.ctx.Value("userId").(int64)
if !ok {
return nil, errors.New("无法获取 userId")
}
whitelistPageResp, err := l.svcCtx.WhitelistRpc.GetWhitePageList(l.ctx, &whitelist.WhitePageListRequest{
UserId: userId,
Page: req.Page,
PageSize: req.PageSize,
})
if err != nil {
return nil, err
}
var list []types.WhitelistItem
for _, up := range whitelistPageResp.Whitelists {
list = append(list, types.WhitelistItem{
Id: up.Id,
WhitelistIp: up.WhitelistIp,
CreatedAt: up.CreatedAt,
UpdatedAt: up.UpdatedAt,
})
}
resp = &types.GetWhitelistListResp{
Total: whitelistPageResp.Total,
List: list,
}
return resp, nil
}