Get all bookings
Build and Push Docker Image / build_and_push (push) Failing after 44s
Details
Build and Push Docker Image / build_and_push (push) Failing after 44s
Details
This commit is contained in:
parent
4718de6c80
commit
575b8129b7
|
@ -91,6 +91,32 @@ func (h *CarpoolServiceHandler) GetUserBookings(user_id string, mindate *time.Ti
|
||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetBookings retrieves all the bookings between 2 dates
|
||||||
|
func (h *CarpoolServiceHandler) GetBookings(mindate *time.Time, maxdate *time.Time) ([]internal.Booking, error) {
|
||||||
|
bookings, err := h.Storage.GetAllBookings()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
results := []internal.Booking{}
|
||||||
|
|
||||||
|
for _, b := range bookings {
|
||||||
|
if mindate != nil {
|
||||||
|
if b.PassengerPickupDate.ToTime().Before(*mindate) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if maxdate != nil {
|
||||||
|
if b.PassengerPickupDate.ToTime().After(*maxdate) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
results = append(results, b)
|
||||||
|
}
|
||||||
|
|
||||||
|
return results, nil
|
||||||
|
}
|
||||||
|
|
||||||
// UpdateBookingStatus sets a new status for a given booking id
|
// UpdateBookingStatus sets a new status for a given booking id
|
||||||
func (h *CarpoolServiceHandler) UpdateBookingStatus(id string, status ocss.BookingStatus) error {
|
func (h *CarpoolServiceHandler) UpdateBookingStatus(id string, status ocss.BookingStatus) error {
|
||||||
err := h.Storage.UpdateBookingStatus(id, status.String())
|
err := h.Storage.UpdateBookingStatus(id, status.String())
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -14,6 +14,7 @@ service CarpoolService {
|
||||||
rpc GetUserPlanning(GetUserPlanningRequest) returns (GetUserPlanningResponse) {}
|
rpc GetUserPlanning(GetUserPlanningRequest) returns (GetUserPlanningResponse) {}
|
||||||
rpc GetPlannedTrip(GetPlannedTripRequest) returns (GetPlannedTripResponse) {}
|
rpc GetPlannedTrip(GetPlannedTripRequest) returns (GetPlannedTripResponse) {}
|
||||||
rpc GetUserBookings(GetUserBookingsRequest) returns (GetUserBookingsResponse) {}
|
rpc GetUserBookings(GetUserBookingsRequest) returns (GetUserBookingsResponse) {}
|
||||||
|
rpc GetCarpoolBookings(GetCarpoolBookingsRequest) returns (GetCarpoolBookingsResponse) {}
|
||||||
|
|
||||||
// OCSS interactions
|
// OCSS interactions
|
||||||
rpc DriverJourneys(DriverJourneysRequest) returns (DriverJourneysResponse) {}
|
rpc DriverJourneys(DriverJourneysRequest) returns (DriverJourneysResponse) {}
|
||||||
|
@ -75,6 +76,15 @@ message GetUserBookingsResponse {
|
||||||
repeated CarpoolServiceBooking bookings = 1;
|
repeated CarpoolServiceBooking bookings = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message GetCarpoolBookingsRequest {
|
||||||
|
optional google.protobuf.Timestamp min_date = 2;
|
||||||
|
optional google.protobuf.Timestamp max_date = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetCarpoolBookingsResponse {
|
||||||
|
repeated CarpoolServiceBooking bookings = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// OCSS-like interaction messages
|
// OCSS-like interaction messages
|
||||||
|
|
|
@ -25,6 +25,7 @@ const (
|
||||||
CarpoolService_GetUserPlanning_FullMethodName = "/CarpoolService/GetUserPlanning"
|
CarpoolService_GetUserPlanning_FullMethodName = "/CarpoolService/GetUserPlanning"
|
||||||
CarpoolService_GetPlannedTrip_FullMethodName = "/CarpoolService/GetPlannedTrip"
|
CarpoolService_GetPlannedTrip_FullMethodName = "/CarpoolService/GetPlannedTrip"
|
||||||
CarpoolService_GetUserBookings_FullMethodName = "/CarpoolService/GetUserBookings"
|
CarpoolService_GetUserBookings_FullMethodName = "/CarpoolService/GetUserBookings"
|
||||||
|
CarpoolService_GetCarpoolBookings_FullMethodName = "/CarpoolService/GetCarpoolBookings"
|
||||||
CarpoolService_DriverJourneys_FullMethodName = "/CarpoolService/DriverJourneys"
|
CarpoolService_DriverJourneys_FullMethodName = "/CarpoolService/DriverJourneys"
|
||||||
CarpoolService_PassengerJourneys_FullMethodName = "/CarpoolService/PassengerJourneys"
|
CarpoolService_PassengerJourneys_FullMethodName = "/CarpoolService/PassengerJourneys"
|
||||||
CarpoolService_DriverRegularTrips_FullMethodName = "/CarpoolService/DriverRegularTrips"
|
CarpoolService_DriverRegularTrips_FullMethodName = "/CarpoolService/DriverRegularTrips"
|
||||||
|
@ -46,6 +47,7 @@ type CarpoolServiceClient interface {
|
||||||
GetUserPlanning(ctx context.Context, in *GetUserPlanningRequest, opts ...grpc.CallOption) (*GetUserPlanningResponse, error)
|
GetUserPlanning(ctx context.Context, in *GetUserPlanningRequest, opts ...grpc.CallOption) (*GetUserPlanningResponse, error)
|
||||||
GetPlannedTrip(ctx context.Context, in *GetPlannedTripRequest, opts ...grpc.CallOption) (*GetPlannedTripResponse, error)
|
GetPlannedTrip(ctx context.Context, in *GetPlannedTripRequest, opts ...grpc.CallOption) (*GetPlannedTripResponse, error)
|
||||||
GetUserBookings(ctx context.Context, in *GetUserBookingsRequest, opts ...grpc.CallOption) (*GetUserBookingsResponse, error)
|
GetUserBookings(ctx context.Context, in *GetUserBookingsRequest, opts ...grpc.CallOption) (*GetUserBookingsResponse, error)
|
||||||
|
GetCarpoolBookings(ctx context.Context, in *GetCarpoolBookingsRequest, opts ...grpc.CallOption) (*GetCarpoolBookingsResponse, error)
|
||||||
// OCSS interactions
|
// OCSS interactions
|
||||||
DriverJourneys(ctx context.Context, in *DriverJourneysRequest, opts ...grpc.CallOption) (*DriverJourneysResponse, error)
|
DriverJourneys(ctx context.Context, in *DriverJourneysRequest, opts ...grpc.CallOption) (*DriverJourneysResponse, error)
|
||||||
PassengerJourneys(ctx context.Context, in *PassengerJourneysRequest, opts ...grpc.CallOption) (*PassengerJourneysResponse, error)
|
PassengerJourneys(ctx context.Context, in *PassengerJourneysRequest, opts ...grpc.CallOption) (*PassengerJourneysResponse, error)
|
||||||
|
@ -118,6 +120,15 @@ func (c *carpoolServiceClient) GetUserBookings(ctx context.Context, in *GetUserB
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *carpoolServiceClient) GetCarpoolBookings(ctx context.Context, in *GetCarpoolBookingsRequest, opts ...grpc.CallOption) (*GetCarpoolBookingsResponse, error) {
|
||||||
|
out := new(GetCarpoolBookingsResponse)
|
||||||
|
err := c.cc.Invoke(ctx, CarpoolService_GetCarpoolBookings_FullMethodName, in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *carpoolServiceClient) DriverJourneys(ctx context.Context, in *DriverJourneysRequest, opts ...grpc.CallOption) (*DriverJourneysResponse, error) {
|
func (c *carpoolServiceClient) DriverJourneys(ctx context.Context, in *DriverJourneysRequest, opts ...grpc.CallOption) (*DriverJourneysResponse, error) {
|
||||||
out := new(DriverJourneysResponse)
|
out := new(DriverJourneysResponse)
|
||||||
err := c.cc.Invoke(ctx, CarpoolService_DriverJourneys_FullMethodName, in, out, opts...)
|
err := c.cc.Invoke(ctx, CarpoolService_DriverJourneys_FullMethodName, in, out, opts...)
|
||||||
|
@ -193,6 +204,7 @@ type CarpoolServiceServer interface {
|
||||||
GetUserPlanning(context.Context, *GetUserPlanningRequest) (*GetUserPlanningResponse, error)
|
GetUserPlanning(context.Context, *GetUserPlanningRequest) (*GetUserPlanningResponse, error)
|
||||||
GetPlannedTrip(context.Context, *GetPlannedTripRequest) (*GetPlannedTripResponse, error)
|
GetPlannedTrip(context.Context, *GetPlannedTripRequest) (*GetPlannedTripResponse, error)
|
||||||
GetUserBookings(context.Context, *GetUserBookingsRequest) (*GetUserBookingsResponse, error)
|
GetUserBookings(context.Context, *GetUserBookingsRequest) (*GetUserBookingsResponse, error)
|
||||||
|
GetCarpoolBookings(context.Context, *GetCarpoolBookingsRequest) (*GetCarpoolBookingsResponse, error)
|
||||||
// OCSS interactions
|
// OCSS interactions
|
||||||
DriverJourneys(context.Context, *DriverJourneysRequest) (*DriverJourneysResponse, error)
|
DriverJourneys(context.Context, *DriverJourneysRequest) (*DriverJourneysResponse, error)
|
||||||
PassengerJourneys(context.Context, *PassengerJourneysRequest) (*PassengerJourneysResponse, error)
|
PassengerJourneys(context.Context, *PassengerJourneysRequest) (*PassengerJourneysResponse, error)
|
||||||
|
@ -226,6 +238,9 @@ func (UnimplementedCarpoolServiceServer) GetPlannedTrip(context.Context, *GetPla
|
||||||
func (UnimplementedCarpoolServiceServer) GetUserBookings(context.Context, *GetUserBookingsRequest) (*GetUserBookingsResponse, error) {
|
func (UnimplementedCarpoolServiceServer) GetUserBookings(context.Context, *GetUserBookingsRequest) (*GetUserBookingsResponse, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method GetUserBookings not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method GetUserBookings not implemented")
|
||||||
}
|
}
|
||||||
|
func (UnimplementedCarpoolServiceServer) GetCarpoolBookings(context.Context, *GetCarpoolBookingsRequest) (*GetCarpoolBookingsResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method GetCarpoolBookings not implemented")
|
||||||
|
}
|
||||||
func (UnimplementedCarpoolServiceServer) DriverJourneys(context.Context, *DriverJourneysRequest) (*DriverJourneysResponse, error) {
|
func (UnimplementedCarpoolServiceServer) DriverJourneys(context.Context, *DriverJourneysRequest) (*DriverJourneysResponse, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method DriverJourneys not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method DriverJourneys not implemented")
|
||||||
}
|
}
|
||||||
|
@ -368,6 +383,24 @@ func _CarpoolService_GetUserBookings_Handler(srv interface{}, ctx context.Contex
|
||||||
return interceptor(ctx, in, info, handler)
|
return interceptor(ctx, in, info, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _CarpoolService_GetCarpoolBookings_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(GetCarpoolBookingsRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(CarpoolServiceServer).GetCarpoolBookings(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: CarpoolService_GetCarpoolBookings_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(CarpoolServiceServer).GetCarpoolBookings(ctx, req.(*GetCarpoolBookingsRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
func _CarpoolService_DriverJourneys_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
func _CarpoolService_DriverJourneys_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
in := new(DriverJourneysRequest)
|
in := new(DriverJourneysRequest)
|
||||||
if err := dec(in); err != nil {
|
if err := dec(in); err != nil {
|
||||||
|
@ -525,6 +558,10 @@ var CarpoolService_ServiceDesc = grpc.ServiceDesc{
|
||||||
MethodName: "GetUserBookings",
|
MethodName: "GetUserBookings",
|
||||||
Handler: _CarpoolService_GetUserBookings_Handler,
|
Handler: _CarpoolService_GetUserBookings_Handler,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
MethodName: "GetCarpoolBookings",
|
||||||
|
Handler: _CarpoolService_GetCarpoolBookings_Handler,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
MethodName: "DriverJourneys",
|
MethodName: "DriverJourneys",
|
||||||
Handler: _CarpoolService_DriverJourneys_Handler,
|
Handler: _CarpoolService_DriverJourneys_Handler,
|
||||||
|
|
|
@ -54,6 +54,39 @@ func (s *CarpoolServiceServerImpl) GetUserBookings(ctx context.Context, req *pro
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *CarpoolServiceServerImpl) GetCarpoolBookings(ctx context.Context, req *proto.GetCarpoolBookingsRequest) (*proto.GetCarpoolBookingsResponse, error) {
|
||||||
|
log.Debug().
|
||||||
|
Time("mindate", req.MinDate.AsTime()).
|
||||||
|
Time("maxdate", req.MaxDate.AsTime()).
|
||||||
|
Msg("grpc server - GetUserBookings")
|
||||||
|
|
||||||
|
var mindate *time.Time
|
||||||
|
if req.MinDate != nil {
|
||||||
|
d := req.MinDate.AsTime()
|
||||||
|
mindate = &d
|
||||||
|
}
|
||||||
|
var maxdate *time.Time
|
||||||
|
if req.MaxDate != nil {
|
||||||
|
d := req.MaxDate.AsTime()
|
||||||
|
maxdate = &d
|
||||||
|
}
|
||||||
|
|
||||||
|
bookings, err := s.Handler.GetBookings(mindate, maxdate)
|
||||||
|
if err != nil {
|
||||||
|
return nil, status.Errorf(codes.Internal, "error retrieving user bookings - %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
results := []*proto.CarpoolServiceBooking{}
|
||||||
|
|
||||||
|
for _, b := range bookings {
|
||||||
|
nb := proto.BookingFromInternal(b)
|
||||||
|
results = append(results, nb)
|
||||||
|
}
|
||||||
|
return &proto.GetCarpoolBookingsResponse{
|
||||||
|
Bookings: results,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *CarpoolServiceServerImpl) UpdateBooking(ctx context.Context, req *proto.UpdateCarpoolBookingRequest) (*proto.UpdateCarpoolBookingResponse, error) {
|
func (s *CarpoolServiceServerImpl) UpdateBooking(ctx context.Context, req *proto.UpdateCarpoolBookingRequest) (*proto.UpdateCarpoolBookingResponse, error) {
|
||||||
err := s.Handler.UpdateBookingStatus(req.BookingId, req.Status.ToOCSS())
|
err := s.Handler.UpdateBookingStatus(req.BookingId, req.Status.ToOCSS())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -280,6 +280,29 @@ func (s MongoDBStorage) GetUserBookings(userid string) ([]internal.Booking, erro
|
||||||
return bookings, nil
|
return bookings, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s MongoDBStorage) GetAllBookings() ([]internal.Booking, error) {
|
||||||
|
findOptions := options.Find()
|
||||||
|
collection := s.Client.Database(s.DbName).Collection(s.Collections["bookings"])
|
||||||
|
cur, err := collection.Find(context.TODO(), bson.M{}, findOptions)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var bookings []internal.Booking
|
||||||
|
for cur.Next(context.TODO()) {
|
||||||
|
var elem internal.Booking
|
||||||
|
|
||||||
|
if err := cur.Decode(&elem); err != nil {
|
||||||
|
log.Error().Err(err).Msg("error reading bookings response")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
bookings = append(bookings, elem)
|
||||||
|
}
|
||||||
|
|
||||||
|
return bookings, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s MongoDBStorage) UpdateBookingStatus(bookingid string, status string) error {
|
func (s MongoDBStorage) UpdateBookingStatus(bookingid string, status string) error {
|
||||||
// TODO implement UpdateBookingStatus
|
// TODO implement UpdateBookingStatus
|
||||||
return errors.New("MongoDB Storage - UpdateBookingStatus not implemented")
|
return errors.New("MongoDB Storage - UpdateBookingStatus not implemented")
|
||||||
|
|
|
@ -412,6 +412,66 @@ func (s PostgresqlStorage) GetUserBookings(userid string) ([]internal.Booking, e
|
||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s PostgresqlStorage) GetAllBookings() ([]internal.Booking, error) {
|
||||||
|
req := fmt.Sprintf(`select booking, status, driver_route, passenger_route from %s
|
||||||
|
where 1=1`, s.Tables["bookings"])
|
||||||
|
rows, err := s.DbConnection.Query(req)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("GetUserBookings query issue")
|
||||||
|
}
|
||||||
|
|
||||||
|
results := []internal.Booking{}
|
||||||
|
for rows.Next() {
|
||||||
|
var booking ocss.Booking
|
||||||
|
var status string
|
||||||
|
var bookingbytes, driverroute, passengerroute []byte
|
||||||
|
err := rows.Scan(
|
||||||
|
&bookingbytes,
|
||||||
|
&status,
|
||||||
|
&driverroute,
|
||||||
|
&passengerroute,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("not able to get and scan booking in GetUsersBooking")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(bookingbytes, &booking)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("issue unmarshalling booking in GetUsersBooking")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Override booking status
|
||||||
|
booking.Status = ocss.BookingStatusFromString(status)
|
||||||
|
|
||||||
|
var dr, pr *geojson.FeatureCollection
|
||||||
|
if driverroute != nil {
|
||||||
|
dr, err = geojson.UnmarshalFeatureCollection(driverroute)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("could not unmarshal driver route feature collection")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if passengerroute != nil {
|
||||||
|
pr, err = geojson.UnmarshalFeatureCollection(passengerroute)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("could not unmarshal passenger route feature collection")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
results = append(results, internal.Booking{
|
||||||
|
Booking: booking,
|
||||||
|
DriverRoute: dr,
|
||||||
|
PassengerRoute: pr,
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
return results, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s PostgresqlStorage) StoreRouteSchedules(journeys []internal.PlannedRouteSchedule) error {
|
func (s PostgresqlStorage) StoreRouteSchedules(journeys []internal.PlannedRouteSchedule) error {
|
||||||
tx, err := s.DbConnection.Begin()
|
tx, err := s.DbConnection.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -18,6 +18,7 @@ type Storage interface {
|
||||||
CreateBooking(internal.Booking) error
|
CreateBooking(internal.Booking) error
|
||||||
GetBooking(id string) (*internal.Booking, error)
|
GetBooking(id string) (*internal.Booking, error)
|
||||||
GetUserBookings(userid string) ([]internal.Booking, error)
|
GetUserBookings(userid string) ([]internal.Booking, error)
|
||||||
|
GetAllBookings() ([]internal.Booking, error)
|
||||||
UpdateBookingStatus(bookingid string, status string) error
|
UpdateBookingStatus(bookingid string, status string) error
|
||||||
|
|
||||||
// Caching temporary results
|
// Caching temporary results
|
||||||
|
|
Loading…
Reference in New Issue