github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/api/coin/currency/feed/update.go (about)

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