update_label_relationship_logic.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/zeromicro/go-zero/core/logx"
  10. )
  11. type UpdateLabelRelationshipLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewUpdateLabelRelationshipLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLabelRelationshipLogic {
  17. return &UpdateLabelRelationshipLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. func (l *UpdateLabelRelationshipLogic) UpdateLabelRelationship(req *types.LabelRelationshipInfo) (*types.BaseMsgResp, error) {
  24. organizationId := l.ctx.Value("organizationId").(uint64)
  25. err := l.svcCtx.DB.LabelRelationship.UpdateOneID(*req.Id).
  26. Where(labelrelationship.OrganizationID(organizationId)).
  27. SetNotNilStatus(req.Status).
  28. SetNotNilLabelID(req.LabelId).
  29. SetNotNilContactID(req.ContactId).
  30. Exec(l.ctx)
  31. if err != nil {
  32. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  33. }
  34. return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
  35. }