get_dictionary_by_id_logic.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 GetDictionaryByIdLogic struct {
  11. logx.Logger
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. }
  15. func NewGetDictionaryByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDictionaryByIdLogic {
  16. return &GetDictionaryByIdLogic{
  17. Logger: logx.WithContext(ctx),
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. }
  21. }
  22. func (l *GetDictionaryByIdLogic) GetDictionaryById(req *types.IDReq) (resp *types.DictionaryInfoResp, err error) {
  23. data, err := l.svcCtx.CoreRpc.GetDictionaryById(l.ctx, &core.IDReq{Id: req.Id})
  24. if err != nil {
  25. return nil, err
  26. }
  27. return &types.DictionaryInfoResp{
  28. BaseDataInfo: types.BaseDataInfo{
  29. Code: 0,
  30. Msg: l.svcCtx.Trans.Trans(l.ctx, i18n.Success),
  31. },
  32. Data: types.DictionaryInfo{
  33. BaseIDInfo: types.BaseIDInfo{
  34. Id: data.Id,
  35. CreatedAt: data.CreatedAt,
  36. UpdatedAt: data.UpdatedAt,
  37. },
  38. Title: data.Title,
  39. Name: data.Name,
  40. Status: data.Status,
  41. Desc: data.Desc,
  42. },
  43. }, nil
  44. }