get all bookings
This commit is contained in:
@@ -21,7 +21,7 @@ func (s *SolidarityServiceServerImpl) SetDriverRegularAvailabilities(ctx context
|
||||
if req.DriverRequest.Driver.Id == "" || req.DriverRequest.Driver.Alias == "" || req.DriverAvailabilities == nil || req.DriverRequest.DriverAddress == nil || req.DriverRequest.DriverRadius == 0 {
|
||||
return &proto.DriverAvailabilitiesResponse{
|
||||
Success: false,
|
||||
}, errors.New("missing required fields")
|
||||
}, errors.New("missing required fields")
|
||||
}
|
||||
|
||||
driver := internal.Driver{
|
||||
@@ -424,6 +424,7 @@ func (s *SolidarityServiceServerImpl) GetBookingSolidarity(ctx context.Context,
|
||||
return resp, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *SolidarityServiceServerImpl) GetBookingsByStatus(ctx context.Context, req *proto.GetBookingsByStatusRequest) (resp *proto.GetBookingsByStatusResponse, err error) {
|
||||
if req.Type.String() == "" || req.Status.String() == "" || req.UserId == "" {
|
||||
return nil, errors.New("missing required fields")
|
||||
@@ -458,6 +459,38 @@ func (s *SolidarityServiceServerImpl) GetBookingsByStatus(ctx context.Context, r
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (s *SolidarityServiceServerImpl) GetAllBookingsSolidarity(ctx context.Context, _ *emptypb.Empty) (resp *proto.GetAllBookingsSolidarityResponse, err error) {
|
||||
|
||||
bookings, err := s.Handler.GetAllBookingsSolidarity(ctx)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), utils.SQL_NO_ROWS) {
|
||||
return nil, errors.New("invalid ID")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Use a goroutine to concurrently convert bookings to proto
|
||||
respChan := make(chan []*proto.BookingSolidarity, 1)
|
||||
go func() {
|
||||
respChan <- convertInternalBookingsToProto(s, bookings, 50)
|
||||
}()
|
||||
|
||||
select {
|
||||
case convertedBookings := <-respChan:
|
||||
close(respChan)
|
||||
|
||||
resp = &proto.GetAllBookingsSolidarityResponse{
|
||||
Booking: convertedBookings,
|
||||
}
|
||||
return resp, nil
|
||||
|
||||
case <-ctx.Done():
|
||||
// If the context is canceled, return an error
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
}
|
||||
|
||||
func convertInternalBookingsToProto(s *SolidarityServiceServerImpl, bookings []internal.Booking, maxGoroutines int) []*proto.BookingSolidarity {
|
||||
var responses []*proto.BookingSolidarity
|
||||
var wg sync.WaitGroup
|
||||
|
||||
Reference in New Issue
Block a user