get_role_by_id_logic.go 1.3 KB

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