get_contact_by_id_logic.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package Contact
  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 GetContactByIdLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewGetContactByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetContactByIdLogic {
  17. return &GetContactByIdLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. func (l *GetContactByIdLogic) GetContactById(req *types.IDReq) (*types.ContactInfoResp, error) {
  24. data, err := l.svcCtx.DB.Contact.Get(l.ctx, req.Id)
  25. if err != nil {
  26. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  27. }
  28. return &types.ContactInfoResp{
  29. BaseDataInfo: types.BaseDataInfo{
  30. Code: 0,
  31. Msg: errormsg.Success,
  32. },
  33. Data: types.ContactInfo{
  34. BaseIDInfo: types.BaseIDInfo{
  35. Id: &data.ID,
  36. CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
  37. UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
  38. },
  39. Status: &data.Status,
  40. WxWxid: &data.WxWxid,
  41. Type: &data.Type,
  42. Wxid: &data.Wxid,
  43. Account: &data.Account,
  44. Nickname: &data.Nickname,
  45. Markname: &data.Markname,
  46. Headimg: &data.Headimg,
  47. Sex: &data.Sex,
  48. Starrole: &data.Starrole,
  49. Dontseeit: &data.Dontseeit,
  50. Dontseeme: &data.Dontseeme,
  51. Lag: &data.Lag,
  52. Gid: &data.Gid,
  53. Gname: &data.Gname,
  54. V3: &data.V3,
  55. },
  56. }, nil
  57. }