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

     1  package coinfiat
     2  
     3  import (
     4  	"context"
     5  
     6  	coinfiat1 "github.com/NpoolPlatform/chain-middleware/pkg/mw/coin/fiat"
     7  	"github.com/NpoolPlatform/go-service-framework/pkg/logger"
     8  	npool "github.com/NpoolPlatform/message/npool/chain/mw/v1/coin/fiat"
     9  
    10  	"google.golang.org/grpc/codes"
    11  	"google.golang.org/grpc/status"
    12  )
    13  
    14  func (s *Server) CreateCoinFiat(ctx context.Context, in *npool.CreateCoinFiatRequest) (*npool.CreateCoinFiatResponse, error) {
    15  	req := in.GetInfo()
    16  	handler, err := coinfiat1.NewHandler(
    17  		ctx,
    18  		coinfiat1.WithCoinTypeID(req.CoinTypeID, true),
    19  		coinfiat1.WithFiatID(req.FiatID, true),
    20  		coinfiat1.WithFeedType(req.FeedType, true),
    21  	)
    22  	if err != nil {
    23  		logger.Sugar().Errorw(
    24  			"CreateCoinFiat",
    25  			"In", in,
    26  			"Error", err,
    27  		)
    28  		return &npool.CreateCoinFiatResponse{}, status.Error(codes.InvalidArgument, err.Error())
    29  	}
    30  
    31  	info, err := handler.CreateCoinFiat(ctx)
    32  	if err != nil {
    33  		logger.Sugar().Errorw(
    34  			"CreateCoinFiat",
    35  			"In", in,
    36  			"Error", err,
    37  		)
    38  		return &npool.CreateCoinFiatResponse{}, status.Error(codes.Internal, err.Error())
    39  	}
    40  
    41  	return &npool.CreateCoinFiatResponse{
    42  		Info: info,
    43  	}, nil
    44  }