2024-04-24 14:05:21 +00:00
|
|
|
package application
|
2024-04-24 08:22:23 +00:00
|
|
|
|
2024-08-28 12:10:03 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
2024-08-02 13:02:35 +00:00
|
|
|
|
2024-08-28 12:10:03 +00:00
|
|
|
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
|
|
|
geojson "github.com/paulmach/go.geojson"
|
|
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
|
|
)
|
2024-04-24 08:22:23 +00:00
|
|
|
|
2024-08-28 12:10:03 +00:00
|
|
|
func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Request) {
|
2024-04-24 14:05:21 +00:00
|
|
|
|
2024-08-28 12:10:03 +00:00
|
|
|
if r.Method == "POST" {
|
2024-04-24 08:22:23 +00:00
|
|
|
|
2024-08-28 12:10:03 +00:00
|
|
|
// firstname := r.FormValue("first_name")
|
|
|
|
// lastname := r.FormValue("last_name")
|
|
|
|
departure := r.FormValue("departure")
|
|
|
|
destination := r.FormValue("destination")
|
|
|
|
//date := r.FormValue("date")
|
2024-06-07 09:51:01 +00:00
|
|
|
|
2024-08-28 12:10:03 +00:00
|
|
|
var (
|
|
|
|
departuregeo *geojson.Feature
|
|
|
|
destinationgeo *geojson.Feature
|
|
|
|
)
|
2024-04-24 08:22:23 +00:00
|
|
|
|
2024-08-28 12:10:03 +00:00
|
|
|
departureTime := time.Now()
|
2024-08-02 13:02:35 +00:00
|
|
|
|
2024-08-28 12:10:03 +00:00
|
|
|
timestamp := timestamppb.New(departureTime)
|
2024-04-24 08:22:23 +00:00
|
|
|
|
2024-08-28 12:10:03 +00:00
|
|
|
if departure != "" && destination != "" {
|
|
|
|
// searched = true
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
departuregeo, err = geojson.UnmarshalFeature([]byte(departure))
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
destinationgeo, err = geojson.UnmarshalFeature([]byte(destination))
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
}
|
2024-08-02 13:02:35 +00:00
|
|
|
|
2024-08-28 12:10:03 +00:00
|
|
|
fmt.Println(departuregeo, destinationgeo, "departuregeo")
|
|
|
|
}
|
2024-08-02 13:02:35 +00:00
|
|
|
|
2024-04-24 14:05:21 +00:00
|
|
|
|
2024-08-28 12:10:03 +00:00
|
|
|
request := &solidarity_service.DriverJourneysRequest{
|
|
|
|
DepartureDate: timestamp,
|
|
|
|
Departure: &solidarity_service.Feature{
|
|
|
|
Lat: departuregeo.Geometry.Point[0],
|
|
|
|
Long: departuregeo.Geometry.Point[1],
|
|
|
|
Address: departure,
|
|
|
|
},
|
|
|
|
}
|
2024-08-02 13:02:35 +00:00
|
|
|
|
|
|
|
|
2024-08-28 12:10:03 +00:00
|
|
|
drivers, err := h.services.GRPC.SolidarityService.DriverJourneys(context.TODO(), request)
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("drivers: ", drivers)
|
|
|
|
h.Renderer.SolidarityServiceBookingList(w, r, drivers)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
departureTime := time.Now()
|
|
|
|
|
|
|
|
timestamp := timestamppb.New(departureTime)
|
|
|
|
|
|
|
|
request := &solidarity_service.DriverJourneysRequest{
|
|
|
|
DepartureDate: timestamp,
|
|
|
|
Departure: &solidarity_service.Feature{
|
|
|
|
Lat: 0,
|
|
|
|
Long: 0,
|
|
|
|
Address: "Null Island (default)",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
drivers, err := h.services.GRPC.SolidarityService.DriverJourneys(context.TODO(), request)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
h.Renderer.SolidarityServiceBookingList(w, r, drivers)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|