update_contact_field_template_logic.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package contact_field_template
  2. import (
  3. "context"
  4. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  5. "wechat-api/ent/contactfieldtemplate"
  6. "wechat-api/internal/utils/dberrorhandler"
  7. "wechat-api/internal/svc"
  8. "wechat-api/internal/types"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type UpdateContactFieldTemplateLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewUpdateContactFieldTemplateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateContactFieldTemplateLogic {
  17. return &UpdateContactFieldTemplateLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx}
  21. }
  22. func (l *UpdateContactFieldTemplateLogic) UpdateContactFieldTemplate(req *types.ContactFieldTemplateInfo) (resp *types.BaseMsgResp, err error) {
  23. organizationId := l.ctx.Value("organizationId").(uint64)
  24. template := ConvertContactFieldTemplates(req.Template)
  25. err = l.svcCtx.DB.ContactFieldTemplate.
  26. Update().
  27. Where(contactfieldtemplate.OrganizationID(organizationId)).
  28. SetTemplate(template).
  29. Exec(l.ctx)
  30. if err != nil {
  31. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  32. }
  33. return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
  34. }