43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package productlogic
|
|
|
|
import (
|
|
"context"
|
|
"tianyuan-api/apps/sentinel/internal/model"
|
|
"tianyuan-api/pkg/sqlutil"
|
|
|
|
"tianyuan-api/apps/sentinel/internal/svc"
|
|
"tianyuan-api/apps/sentinel/sentinel"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type CreateProductLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewCreateProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateProductLogic {
|
|
return &CreateProductLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
// Product methods
|
|
func (l *CreateProductLogic) CreateProduct(in *sentinel.CreateProductRequest) (*sentinel.Product, error) {
|
|
_, err := l.svcCtx.ProductsModel.Insert(l.ctx, &model.Products{
|
|
ProductName: in.ProductName,
|
|
ProductCode: in.ProductCode,
|
|
ProductDescription: sqlutil.StringToNullString(in.ProductDescription),
|
|
ProductContent: sqlutil.StringToNullString(in.ProductContent),
|
|
ProductGroup: in.ProductGroup,
|
|
ProductPrice: in.ProductPrice,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &sentinel.Product{}, nil
|
|
}
|