first commit
This commit is contained in:
42
apps/sentinel/internal/logic/product/getproductbyidlogic.go
Normal file
42
apps/sentinel/internal/logic/product/getproductbyidlogic.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package productlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/pkg/sqlutil"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetProductByIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetProductByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductByIdLogic {
|
||||
return &GetProductByIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetProductByIdLogic) GetProductById(in *sentinel.GetRecordByIdRequest) (*sentinel.Product, error) {
|
||||
product, err := l.svcCtx.ProductsModel.FindOne(l.ctx, in.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sentinel.Product{
|
||||
Id: product.Id,
|
||||
ProductName: product.ProductName,
|
||||
ProductCode: product.ProductCode,
|
||||
ProductPrice: product.ProductPrice,
|
||||
ProductDescription: sqlutil.NullStringToString(product.ProductDescription),
|
||||
ProductContent: sqlutil.NullStringToString(product.ProductContent),
|
||||
ProductGroup: product.ProductGroup,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user