update_label_logic.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package label
  2. import (
  3. "context"
  4. "wechat-api/ent/label"
  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 UpdateLabelLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewUpdateLabelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLabelLogic {
  17. return &UpdateLabelLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. func (l *UpdateLabelLogic) UpdateLabel(req *types.LabelInfo) (*types.BaseMsgResp, error) {
  24. organizationId := l.ctx.Value("organizationId").(uint64)
  25. err := l.svcCtx.DB.Label.UpdateOneID(*req.Id).
  26. Where(label.OrganizationID(organizationId)).
  27. SetNotNilStatus(req.Status).
  28. SetNotNilType(req.Type).
  29. SetNotNilName(req.Name).
  30. SetNotNilFrom(req.From).
  31. SetNotNilMode(req.Mode).
  32. SetNotNilConditions(req.Conditions).
  33. Exec(l.ctx)
  34. if err != nil {
  35. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  36. }
  37. return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
  38. }