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/rs/zerolog/log" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) func (s SolidarityTransportServerImpl) BookDriverJourney(ctx context.Context, req *gen.BookDriverJourneyRequest) (*gen.BookDriverJourneyResponse, error) { passengerId := req.PassengerId driverId := req.DriverId journeyId := req.DriverJourneyId if err := s.Handler.BookDriverJourney(passengerId, driverId, journeyId); err != nil { log.Error().Err(err).Msg("issue in BookDriverJourney handler") return nil, status.Errorf(codes.Internal, "could not create booking : %v", err) } return &gen.BookDriverJourneyResponse{}, nil } func (s SolidarityTransportServerImpl) GetSolidarityTransportBookings(ctx context.Context, req *gen.GetSolidarityTransportBookingsRequest) (*gen.GetSolidarityTransportBookingsResponse, error) { startdate := req.StartDate.AsTime() enddate := req.EndDate.AsTime() bookings, err := s.Handler.GetBookings(startdate, enddate) if err != nil { log.Error().Err(err).Msg("issue in GetBookings handler") return nil, status.Errorf(codes.NotFound, "could not get bookings : %v", err) } protobookings := []*gen.SolidarityTransportBooking{} for _, b := range bookings { protobooking, _ := transformers.BookingTypeToProto(b) protobookings = append(protobookings, protobooking) } return &gen.GetSolidarityTransportBookingsResponse{ Bookings: protobookings, }, nil } func (s SolidarityTransportServerImpl) GetSolidarityTransportBooking(ctx context.Context, req *gen.GetSolidarityTransportBookingRequest) (*gen.GetSolidarityTransportBookingResponse, error) { bookingid := req.Id booking, err := s.Handler.GetBooking(bookingid) if err != nil { log.Error().Err(err).Msg("issue in GetBooking handler") return nil, status.Errorf(codes.NotFound, "could not get booking : %v", err) } bookingproto, err := transformers.BookingTypeToProto(booking) if err != nil { log.Error().Err(err).Msg("issue in GetBooking handler") return nil, status.Errorf(codes.NotFound, "transformer issue on booking : %v", err) } return &gen.GetSolidarityTransportBookingResponse{ Booking: bookingproto, }, nil } func (s SolidarityTransportServerImpl) UpdateSolidarityTransportBookingStatus(ctx context.Context, req *gen.UpdateSolidarityTransportBookingStatusRequest) (*gen.UpdateSolidarityTransportBookingStatusResponse, error) { bookingid := req.BookingId newStatus := req.NewStatus err := s.Handler.UpdateBookingStatus(bookingid, newStatus) if err != nil { log.Error().Err(err).Msg("issue in GetBooking handler") return nil, status.Errorf(codes.NotFound, "transformer issue on booking : %v", err) } return &gen.UpdateSolidarityTransportBookingStatusResponse{}, nil }