github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/api/fiat/currency/feed/create.go (about) 1 package currencyfeed 2 3 import ( 4 "context" 5 6 currencyfeed1 "github.com/NpoolPlatform/chain-middleware/pkg/mw/fiat/currency/feed" 7 "github.com/NpoolPlatform/go-service-framework/pkg/logger" 8 npool "github.com/NpoolPlatform/message/npool/chain/mw/v1/fiat/currency/feed" 9 10 "google.golang.org/grpc/codes" 11 "google.golang.org/grpc/status" 12 ) 13 14 func (s *Server) CreateFeed(ctx context.Context, in *npool.CreateFeedRequest) (*npool.CreateFeedResponse, error) { 15 req := in.GetInfo() 16 handler, err := currencyfeed1.NewHandler( 17 ctx, 18 currencyfeed1.WithID(req.ID, false), 19 currencyfeed1.WithEntID(req.EntID, false), 20 currencyfeed1.WithFiatID(req.FiatID, true), 21 currencyfeed1.WithFeedType(req.FeedType, true), 22 currencyfeed1.WithFeedFiatName(req.FeedFiatName, true), 23 currencyfeed1.WithDisabled(req.Disabled, true), 24 ) 25 if err != nil { 26 logger.Sugar().Errorw( 27 "CreateFeed", 28 "In", in, 29 "Error", err, 30 ) 31 return &npool.CreateFeedResponse{}, status.Error(codes.InvalidArgument, err.Error()) 32 } 33 34 info, err := handler.CreateFeed(ctx) 35 if err != nil { 36 logger.Sugar().Errorw( 37 "CreateFeed", 38 "In", in, 39 "Error", err, 40 ) 41 return &npool.CreateFeedResponse{}, status.Error(codes.Internal, err.Error()) 42 } 43 44 return &npool.CreateFeedResponse{ 45 Info: info, 46 }, nil 47 }