init: 1.0.0
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package document
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/document"
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type CreateDocumentLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Create document
|
||||
func NewCreateDocumentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateDocumentLogic {
|
||||
return &CreateDocumentLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateDocumentLogic) CreateDocument(req *types.CreateDocumentRequest) error {
|
||||
if err := l.svcCtx.DocumentModel.Insert(l.ctx, &document.Document{
|
||||
Title: req.Title,
|
||||
Content: req.Content,
|
||||
Tags: strings.Join(req.Tags, ","),
|
||||
Show: req.Show,
|
||||
}); err != nil {
|
||||
l.Errorw("[CreateDocument] Database Error", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "insert document error: %v", err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user