get_token_list_logic.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package token
  2. import (
  3. "context"
  4. "github.com/suyuan32/simple-admin-core/api/internal/svc"
  5. "github.com/suyuan32/simple-admin-core/api/internal/types"
  6. "github.com/suyuan32/simple-admin-core/rpc/types/core"
  7. "github.com/zeromicro/go-zero/core/logx"
  8. "github.com/suyuan32/simple-admin-common/i18n"
  9. )
  10. type GetTokenListLogic struct {
  11. logx.Logger
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. }
  15. func NewGetTokenListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTokenListLogic {
  16. return &GetTokenListLogic{
  17. Logger: logx.WithContext(ctx),
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. }
  21. }
  22. func (l *GetTokenListLogic) GetTokenList(req *types.TokenListReq) (resp *types.TokenListResp, err error) {
  23. data, err := l.svcCtx.CoreRpc.GetTokenList(l.ctx,
  24. &core.TokenListReq{
  25. Page: req.Page,
  26. PageSize: req.PageSize,
  27. Username: req.Username,
  28. Nickname: req.Nickname,
  29. Email: req.Email,
  30. Uuid: req.Uuid,
  31. })
  32. if err != nil {
  33. return nil, err
  34. }
  35. resp = &types.TokenListResp{}
  36. resp.Msg = l.svcCtx.Trans.Trans(l.ctx, i18n.Success)
  37. resp.Data.Total = data.GetTotal()
  38. for _, v := range data.Data {
  39. resp.Data.Data = append(resp.Data.Data,
  40. types.TokenInfo{
  41. BaseUUIDInfo: types.BaseUUIDInfo{
  42. Id: v.Id,
  43. CreatedAt: v.CreatedAt,
  44. UpdatedAt: v.UpdatedAt,
  45. },
  46. Status: v.Status,
  47. Uuid: v.Uuid,
  48. Token: v.Token,
  49. Source: v.Source,
  50. Username: v.Username,
  51. ExpiredAt: v.ExpiredAt,
  52. })
  53. }
  54. return resp, nil
  55. }