github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/api/app/coin/description/create.go (about)

     1  package description
     2  
     3  import (
     4  	"context"
     5  
     6  	description1 "github.com/NpoolPlatform/chain-middleware/pkg/mw/app/coin/description"
     7  	"github.com/NpoolPlatform/go-service-framework/pkg/logger"
     8  	npool "github.com/NpoolPlatform/message/npool/chain/mw/v1/app/coin/description"
     9  
    10  	"google.golang.org/grpc/codes"
    11  	"google.golang.org/grpc/status"
    12  )
    13  
    14  func (s *Server) CreateCoinDescription(ctx context.Context, in *npool.CreateCoinDescriptionRequest) (*npool.CreateCoinDescriptionResponse, error) {
    15  	req := in.GetInfo()
    16  	handler, err := description1.NewHandler(
    17  		ctx,
    18  		description1.WithID(req.ID, false),
    19  		description1.WithEntID(req.EntID, false),
    20  		description1.WithAppID(req.AppID, true),
    21  		description1.WithCoinTypeID(req.CoinTypeID, true),
    22  		description1.WithUsedFor(req.UsedFor, true),
    23  		description1.WithTitle(req.Title, true),
    24  		description1.WithMessage(req.Message, true),
    25  	)
    26  	if err != nil {
    27  		logger.Sugar().Errorw(
    28  			"CreateCoinDescription",
    29  			"In", in,
    30  			"Error", err,
    31  		)
    32  		return &npool.CreateCoinDescriptionResponse{}, status.Error(codes.InvalidArgument, err.Error())
    33  	}
    34  
    35  	info, err := handler.CreateCoinDescription(ctx)
    36  	if err != nil {
    37  		logger.Sugar().Errorw(
    38  			"CreateCoinDescription",
    39  			"In", in,
    40  			"Error", err,
    41  		)
    42  		return &npool.CreateCoinDescriptionResponse{}, status.Error(codes.Internal, err.Error())
    43  	}
    44  
    45  	return &npool.CreateCoinDescriptionResponse{
    46  		Info: info,
    47  	}, nil
    48  }