68 lines
2.3 KiB
Go
68 lines
2.3 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/proto/gen"
|
|
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/transformers"
|
|
"github.com/paulmach/orb/geojson"
|
|
"github.com/rs/zerolog/log"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
func (s SolidarityTransportServerImpl) GetDriverJourneys(ctx context.Context, req *gen.GetDriverJourneysRequest) (*gen.GetDriverJourneysResponse, error) {
|
|
departureDate := req.DepartureDate.AsTime()
|
|
departure, err := geojson.UnmarshalFeature([]byte(req.Departure.Serialized))
|
|
if err != nil {
|
|
return nil, status.Errorf(codes.Internal, "departure unmarshalling error: %v", err)
|
|
}
|
|
arrival, err := geojson.UnmarshalFeature([]byte(req.Arrival.Serialized))
|
|
if err != nil {
|
|
return nil, status.Errorf(codes.Internal, "arrival unmarhsalling error : %v", err)
|
|
}
|
|
|
|
driverJourneys, err := s.Handler.GetDriverJourneys(departure, arrival, departureDate)
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("issue in GetDriverJourneys handler")
|
|
return nil, status.Errorf(codes.Internal, "could not get driver journeys : %v", err)
|
|
}
|
|
|
|
results := []*gen.SolidarityTransportDriverJourney{}
|
|
|
|
for _, j := range driverJourneys {
|
|
// transformer
|
|
dj, err := transformers.DriverJourneyTypeToProto(j)
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("issue while converting DriverJourney type to protobuf")
|
|
continue
|
|
// return nil, status.Errorf(codes.Internal, "could not get driver journeys : %v", err)
|
|
}
|
|
results = append(results, dj)
|
|
}
|
|
|
|
return &gen.GetDriverJourneysResponse{
|
|
DriverJourneys: results,
|
|
}, nil
|
|
}
|
|
|
|
func (s SolidarityTransportServerImpl) GetDriverJourney(ctx context.Context, req *gen.GetDriverJourneyRequest) (*gen.GetDriverJourneyResponse, error) {
|
|
driverid := req.DriverId
|
|
journeyid := req.JourneyId
|
|
|
|
journey, err := s.Handler.GetDriverJourney(driverid, journeyid)
|
|
if err != nil {
|
|
return nil, status.Errorf(codes.NotFound, "could not get driver journey : %v", err)
|
|
}
|
|
|
|
protojourney, err := transformers.DriverJourneyTypeToProto(journey)
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("transformation error")
|
|
return nil, status.Errorf(codes.NotFound, "transformation error : %v", err)
|
|
}
|
|
|
|
return &gen.GetDriverJourneyResponse{
|
|
DriverJourney: protojourney,
|
|
}, nil
|
|
}
|