45 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
		
		
			
		
	
	
			45 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
|  | package whitelistlogic | ||
|  | 
 | ||
|  | import ( | ||
|  | 	"context" | ||
|  | 	"tianyuan-api/apps/sentinel/internal/svc" | ||
|  | 	"tianyuan-api/apps/sentinel/sentinel" | ||
|  | 
 | ||
|  | 	"github.com/zeromicro/go-zero/core/logx" | ||
|  | ) | ||
|  | 
 | ||
|  | type GetWhitePageListLogic struct { | ||
|  | 	ctx    context.Context | ||
|  | 	svcCtx *svc.ServiceContext | ||
|  | 	logx.Logger | ||
|  | } | ||
|  | 
 | ||
|  | func NewGetWhitePageListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWhitePageListLogic { | ||
|  | 	return &GetWhitePageListLogic{ | ||
|  | 		ctx:    ctx, | ||
|  | 		svcCtx: svcCtx, | ||
|  | 		Logger: logx.WithContext(ctx), | ||
|  | 	} | ||
|  | } | ||
|  | 
 | ||
|  | func (l *GetWhitePageListLogic) GetWhitePageList(in *sentinel.WhitePageListRequest) (*sentinel.WhitelistResponse, error) { | ||
|  | 	whitelists, total, err := l.svcCtx.WhitelistModel.FindWhitelistList(l.ctx, in.UserId, in.Page, in.PageSize) | ||
|  | 	if err != nil { | ||
|  | 		return nil, err | ||
|  | 	} | ||
|  | 	var list []*sentinel.Whitelist | ||
|  | 	for _, w := range whitelists { | ||
|  | 		list = append(list, &sentinel.Whitelist{ | ||
|  | 			Id:          w.Id, | ||
|  | 			UserId:      w.UserId, | ||
|  | 			WhitelistIp: w.WhitelistIp, | ||
|  | 			CreatedAt:   w.CreatedAt.Format("2006-01-02 15:04:05"), | ||
|  | 			UpdatedAt:   w.UpdatedAt.Format("2006-01-02 15:04:05"), | ||
|  | 		}) | ||
|  | 	} | ||
|  | 	return &sentinel.WhitelistResponse{ | ||
|  | 		Total:      total, | ||
|  | 		Whitelists: list, | ||
|  | 	}, nil | ||
|  | } |