github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/api/coin/query.go (about) 1 //nolint:nolintlint,dupl 2 package coin 3 4 import ( 5 "context" 6 7 coin1 "github.com/NpoolPlatform/chain-middleware/pkg/mw/coin" 8 "github.com/NpoolPlatform/go-service-framework/pkg/logger" 9 npool "github.com/NpoolPlatform/message/npool/chain/mw/v1/coin" 10 11 "google.golang.org/grpc/codes" 12 "google.golang.org/grpc/status" 13 ) 14 15 func (s *Server) GetCoin(ctx context.Context, in *npool.GetCoinRequest) (*npool.GetCoinResponse, error) { 16 handler, err := coin1.NewHandler( 17 ctx, 18 coin1.WithEntID(&in.EntID, true), 19 ) 20 if err != nil { 21 logger.Sugar().Errorw( 22 "GetCoin", 23 "In", in, 24 "Error", err, 25 ) 26 return &npool.GetCoinResponse{}, status.Error(codes.InvalidArgument, err.Error()) 27 } 28 29 info, err := handler.GetCoin(ctx) 30 if err != nil { 31 logger.Sugar().Errorw( 32 "GetCoin", 33 "In", in, 34 "Error", err, 35 ) 36 return &npool.GetCoinResponse{}, status.Error(codes.Internal, err.Error()) 37 } 38 39 return &npool.GetCoinResponse{ 40 Info: info, 41 }, nil 42 } 43 44 func (s *Server) GetCoins(ctx context.Context, in *npool.GetCoinsRequest) (*npool.GetCoinsResponse, error) { 45 handler, err := coin1.NewHandler( 46 ctx, 47 coin1.WithConds(in.GetConds()), 48 coin1.WithOffset(in.GetOffset()), 49 coin1.WithLimit(in.GetLimit()), 50 ) 51 if err != nil { 52 logger.Sugar().Errorw( 53 "GetCoins", 54 "In", in, 55 "Error", err, 56 ) 57 return &npool.GetCoinsResponse{}, status.Error(codes.InvalidArgument, err.Error()) 58 } 59 60 infos, total, err := handler.GetCoins(ctx) 61 if err != nil { 62 logger.Sugar().Errorw( 63 "GetCoins", 64 "In", in, 65 "Error", err, 66 ) 67 return &npool.GetCoinsResponse{}, status.Error(codes.Internal, err.Error()) 68 } 69 70 return &npool.GetCoinsResponse{ 71 Infos: infos, 72 Total: total, 73 }, nil 74 }