GroupID management
Build and Push Docker Image / build_and_push (push) Failing after 3m9s Details

This commit is contained in:
Arnaud Delcasse 2025-10-16 17:21:45 +02:00
parent 723c12a657
commit e0882db1bc
8 changed files with 68 additions and 5 deletions

View File

@ -9,7 +9,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
func (h Handler) BookDriverJourney(passengerid string, driverid string, journeyid string, returnWaitingDuration time.Duration, priceAmount float64, priceCurrency string, driverCompensationAmount float64, driverCompensationCurrency string, data map[string]any) (*types.Booking, error) { func (h Handler) BookDriverJourney(passengerid string, driverid string, journeyid string, returnWaitingDuration time.Duration, priceAmount float64, priceCurrency string, driverCompensationAmount float64, driverCompensationCurrency string, data map[string]any, groupId string) (*types.Booking, error) {
journey, err := h.Storage.GetDriverJourney(journeyid) journey, err := h.Storage.GetDriverJourney(journeyid)
if err != nil { if err != nil {
log.Error().Err(err).Msg("could not find driver journey") log.Error().Err(err).Msg("could not find driver journey")
@ -25,9 +25,14 @@ func (h Handler) BookDriverJourney(passengerid string, driverid string, journeyi
log.Debug().Float64("Price", priceAmount).Any("journey", journey.Price).Msg("store booking") log.Debug().Float64("Price", priceAmount).Any("journey", journey.Price).Msg("store booking")
// Use provided group_id if set, otherwise generate a new one
if groupId == "" {
groupId = uuid.NewString()
}
booking := types.Booking{ booking := types.Booking{
Id: uuid.NewString(), Id: uuid.NewString(),
GroupId: uuid.NewString(), GroupId: groupId,
Status: "WAITING_CONFIRMATION", Status: "WAITING_CONFIRMATION",
PassengerId: passengerid, PassengerId: passengerid,
DriverId: driverid, DriverId: driverid,

View File

@ -618,6 +618,7 @@ type BookDriverJourneyRequest struct {
Data *structpb.Struct `protobuf:"bytes,7,opt,name=data,proto3" json:"data,omitempty"` Data *structpb.Struct `protobuf:"bytes,7,opt,name=data,proto3" json:"data,omitempty"`
DriverCompensationAmount float64 `protobuf:"fixed64,8,opt,name=driver_compensation_amount,json=driverCompensationAmount,proto3" json:"driver_compensation_amount,omitempty"` DriverCompensationAmount float64 `protobuf:"fixed64,8,opt,name=driver_compensation_amount,json=driverCompensationAmount,proto3" json:"driver_compensation_amount,omitempty"`
DriverCompensationCurrency string `protobuf:"bytes,9,opt,name=driver_compensation_currency,json=driverCompensationCurrency,proto3" json:"driver_compensation_currency,omitempty"` DriverCompensationCurrency string `protobuf:"bytes,9,opt,name=driver_compensation_currency,json=driverCompensationCurrency,proto3" json:"driver_compensation_currency,omitempty"`
GroupId *string `protobuf:"bytes,10,opt,name=group_id,json=groupId,proto3,oneof" json:"group_id,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
} }
@ -715,6 +716,13 @@ func (x *BookDriverJourneyRequest) GetDriverCompensationCurrency() string {
return "" return ""
} }
func (x *BookDriverJourneyRequest) GetGroupId() string {
if x != nil && x.GroupId != nil {
return *x.GroupId
}
return ""
}
type BookDriverJourneyResponse struct { type BookDriverJourneyResponse struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
Booking *SolidarityTransportBooking `protobuf:"bytes,1,opt,name=booking,proto3" json:"booking,omitempty"` Booking *SolidarityTransportBooking `protobuf:"bytes,1,opt,name=booking,proto3" json:"booking,omitempty"`
@ -1262,7 +1270,7 @@ const file_solidarity_transport_proto_rawDesc = "" +
"\n" + "\n" +
"journey_id\x18\x02 \x01(\tR\tjourneyId\"d\n" + "journey_id\x18\x02 \x01(\tR\tjourneyId\"d\n" +
"\x18GetDriverJourneyResponse\x12H\n" + "\x18GetDriverJourneyResponse\x12H\n" +
"\x0edriver_journey\x18\x01 \x01(\v2!.SolidarityTransportDriverJourneyR\rdriverJourney\"\xb5\x03\n" + "\x0edriver_journey\x18\x01 \x01(\v2!.SolidarityTransportDriverJourneyR\rdriverJourney\"\xe2\x03\n" +
"\x18BookDriverJourneyRequest\x12!\n" + "\x18BookDriverJourneyRequest\x12!\n" +
"\fpassenger_id\x18\x01 \x01(\tR\vpassengerId\x12\x1b\n" + "\fpassenger_id\x18\x01 \x01(\tR\vpassengerId\x12\x1b\n" +
"\tdriver_id\x18\x02 \x01(\tR\bdriverId\x12*\n" + "\tdriver_id\x18\x02 \x01(\tR\bdriverId\x12*\n" +
@ -1272,7 +1280,10 @@ const file_solidarity_transport_proto_rawDesc = "" +
"\x0eprice_currency\x18\x06 \x01(\tR\rpriceCurrency\x12+\n" + "\x0eprice_currency\x18\x06 \x01(\tR\rpriceCurrency\x12+\n" +
"\x04data\x18\a \x01(\v2\x17.google.protobuf.StructR\x04data\x12<\n" + "\x04data\x18\a \x01(\v2\x17.google.protobuf.StructR\x04data\x12<\n" +
"\x1adriver_compensation_amount\x18\b \x01(\x01R\x18driverCompensationAmount\x12@\n" + "\x1adriver_compensation_amount\x18\b \x01(\x01R\x18driverCompensationAmount\x12@\n" +
"\x1cdriver_compensation_currency\x18\t \x01(\tR\x1adriverCompensationCurrency\"R\n" + "\x1cdriver_compensation_currency\x18\t \x01(\tR\x1adriverCompensationCurrency\x12\x1e\n" +
"\bgroup_id\x18\n" +
" \x01(\tH\x00R\agroupId\x88\x01\x01B\v\n" +
"\t_group_id\"R\n" +
"\x19BookDriverJourneyResponse\x125\n" + "\x19BookDriverJourneyResponse\x125\n" +
"\abooking\x18\x01 \x01(\v2\x1b.SolidarityTransportBookingR\abooking\"\xef\x01\n" + "\abooking\x18\x01 \x01(\v2\x1b.SolidarityTransportBookingR\abooking\"\xef\x01\n" +
"%GetSolidarityTransportBookingsRequest\x129\n" + "%GetSolidarityTransportBookingsRequest\x129\n" +
@ -1416,6 +1427,7 @@ func file_solidarity_transport_proto_init() {
} }
file_solidarity_transport_types_proto_init() file_solidarity_transport_types_proto_init()
file_solidarity_transport_proto_msgTypes[8].OneofWrappers = []any{} file_solidarity_transport_proto_msgTypes[8].OneofWrappers = []any{}
file_solidarity_transport_proto_msgTypes[12].OneofWrappers = []any{}
type x struct{} type x struct{}
out := protoimpl.TypeBuilder{ out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{ File: protoimpl.DescBuilder{

View File

@ -90,6 +90,7 @@ message BookDriverJourneyRequest {
google.protobuf.Struct data = 7; google.protobuf.Struct data = 7;
double driver_compensation_amount = 8; double driver_compensation_amount = 8;
string driver_compensation_currency = 9; string driver_compensation_currency = 9;
optional string group_id = 10;
} }
message BookDriverJourneyResponse { message BookDriverJourneyResponse {

View File

@ -21,8 +21,9 @@ func (s SolidarityTransportServerImpl) BookDriverJourney(ctx context.Context, re
driverCompensationCurrency := req.DriverCompensationCurrency driverCompensationCurrency := req.DriverCompensationCurrency
returnWaitingDuration := time.Duration(req.ReturnWaitingDuration) returnWaitingDuration := time.Duration(req.ReturnWaitingDuration)
data := req.Data.AsMap() data := req.Data.AsMap()
groupId := req.GetGroupId()
booking, err := s.Handler.BookDriverJourney(passengerId, driverId, journeyId, returnWaitingDuration, priceAmount, priceCurrency, driverCompensationAmount, driverCompensationCurrency, data) booking, err := s.Handler.BookDriverJourney(passengerId, driverId, journeyId, returnWaitingDuration, priceAmount, priceCurrency, driverCompensationAmount, driverCompensationCurrency, data, groupId)
if err != nil { if err != nil {
log.Error().Err(err).Msg("issue in BookDriverJourney handler") log.Error().Err(err).Msg("issue in BookDriverJourney handler")
return nil, status.Errorf(codes.Internal, "could not create booking : %v", err) return nil, status.Errorf(codes.Internal, "could not create booking : %v", err)

View File

@ -161,3 +161,15 @@ func (s MemoryStorage) UpdateBookingStatus(bookingid string, newStatus string, r
return nil return nil
} }
func (s MemoryStorage) GetBookingsByGroupId(groupId string) ([]*types.Booking, error) {
var bookings []*types.Booking
for _, booking := range s.Bookings {
if booking.GroupId == groupId {
bookings = append(bookings, booking)
}
}
return bookings, nil
}

View File

@ -241,6 +241,20 @@ func (m *MockStorage) UpdateBookingStatus(bookingid string, newStatus string, re
return nil return nil
} }
func (m *MockStorage) GetBookingsByGroupId(groupId string) ([]*types.Booking, error) {
m.mu.RLock()
defer m.mu.RUnlock()
var bookings []*types.Booking
for _, booking := range m.bookings {
if booking.GroupId == groupId {
bookings = append(bookings, booking)
}
}
return bookings, nil
}
// Helper methods for testing // Helper methods for testing
// Reset clears all data - useful for test setup // Reset clears all data - useful for test setup

View File

@ -229,3 +229,20 @@ func (s MongoDBStorage) UpdateBookingStatus(bookingid string, newStatus string,
return nil return nil
} }
func (s MongoDBStorage) GetBookingsByGroupId(groupId string) ([]*types.Booking, error) {
filter := bson.M{"groupid": groupId}
cursor, err := s.Collections.Bookings.Find(context.Background(), filter)
if err != nil {
return nil, err
}
defer cursor.Close(context.Background())
var bookings []*types.Booking
if err := cursor.All(context.Background(), &bookings); err != nil {
return nil, err
}
return bookings, nil
}

View File

@ -23,6 +23,7 @@ type Storage interface {
CreateBooking(types.Booking) error CreateBooking(types.Booking) error
GetAllBookings() ([]*types.Booking, error) GetAllBookings() ([]*types.Booking, error)
GetBooking(id string) (*types.Booking, error) GetBooking(id string) (*types.Booking, error)
GetBookingsByGroupId(groupId string) ([]*types.Booking, error)
UpdateBooking(booking types.Booking) error UpdateBooking(booking types.Booking) error
UpdateBookingStatus(bookingid string, newStatus string, reason string) error UpdateBookingStatus(bookingid string, newStatus string, reason string) error
} }