first commit
This commit is contained in:
42
apps/sentinel/internal/logic/product/createproductlogic.go
Normal file
42
apps/sentinel/internal/logic/product/createproductlogic.go
Normal file
@@ -0,0 +1,42 @@
|
||||
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
|
||||
}
|
||||
30
apps/sentinel/internal/logic/product/deleteproductlogic.go
Normal file
30
apps/sentinel/internal/logic/product/deleteproductlogic.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package productlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DeleteProductLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDeleteProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteProductLogic {
|
||||
return &DeleteProductLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeleteProductLogic) DeleteProduct(in *sentinel.DeleteProductRequest) (*sentinel.Product, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &sentinel.Product{}, nil
|
||||
}
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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 GetProductPageListLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetProductPageListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductPageListLogic {
|
||||
return &GetProductPageListLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetProductPageListLogic) GetProductPageList(in *sentinel.PageListRequest) (*sentinel.ProductResponse, error) {
|
||||
products, total, err := l.svcCtx.ProductsModel.FindProductsList(l.ctx, in.Page, in.PageSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var list []*sentinel.Product
|
||||
for _, p := range products {
|
||||
list = append(list, &sentinel.Product{
|
||||
Id: p.Id,
|
||||
ProductName: p.ProductName,
|
||||
ProductCode: p.ProductCode,
|
||||
ProductDescription: sqlutil.NullStringToString(p.ProductDescription),
|
||||
ProductGroup: p.ProductGroup,
|
||||
ProductPrice: p.ProductPrice,
|
||||
})
|
||||
}
|
||||
return &sentinel.ProductResponse{
|
||||
Total: total,
|
||||
Products: list,
|
||||
}, nil
|
||||
}
|
||||
30
apps/sentinel/internal/logic/product/updateproductlogic.go
Normal file
30
apps/sentinel/internal/logic/product/updateproductlogic.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package productlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateProductLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateProductLogic {
|
||||
return &UpdateProductLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateProductLogic) UpdateProduct(in *sentinel.UpdateProductRequest) (*sentinel.Product, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &sentinel.Product{}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user