47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package crm
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
app "haixun-backend/internal/library/errors"
|
|
"haixun-backend/internal/library/errors/code"
|
|
"haixun-backend/internal/svc"
|
|
"haixun-backend/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type CreateCrmContactLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewCreateCrmContactLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateCrmContactLogic {
|
|
return &CreateCrmContactLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
|
}
|
|
|
|
func (l *CreateCrmContactLogic) CreateCrmContact(req *types.CreateCrmContactReq) (*types.CrmContactData, error) {
|
|
tenantID, uid, err := actorFrom(l.ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
authorID := strings.TrimSpace(req.AuthorID)
|
|
authorName := strings.TrimSpace(req.AuthorName)
|
|
if authorID == "" {
|
|
return nil, app.For(code.Persona).InputMissingRequired("author_id is required")
|
|
}
|
|
if authorName == "" {
|
|
return nil, app.For(code.Persona).InputMissingRequired("author_name is required")
|
|
}
|
|
|
|
result, err := l.svcCtx.CrmContact.Create(l.ctx, tenantID, uid, strings.TrimSpace(req.BrandID), authorID, authorName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return toCrmContactData(result), nil
|
|
}
|