github.com/unionj-cloud/go-doudou/v2@v2.3.5/toolkit/gormgen/internal/template/appendsvcimplgrpc.go (about)

     1  package template
     2  
     3  const AppendSvcImplGrpc = `
     4  // PostGen{{.ModelStructName}}Rpc {{.StructComment}}
     5  ` + NotEditMarkForGDDShort + `
     6  func (receiver *{{.InterfaceName}}Impl) PostGen{{.ModelStructName}}Rpc(ctx context.Context, request *pb.{{.ModelStructName}}) (*pb.PostGen{{.ModelStructName}}RpcResponse, error) {
     7  	var body dto.{{.ModelStructName}}
     8  	jsoncopier.DeepCopy(request, &body)
     9  	data, err := receiver.PostGen{{.ModelStructName}}(ctx, body)
    10  	return &pb.PostGen{{.ModelStructName}}RpcResponse{
    11  		Data: data,
    12  	}, errors.WithStack(err)
    13  }
    14  
    15  // PostGen{{.ModelStructName}}sRpc {{.StructComment}}
    16  ` + NotEditMarkForGDDShort + `
    17  func (receiver *{{.InterfaceName}}Impl) PostGen{{.ModelStructName}}sRpc(ctx context.Context, request *pb.PostGen{{.ModelStructName}}sRpcRequest) (*pb.PostGen{{.ModelStructName}}sRpcResponse, error) {
    18  	list := make([]dto.{{.ModelStructName}}, 0, len(request.Body))
    19  	for _, item := range request.Body {
    20  		var d dto.{{.ModelStructName}}
    21  		jsoncopier.DeepCopy(item, &d)
    22  		list = append(list, d)
    23  	}
    24  	data, err := receiver.PostGen{{.ModelStructName}}s(ctx, list)
    25  	return &pb.PostGen{{.ModelStructName}}sRpcResponse{
    26  		Data: data,
    27  	}, errors.WithStack(err)
    28  }
    29  
    30  // GetGen{{.ModelStructName}}IdRpc {{.StructComment}}
    31  ` + NotEditMarkForGDDShort + `
    32  func (receiver *{{.InterfaceName}}Impl) GetGen{{.ModelStructName}}IdRpc(ctx context.Context, request *pb.GetGen{{.ModelStructName}}IdRpcRequest) (*pb.{{.ModelStructName}}, error) {
    33  	data, err := receiver.GetGen{{.ModelStructName}}_Id(ctx, request.Id)
    34  	if err != nil {
    35  		return nil, errors.WithStack(err)
    36  	}
    37  	var ret pb.{{.ModelStructName}}
    38  	jsoncopier.DeepCopy(data, &ret)
    39  	return &ret, nil
    40  }
    41  
    42  // PutGen{{.ModelStructName}}Rpc {{.StructComment}}
    43  ` + NotEditMarkForGDDShort + `
    44  func (receiver *{{.InterfaceName}}Impl) PutGen{{.ModelStructName}}Rpc(ctx context.Context, request *pb.{{.ModelStructName}}) (*emptypb.Empty, error) {
    45  	var body dto.{{.ModelStructName}}
    46  	jsoncopier.DeepCopy(request, &body)
    47  	return &emptypb.Empty{}, errors.WithStack(receiver.PutGen{{.ModelStructName}}(ctx, body))
    48  }
    49  
    50  // DeleteGen{{.ModelStructName}}IdRpc {{.StructComment}}
    51  ` + NotEditMarkForGDDShort + `
    52  func (receiver *{{.InterfaceName}}Impl) DeleteGen{{.ModelStructName}}IdRpc(ctx context.Context, request *pb.DeleteGen{{.ModelStructName}}IdRpcRequest) (*emptypb.Empty, error) {
    53  	return &emptypb.Empty{}, errors.WithStack(receiver.DeleteGen{{.ModelStructName}}_Id(ctx, request.Id))
    54  }
    55  
    56  // GetGen{{.ModelStructName}}sRpc {{.StructComment}}
    57  ` + NotEditMarkForGDDShort + `
    58  func (receiver *{{.InterfaceName}}Impl) GetGen{{.ModelStructName}}sRpc(ctx context.Context, request *pb.Parameter) (*pb.Page, error) {
    59  	filters := make([]interface{}, 0, len(request.Filters))
    60  	for _, item := range request.Filters {
    61  		str := wrappers.StringValue{}
    62  		if err := anypb.UnmarshalTo(item, &str, proto.UnmarshalOptions{}); err != nil {
    63  			return nil, errors.WithStack(err)
    64  		}
    65  		filters = append(filters, str.Value)
    66  	}
    67  	var parameter dto.Parameter
    68  	jsoncopier.DeepCopy(request, &parameter)
    69  	parameter.Filters = filters
    70  	data, err := receiver.GetGen{{.ModelStructName}}s(ctx, parameter)
    71  	if err != nil {
    72  		return nil, errors.WithStack(err)
    73  	}
    74  	items := make([]*anypb.Any, 0, len(data.Items))
    75  	for _, item := range data.Items {
    76  		d := dto.{{.ModelStructName}}(item.(model.{{.ModelStructName}}))
    77  		var msg pb.{{.ModelStructName}}
    78  		jsoncopier.DeepCopy(d, &msg)
    79  		a, err := anypb.New(&msg)
    80  		if err != nil {
    81  			return nil, errors.WithStack(err)
    82  		}
    83  		items = append(items, a)
    84  	}
    85  	var ret pb.Page
    86  	jsoncopier.DeepCopy(data, &ret)
    87  	ret.Items = items
    88  	return &ret, nil
    89  }
    90  
    91  `