get_label_relationship_by_id_logic.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package label_relationship
  2. import (
  3. "context"
  4. "wechat-api/ent/labelrelationship"
  5. "wechat-api/internal/svc"
  6. "wechat-api/internal/types"
  7. "wechat-api/internal/utils/dberrorhandler"
  8. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  9. "github.com/suyuan32/simple-admin-common/utils/pointy"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type GetLabelRelationshipByIdLogic struct {
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. logx.Logger
  16. }
  17. func NewGetLabelRelationshipByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLabelRelationshipByIdLogic {
  18. return &GetLabelRelationshipByIdLogic{
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. Logger: logx.WithContext(ctx),
  22. }
  23. }
  24. func (l *GetLabelRelationshipByIdLogic) GetLabelRelationshipById(req *types.IDReq) (*types.LabelRelationshipInfoResp, error) {
  25. organizationId := l.ctx.Value("organizationId").(uint64)
  26. data, err := l.svcCtx.DB.LabelRelationship.Query().
  27. Where(
  28. labelrelationship.IDEQ(req.Id), // Filter by ID
  29. labelrelationship.OrganizationID(organizationId), // Additional filter by organizationId
  30. ).
  31. Only(l.ctx)
  32. if err != nil {
  33. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  34. }
  35. return &types.LabelRelationshipInfoResp{
  36. BaseDataInfo: types.BaseDataInfo{
  37. Code: 0,
  38. Msg: errormsg.Success,
  39. },
  40. Data: types.LabelRelationshipInfo{
  41. BaseIDInfo: types.BaseIDInfo{
  42. Id: &data.ID,
  43. CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
  44. UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
  45. },
  46. Status: &data.Status,
  47. LabelId: &data.LabelID,
  48. ContactId: &data.ContactID,
  49. },
  50. }, nil
  51. }