get_tutorial_by_id_logic.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package tutorial
  2. import (
  3. "context"
  4. "wechat-api/internal/svc"
  5. "wechat-api/internal/types"
  6. "wechat-api/internal/utils/dberrorhandler"
  7. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  8. "github.com/suyuan32/simple-admin-common/utils/pointy"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type GetTutorialByIdLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewGetTutorialByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTutorialByIdLogic {
  17. return &GetTutorialByIdLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. func (l *GetTutorialByIdLogic) GetTutorialById(req *types.IDReq) (*types.TutorialInfoResp, error) {
  24. data, err := l.svcCtx.DB.Tutorial.Get(l.ctx, req.Id)
  25. if err != nil {
  26. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  27. }
  28. return &types.TutorialInfoResp{
  29. BaseDataInfo: types.BaseDataInfo{
  30. Code: 0,
  31. Msg: errormsg.Success,
  32. },
  33. Data: types.TutorialInfo{
  34. BaseIDInfo: types.BaseIDInfo{
  35. Id: &data.ID,
  36. CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
  37. UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
  38. },
  39. EmployeeId: &data.EmployeeID,
  40. Index: &data.Index,
  41. Title: &data.Title,
  42. Content: &data.Content,
  43. },
  44. }, nil
  45. }