package transformers import ( "time" "git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/proto/gen" "git.coopgo.io/coopgo-platform/solidarity-transport/types" "github.com/paulmach/orb/geojson" "google.golang.org/protobuf/types/known/timestamppb" ) func DriverJourneyTypeToProto(j *types.DriverJourney) (*gen.SolidarityTransportDriverJourney, error) { passengerPickup, err := j.PassengerPickup.MarshalJSON() if err != nil { return nil, err } passengerDrop, err := j.PassengerDrop.MarshalJSON() if err != nil { return nil, err } driverDeparture, err := j.DriverDeparture.MarshalJSON() if err != nil { return nil, err } driverArrival, err := j.DriverArrival.MarshalJSON() if err != nil { return nil, err } return &gen.SolidarityTransportDriverJourney{ Id: j.Id, DriverId: j.DriverId, PassengerPickup: &gen.GeoJsonFeature{ Serialized: string(passengerPickup), }, PassengerDrop: &gen.GeoJsonFeature{ Serialized: string(passengerDrop), }, PassengerDistance: j.PassengerDistance, DriverDeparture: &gen.GeoJsonFeature{ Serialized: string(driverDeparture), }, DriverArrival: &gen.GeoJsonFeature{ Serialized: string(driverArrival), }, DriverDistance: j.DriverDistance, Duration: int64(j.Duration.Seconds()), JourneyPolyline: &j.JourneyPolyline, DriverDepartureDate: timestamppb.New(j.DriverDepartureDate), PassengerPickupDate: timestamppb.New(j.PassengerPickupDate), Price: &gen.SolidarityTransportPrice{ Amount: 0, Currency: "EUR", }, }, nil } func DriverJourneyProtoToType(j *gen.SolidarityTransportDriverJourney) (*types.DriverJourney, error) { passengerPickup, err := geojson.UnmarshalFeature([]byte(j.PassengerPickup.Serialized)) if err != nil { return nil, err } passengerDrop, err := geojson.UnmarshalFeature([]byte(j.PassengerDrop.Serialized)) if err != nil { return nil, err } driverDeparture, err := geojson.UnmarshalFeature([]byte(j.DriverDeparture.Serialized)) if err != nil { return nil, err } driverArrival, err := geojson.UnmarshalFeature([]byte(j.DriverArrival.Serialized)) if err != nil { return nil, err } return &types.DriverJourney{ Id: j.Id, DriverId: j.DriverId, PassengerPickup: passengerPickup, PassengerDrop: passengerDrop, PassengerDistance: j.PassengerDistance, DriverDeparture: driverDeparture, DriverArrival: driverArrival, DriverDistance: j.DriverDistance, Duration: time.Duration(j.Duration) * time.Second, JourneyPolyline: *j.JourneyPolyline, DriverDepartureDate: j.DriverDepartureDate.AsTime(), PassengerPickupDate: j.PassengerPickupDate.AsTime(), Price: types.SolidarityTransportPrice{ Amount: j.Price.Amount, Currency: j.Price.Currency, }, }, nil }