temp
This commit is contained in:
@@ -22,6 +22,7 @@ type (
|
||||
DeleteSecretRequest = sentinel.DeleteSecretRequest
|
||||
DeleteUserProductRequest = sentinel.DeleteUserProductRequest
|
||||
DeleteWhitelistRequest = sentinel.DeleteWhitelistRequest
|
||||
GetRecordByCodeRequest = sentinel.GetRecordByCodeRequest
|
||||
GetRecordByIdRequest = sentinel.GetRecordByIdRequest
|
||||
GetSecretBySecretIdRequest = sentinel.GetSecretBySecretIdRequest
|
||||
MatchResponse = sentinel.MatchResponse
|
||||
@@ -51,6 +52,7 @@ type (
|
||||
DeleteProduct(ctx context.Context, in *DeleteProductRequest, opts ...grpc.CallOption) (*Product, error)
|
||||
GetProductPageList(ctx context.Context, in *PageListRequest, opts ...grpc.CallOption) (*ProductResponse, error)
|
||||
GetProductById(ctx context.Context, in *GetRecordByIdRequest, opts ...grpc.CallOption) (*Product, error)
|
||||
GetProductByCode(ctx context.Context, in *GetRecordByCodeRequest, opts ...grpc.CallOption) (*Product, error)
|
||||
}
|
||||
|
||||
defaultProductZrpcClient struct {
|
||||
@@ -89,3 +91,8 @@ func (m *defaultProductZrpcClient) GetProductById(ctx context.Context, in *GetRe
|
||||
client := sentinel.NewProductClient(m.cli.Conn())
|
||||
return client.GetProductById(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultProductZrpcClient) GetProductByCode(ctx context.Context, in *GetRecordByCodeRequest, opts ...grpc.CallOption) (*Product, error) {
|
||||
client := sentinel.NewProductClient(m.cli.Conn())
|
||||
return client.GetProductByCode(ctx, in, opts...)
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ type (
|
||||
DeleteSecretRequest = sentinel.DeleteSecretRequest
|
||||
DeleteUserProductRequest = sentinel.DeleteUserProductRequest
|
||||
DeleteWhitelistRequest = sentinel.DeleteWhitelistRequest
|
||||
GetRecordByCodeRequest = sentinel.GetRecordByCodeRequest
|
||||
GetRecordByIdRequest = sentinel.GetRecordByIdRequest
|
||||
GetSecretBySecretIdRequest = sentinel.GetSecretBySecretIdRequest
|
||||
MatchResponse = sentinel.MatchResponse
|
||||
|
||||
@@ -22,6 +22,7 @@ type (
|
||||
DeleteSecretRequest = sentinel.DeleteSecretRequest
|
||||
DeleteUserProductRequest = sentinel.DeleteUserProductRequest
|
||||
DeleteWhitelistRequest = sentinel.DeleteWhitelistRequest
|
||||
GetRecordByCodeRequest = sentinel.GetRecordByCodeRequest
|
||||
GetRecordByIdRequest = sentinel.GetRecordByIdRequest
|
||||
GetSecretBySecretIdRequest = sentinel.GetSecretBySecretIdRequest
|
||||
MatchResponse = sentinel.MatchResponse
|
||||
|
||||
@@ -22,6 +22,7 @@ type (
|
||||
DeleteSecretRequest = sentinel.DeleteSecretRequest
|
||||
DeleteUserProductRequest = sentinel.DeleteUserProductRequest
|
||||
DeleteWhitelistRequest = sentinel.DeleteWhitelistRequest
|
||||
GetRecordByCodeRequest = sentinel.GetRecordByCodeRequest
|
||||
GetRecordByIdRequest = sentinel.GetRecordByIdRequest
|
||||
GetSecretBySecretIdRequest = sentinel.GetSecretBySecretIdRequest
|
||||
MatchResponse = sentinel.MatchResponse
|
||||
|
||||
@@ -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 GetProductByCodeLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetProductByCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductByCodeLogic {
|
||||
return &GetProductByCodeLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetProductByCodeLogic) GetProductByCode(in *sentinel.GetRecordByCodeRequest) (*sentinel.Product, error) {
|
||||
product, err := l.svcCtx.ProductsModel.FindOneByProductCode(l.ctx, in.Code)
|
||||
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
|
||||
}
|
||||
@@ -48,3 +48,8 @@ func (s *ProductServer) GetProductById(ctx context.Context, in *sentinel.GetReco
|
||||
l := productlogic.NewGetProductByIdLogic(ctx, s.svcCtx)
|
||||
return l.GetProductById(in)
|
||||
}
|
||||
|
||||
func (s *ProductServer) GetProductByCode(ctx context.Context, in *sentinel.GetRecordByCodeRequest) (*sentinel.Product, error) {
|
||||
l := productlogic.NewGetProductByCodeLogic(ctx, s.svcCtx)
|
||||
return l.GetProductByCode(in)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ message WhitePageListRequest {
|
||||
message GetRecordByIdRequest {
|
||||
int64 id = 1;
|
||||
}
|
||||
|
||||
message GetRecordByCodeRequest {
|
||||
string code = 1;
|
||||
}
|
||||
|
||||
message Whitelist {
|
||||
int64 id = 1;
|
||||
@@ -186,6 +188,7 @@ service product {
|
||||
rpc DeleteProduct(DeleteProductRequest) returns (Product);
|
||||
rpc GetProductPageList(PageListRequest) returns (ProductResponse);
|
||||
rpc GetProductById(GetRecordByIdRequest) returns (Product);
|
||||
rpc GetProductByCode(GetRecordByCodeRequest) returns (Product);
|
||||
}
|
||||
service userProduct {
|
||||
// UserProduct methods
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -442,6 +442,7 @@ const (
|
||||
Product_DeleteProduct_FullMethodName = "/product/DeleteProduct"
|
||||
Product_GetProductPageList_FullMethodName = "/product/GetProductPageList"
|
||||
Product_GetProductById_FullMethodName = "/product/GetProductById"
|
||||
Product_GetProductByCode_FullMethodName = "/product/GetProductByCode"
|
||||
)
|
||||
|
||||
// ProductClient is the client API for Product service.
|
||||
@@ -454,6 +455,7 @@ type ProductClient interface {
|
||||
DeleteProduct(ctx context.Context, in *DeleteProductRequest, opts ...grpc.CallOption) (*Product, error)
|
||||
GetProductPageList(ctx context.Context, in *PageListRequest, opts ...grpc.CallOption) (*ProductResponse, error)
|
||||
GetProductById(ctx context.Context, in *GetRecordByIdRequest, opts ...grpc.CallOption) (*Product, error)
|
||||
GetProductByCode(ctx context.Context, in *GetRecordByCodeRequest, opts ...grpc.CallOption) (*Product, error)
|
||||
}
|
||||
|
||||
type productClient struct {
|
||||
@@ -514,6 +516,16 @@ func (c *productClient) GetProductById(ctx context.Context, in *GetRecordByIdReq
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *productClient) GetProductByCode(ctx context.Context, in *GetRecordByCodeRequest, opts ...grpc.CallOption) (*Product, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Product)
|
||||
err := c.cc.Invoke(ctx, Product_GetProductByCode_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ProductServer is the server API for Product service.
|
||||
// All implementations must embed UnimplementedProductServer
|
||||
// for forward compatibility
|
||||
@@ -524,6 +536,7 @@ type ProductServer interface {
|
||||
DeleteProduct(context.Context, *DeleteProductRequest) (*Product, error)
|
||||
GetProductPageList(context.Context, *PageListRequest) (*ProductResponse, error)
|
||||
GetProductById(context.Context, *GetRecordByIdRequest) (*Product, error)
|
||||
GetProductByCode(context.Context, *GetRecordByCodeRequest) (*Product, error)
|
||||
mustEmbedUnimplementedProductServer()
|
||||
}
|
||||
|
||||
@@ -546,6 +559,9 @@ func (UnimplementedProductServer) GetProductPageList(context.Context, *PageListR
|
||||
func (UnimplementedProductServer) GetProductById(context.Context, *GetRecordByIdRequest) (*Product, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetProductById not implemented")
|
||||
}
|
||||
func (UnimplementedProductServer) GetProductByCode(context.Context, *GetRecordByCodeRequest) (*Product, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetProductByCode not implemented")
|
||||
}
|
||||
func (UnimplementedProductServer) mustEmbedUnimplementedProductServer() {}
|
||||
|
||||
// UnsafeProductServer may be embedded to opt out of forward compatibility for this service.
|
||||
@@ -649,6 +665,24 @@ func _Product_GetProductById_Handler(srv interface{}, ctx context.Context, dec f
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Product_GetProductByCode_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetRecordByCodeRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ProductServer).GetProductByCode(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Product_GetProductByCode_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ProductServer).GetProductByCode(ctx, req.(*GetRecordByCodeRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// Product_ServiceDesc is the grpc.ServiceDesc for Product service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
@@ -676,6 +710,10 @@ var Product_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "GetProductById",
|
||||
Handler: _Product_GetProductById_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetProductByCode",
|
||||
Handler: _Product_GetProductByCode_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "sentinel.proto",
|
||||
|
||||
Reference in New Issue
Block a user