implement count rpc
This commit is contained in:
@ -9,6 +9,7 @@ import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
"k8s.io/utils/ptr"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
||||
|
||||
@ -31,6 +32,27 @@ func NewGRPCWeather(ctx context.Context, recorder *recorder.WeatherRecorder) *GR
|
||||
}
|
||||
}
|
||||
|
||||
func (w *GRPCWeather) CountWeatherUpdates(ctx context.Context, req *pb.CountWeatherUpdatesRequest) (
|
||||
*pb.CountWeatherUpdatesResponse, error,
|
||||
) {
|
||||
if req.Opts == nil {
|
||||
count := w.recorder.Count(ctx)
|
||||
return &pb.CountWeatherUpdatesResponse{Count: int32(count)}, nil
|
||||
}
|
||||
|
||||
resp, err := w.GetWeather(ctx, &pb.GetWeatherRequest{
|
||||
Opts: req.Opts,
|
||||
Limit: ptr.To(int32(-1)),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
return &pb.CountWeatherUpdatesResponse{
|
||||
Count: int32(len(resp.WeatherUpdates)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (w *GRPCWeather) GetWeather(ctx context.Context, req *pb.GetWeatherRequest) (
|
||||
*pb.GetWeatherResponse, error,
|
||||
) {
|
||||
|
Reference in New Issue
Block a user