get_dictionary_list_logic.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package dictionary
  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 GetDictionaryListLogic struct {
  11. logx.Logger
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. }
  15. func NewGetDictionaryListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDictionaryListLogic {
  16. return &GetDictionaryListLogic{
  17. Logger: logx.WithContext(ctx),
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. }
  21. }
  22. func (l *GetDictionaryListLogic) GetDictionaryList(req *types.DictionaryListReq) (resp *types.DictionaryListResp, err error) {
  23. data, err := l.svcCtx.CoreRpc.GetDictionaryList(l.ctx,
  24. &core.DictionaryListReq{
  25. Page: req.Page,
  26. PageSize: req.PageSize,
  27. Name: req.Name,
  28. })
  29. if err != nil {
  30. return nil, err
  31. }
  32. resp = &types.DictionaryListResp{}
  33. resp.Msg = l.svcCtx.Trans.Trans(l.ctx, i18n.Success)
  34. resp.Data.Total = data.GetTotal()
  35. for _, v := range data.Data {
  36. resp.Data.Data = append(resp.Data.Data,
  37. types.DictionaryInfo{
  38. BaseIDInfo: types.BaseIDInfo{
  39. Id: v.Id,
  40. CreatedAt: v.CreatedAt,
  41. UpdatedAt: v.UpdatedAt,
  42. },
  43. Trans: l.svcCtx.Trans.Trans(l.ctx, *v.Title),
  44. Title: v.Title,
  45. Name: v.Name,
  46. Status: v.Status,
  47. Desc: v.Desc,
  48. })
  49. }
  50. return resp, nil
  51. }