Initial commit
This commit is contained in:
3
cmd/standardcovoiturage-to-rdex-gateway/README.md
Normal file
3
cmd/standardcovoiturage-to-rdex-gateway/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Standard covoiturage to RDEX Gateway
|
||||
|
||||
Standard covoiturage to RDEX Gateway is a converter from the new standard covoiturage to RDEX API calls for searching carpool journeys.
|
||||
15
cmd/standardcovoiturage-to-rdex-gateway/go.mod
Normal file
15
cmd/standardcovoiturage-to-rdex-gateway/go.mod
Normal file
@@ -0,0 +1,15 @@
|
||||
module git.coopgo.io/coopgo-platform/standard-covoiturage/cmd/standardcovoiturage-to-rdex-bridge
|
||||
|
||||
replace git.coopgo.io/coopgo-platform/standard-covoiturage => ../../
|
||||
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
git.coopgo.io/coopgo-platform/standard-covoiturage v0.0.0
|
||||
gitlab.scity.coop/go-libs/rdex-golang v0.0.0-20210202230228-0ccbfcbe2163
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/gorilla/schema v1.2.0 // indirect
|
||||
golang.org/x/crypto v0.1.0 // indirect
|
||||
)
|
||||
6
cmd/standardcovoiturage-to-rdex-gateway/go.sum
Normal file
6
cmd/standardcovoiturage-to-rdex-gateway/go.sum
Normal file
@@ -0,0 +1,6 @@
|
||||
github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
|
||||
github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
|
||||
gitlab.scity.coop/go-libs/rdex-golang v0.0.0-20210202230228-0ccbfcbe2163 h1:F0XUsnMwOtDLaS1riH/fEopzly+KdwZpUHIvL0f/RHQ=
|
||||
gitlab.scity.coop/go-libs/rdex-golang v0.0.0-20210202230228-0ccbfcbe2163/go.mod h1:EOh0Z3TK1/Z48oDidtIV3reDcflpYCIdZk+2Mj76a/4=
|
||||
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
|
||||
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
|
||||
117
cmd/standardcovoiturage-to-rdex-gateway/main.go
Normal file
117
cmd/standardcovoiturage-to-rdex-gateway/main.go
Normal file
@@ -0,0 +1,117 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
standardcovoiturage "git.coopgo.io/coopgo-platform/standard-covoiturage"
|
||||
"gitlab.scity.coop/go-libs/rdex-golang"
|
||||
)
|
||||
|
||||
func main() {
|
||||
handler := CarpoolHandler{}
|
||||
server := standardcovoiturage.NewServer(handler)
|
||||
server.AddOperator("fakeoperator", "mysupersecretapikey")
|
||||
|
||||
http.Handle("/", server)
|
||||
|
||||
err := http.ListenAndServe(":3333", nil)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
type CarpoolHandler struct{}
|
||||
|
||||
func (h CarpoolHandler) GetDriverJourneys(ctx context.Context, departureLat float64, departureLng float64, arrivalLat float64, arrivalLng float64, departureDate time.Time, timeDelta *time.Duration, departureRadius *float64, count *int64) ([]standardcovoiturage.DriverJourney, error) {
|
||||
carpoolrequest := "https://api.rdex.ridygo.fr/journeys.json"
|
||||
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest("GET", carpoolrequest, nil)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
req.URL.RawQuery = fmt.Sprintf(
|
||||
"p[driver][state]=1&frequency=punctual&p[passenger][state]=0&p[from][latitude]=%f&p[from][longitude]=%f&p[to][latitude]=%f&p[to][longitude]=%f&p[outward][mindate]=%s&p[outward][maxdate]=%s",
|
||||
departureLat, departureLng,
|
||||
arrivalLat, arrivalLng,
|
||||
departureDate.Format("2006-01-02"), departureDate.Format("2006-01-02"))
|
||||
|
||||
req.Header.Set("X-API-KEY", "123456")
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
var carpoolresults []rdex.RDEXJourney
|
||||
|
||||
if err == nil && resp.StatusCode == http.StatusOK {
|
||||
err = json.NewDecoder(resp.Body).Decode(&carpoolresults)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if carpoolresults == nil {
|
||||
carpoolresults = []rdex.RDEXJourney{}
|
||||
}
|
||||
} else {
|
||||
carpoolresults = []rdex.RDEXJourney{}
|
||||
}
|
||||
|
||||
results := []standardcovoiturage.DriverJourney{}
|
||||
for _, c := range carpoolresults {
|
||||
|
||||
journey := standardcovoiturage.DriverJourney{
|
||||
AvailableSteats: c.Driver.Seats,
|
||||
DriverTrip: standardcovoiturage.DriverTrip{
|
||||
Trip: standardcovoiturage.Trip{
|
||||
Operator: c.Operator,
|
||||
WebUrl: c.URL,
|
||||
PassengerPickupLat: c.From.Latitude,
|
||||
PassengerPickupLng: c.From.Longitude,
|
||||
},
|
||||
Driver: standardcovoiturage.User{
|
||||
ID: *c.Driver.UUID,
|
||||
Operator: c.Operator,
|
||||
Alias: *c.Driver.Alias,
|
||||
Picture: c.Driver.Image,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
results = append(results, journey)
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// func (h CarpoolHandler) GetDriverJourneys(ctx context.Context, departureLat float64, departureLng float64, arrivalLat float64, arrivalLng float64, departureDate time.Time, timeDelta *time.Duration, departureRadius *float64, count *int64) ([]standardcovoiturage.DriverJourney, error) {
|
||||
// availableSeats := int64(1)
|
||||
|
||||
// return []standardcovoiturage.DriverJourney{
|
||||
// {
|
||||
// AvailableSteats: &availableSeats,
|
||||
// DriverTrip: standardcovoiturage.DriverTrip{
|
||||
// Driver: standardcovoiturage.User{
|
||||
// ID: "1234567890",
|
||||
// Operator: "fakeoperator",
|
||||
// Alias: "Fake user",
|
||||
// },
|
||||
// Trip: standardcovoiturage.Trip{
|
||||
// Operator: "fakeoperator",
|
||||
// PassengerPickupLat: 2.0,
|
||||
// PassengerPickupLng: 2.0,
|
||||
// PassengerDropLat: 3.0,
|
||||
// PassengerDropLng: 3.0,
|
||||
// Duration: 3600,
|
||||
// },
|
||||
// },
|
||||
// JourneySchedule: standardcovoiturage.JourneySchedule{
|
||||
// PassengerPickupDate: time.Now(),
|
||||
// Type: standardcovoiturage.Planned,
|
||||
// },
|
||||
// },
|
||||
// }, nil
|
||||
// }
|
||||
Reference in New Issue
Block a user