get_wx_card_user_by_id_logic.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package wxcarduser
  2. import (
  3. "context"
  4. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  5. "github.com/suyuan32/simple-admin-common/utils/pointy"
  6. "github.com/zeromicro/go-zero/core/errorx"
  7. "wechat-api/ent"
  8. "wechat-api/ent/wxcarduser"
  9. "wechat-api/internal/utils/dberrorhandler"
  10. "wechat-api/internal/svc"
  11. "wechat-api/internal/types"
  12. "github.com/zeromicro/go-zero/core/logx"
  13. )
  14. type GetWxCardUserByIdLogic struct {
  15. logx.Logger
  16. ctx context.Context
  17. svcCtx *svc.ServiceContext
  18. }
  19. func NewGetWxCardUserByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWxCardUserByIdLogic {
  20. return &GetWxCardUserByIdLogic{
  21. Logger: logx.WithContext(ctx),
  22. ctx: ctx,
  23. svcCtx: svcCtx}
  24. }
  25. func (l *GetWxCardUserByIdLogic) GetWxCardUserById(req *types.IDReq) (*types.WxCardUserInfoResp, error) {
  26. data, err := l.svcCtx.DB.WxCardUser.Query().Where(wxcarduser.ID(req.Id)).Only(l.ctx)
  27. if err != nil {
  28. if ent.IsNotFound(err) {
  29. return nil, errorx.NewInvalidArgumentError("记录不存在")
  30. }
  31. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  32. }
  33. return &types.WxCardUserInfoResp{
  34. BaseDataInfo: types.BaseDataInfo{
  35. Code: 0,
  36. Msg: errormsg.Success,
  37. },
  38. Data: types.WxCardUserInfo{
  39. BaseIDInfo: types.BaseIDInfo{
  40. Id: &data.ID,
  41. CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
  42. UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
  43. },
  44. OpenId: &data.OpenID,
  45. Account: &data.Account,
  46. Avatar: &data.Avatar,
  47. Nickname: &data.Nickname,
  48. Remark: &data.Remark,
  49. Phone: &data.Phone,
  50. Wxid: &data.Wxid,
  51. },
  52. }, nil
  53. }