Add PostgreSQL database option and more booking flow functionalities
This commit is contained in:
@@ -55,7 +55,7 @@ func (s *CarpoolServiceServerImpl) GetUserPlanning(ctx context.Context, req *pro
|
||||
for _, s := range scheds {
|
||||
s.Route.ExtraMembers["departure_date"] = s.DepartureDate
|
||||
s.Route.ExtraMembers["id"] = s.ID
|
||||
fcraw, _ := s.Route.FeatureCollection().MarshalJSON()
|
||||
fcraw, _ := s.Route.MarshalJSON()
|
||||
results[k].Collection = append(results[k].Collection, &proto.CarpoolFeatureCollection{
|
||||
Serialized: string(fcraw),
|
||||
})
|
||||
@@ -73,9 +73,10 @@ func (s *CarpoolServiceServerImpl) GetPlannedTrip(ctx context.Context, req *prot
|
||||
return nil, status.Errorf(codes.Internal, "could not retrieve planned trip - %s", err.Error())
|
||||
}
|
||||
|
||||
planned_trip.Route.ExtraMembers["id"] = planned_trip.ID
|
||||
planned_trip.Route.ExtraMembers["departure_date"] = planned_trip.DepartureDate
|
||||
|
||||
serialized, err := planned_trip.Route.FeatureCollection().MarshalJSON()
|
||||
serialized, err := planned_trip.Route.MarshalJSON()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("grpc GetPlannedTrip - could not serialize feature collection")
|
||||
return nil, status.Errorf(codes.Internal, "could not serialize feature collection")
|
||||
|
||||
@@ -13,13 +13,16 @@ import (
|
||||
)
|
||||
|
||||
func (s *CarpoolServiceServerImpl) DriverJourneys(ctx context.Context, req *proto.DriverJourneysRequest) (*proto.DriverJourneysResponse, error) {
|
||||
log.Debug().
|
||||
Str("departure date", req.DepartureDate.String()).
|
||||
Msg("grpc server - DriverJourneys")
|
||||
|
||||
departure := orb.Point{req.DepartureLng, req.DepartureLat}
|
||||
arrival := orb.Point{req.ArrivalLng, req.ArrivalLat}
|
||||
|
||||
log.Debug().
|
||||
Str("departure date", req.DepartureDate.String()).
|
||||
Any("departure", departure).
|
||||
Any("arrival", arrival).
|
||||
Msg("grpc server - DriverJourneys")
|
||||
|
||||
td := 900 * time.Second
|
||||
if req.TimeDelta != nil {
|
||||
td = time.Duration(*req.TimeDelta) * time.Second
|
||||
@@ -65,17 +68,18 @@ func (s *CarpoolServiceServerImpl) DriverJourneys(ctx context.Context, req *prot
|
||||
var distance *int64
|
||||
if len(j.Itinerary.Legs) > 2 {
|
||||
duration = j.Itinerary.Legs[1].Duration
|
||||
dist := int64(j.Itinerary.Legs[1].Distance)
|
||||
dist := j.Itinerary.Legs[1].Distance
|
||||
distance = &dist
|
||||
}
|
||||
|
||||
results = append(results, &proto.CarpoolServiceDriverJourney{
|
||||
Id: journeyId,
|
||||
Driver: &proto.CarpoolServiceUser{
|
||||
Id: usermap["id"].(string),
|
||||
Operator: usermap["operator"].(string),
|
||||
Alias: usermap["alias"].(string),
|
||||
},
|
||||
Operator: "ridygo.fr",
|
||||
Operator: s.Handler.InternalOperatorID,
|
||||
PassengerPickupLat: req.DepartureLat,
|
||||
PassengerPickupLng: req.DepartureLng,
|
||||
PassengerDropLat: req.ArrivalLat,
|
||||
@@ -86,9 +90,8 @@ func (s *CarpoolServiceServerImpl) DriverJourneys(ctx context.Context, req *prot
|
||||
DriverArrivalLng: &driverArrivalLng,
|
||||
DriverDepartureAddress: driverDepartureAddress,
|
||||
DriverArrivalAddress: driverArrivalAddress,
|
||||
Duration: int64(duration),
|
||||
Duration: int64(duration.Seconds()),
|
||||
Distance: distance,
|
||||
Id: journeyId,
|
||||
PassengerPickupDate: timestamppb.New(j.DepartureDate.Add(j.Itinerary.Legs[0].Duration)),
|
||||
DriverDepartureDate: timestamppb.New(j.DepartureDate),
|
||||
Type: proto.CarpoolServiceJourneyType_PLANNED,
|
||||
@@ -137,25 +140,26 @@ func (s *CarpoolServiceServerImpl) PassengerJourneys(ctx context.Context, req *p
|
||||
passengerPickupAddress = &ppa
|
||||
}
|
||||
var passengerDropAddress *string
|
||||
if pda := j.Route.Features[0].Properties.MustString("label", ""); pda != "" {
|
||||
if pda := j.Route.Features[1].Properties.MustString("label", ""); pda != "" {
|
||||
passengerDropAddress = &pda
|
||||
}
|
||||
driverDepartureDate := timestamppb.New(j.DepartureDate.Add(-j.Itinerary.Legs[0].Duration))
|
||||
duration := time.Duration(0)
|
||||
var distance *int64
|
||||
if len(j.Itinerary.Legs) > 2 {
|
||||
duration = j.Itinerary.Legs[1].Duration / time.Second
|
||||
dist := int64(j.Itinerary.Legs[1].Distance)
|
||||
duration = j.Itinerary.Legs[1].Duration
|
||||
dist := j.Itinerary.Legs[1].Distance
|
||||
distance = &dist
|
||||
}
|
||||
|
||||
results = append(results, &proto.CarpoolServicePassengerJourney{
|
||||
Id: journeyId,
|
||||
Passenger: &proto.CarpoolServiceUser{
|
||||
Id: usermap["id"].(string),
|
||||
Operator: usermap["operator"].(string),
|
||||
Alias: usermap["alias"].(string),
|
||||
},
|
||||
Operator: "ridygo.fr",
|
||||
Operator: s.Handler.InternalOperatorID,
|
||||
PassengerPickupLat: passengerDepartureLat,
|
||||
PassengerPickupLng: passengerDepartureLng,
|
||||
PassengerDropLat: passengerArrivalLat,
|
||||
@@ -166,9 +170,8 @@ func (s *CarpoolServiceServerImpl) PassengerJourneys(ctx context.Context, req *p
|
||||
DriverDepartureLng: &req.DepartureLng,
|
||||
DriverArrivalLat: &req.ArrivalLat,
|
||||
DriverArrivalLng: &req.ArrivalLng,
|
||||
Duration: int64(duration),
|
||||
Duration: int64(duration.Seconds()),
|
||||
Distance: distance,
|
||||
Id: journeyId,
|
||||
PassengerPickupDate: passengerDepartureDate,
|
||||
DriverDepartureDate: driverDepartureDate,
|
||||
Type: proto.CarpoolServiceJourneyType_PLANNED,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package grpcserver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
@@ -10,9 +9,7 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/reflection"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type CarpoolServiceServerImpl struct {
|
||||
@@ -27,16 +24,6 @@ func NewCarpoolServiceServer(handler *handler.CarpoolServiceHandler) *CarpoolSer
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CarpoolServiceServerImpl) CreateBooking(context.Context, *proto.CreateBookingRequest) (*proto.CreateBookingResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CreateBooking not implemented")
|
||||
}
|
||||
func (s *CarpoolServiceServerImpl) UpdateBooking(context.Context, *proto.UpdateBookingRequest) (*proto.UpdateBookingResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method UpdateBooking not implemented")
|
||||
}
|
||||
func (s *CarpoolServiceServerImpl) GetBooking(context.Context, *proto.GetBookingRequest) (*proto.GetBookingResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetBooking not implemented")
|
||||
}
|
||||
|
||||
func Run(done chan error, cfg *viper.Viper, handler *handler.CarpoolServiceHandler) {
|
||||
var (
|
||||
dev_env = cfg.GetBool("dev_env")
|
||||
|
||||
Reference in New Issue
Block a user