list beneficiaries
+ select beneficiary
This commit is contained in:
@@ -7,42 +7,53 @@ import (
|
||||
"time"
|
||||
|
||||
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
||||
"github.com/google/uuid"
|
||||
geojson "github.com/paulmach/go.geojson"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
|
||||
func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if r.Method == "POST" {
|
||||
accounts, err := h.beneficiaries(r)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// firstname := r.FormValue("first_name")
|
||||
// lastname := r.FormValue("last_name")
|
||||
departure := r.FormValue("departure")
|
||||
destination := r.FormValue("destination")
|
||||
//date := r.FormValue("date")
|
||||
cacheid := uuid.NewString()
|
||||
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
|
||||
|
||||
if r.Method == "POST" {
|
||||
|
||||
DepartureAddress := r.FormValue("departure");
|
||||
DestinationAddress := r.FormValue("destination");
|
||||
PickupDate := r.FormValue("date");
|
||||
|
||||
layout := "2006-01-02T15:04"
|
||||
dateParsed, err := time.Parse(layout, PickupDate)
|
||||
|
||||
var (
|
||||
departuregeo *geojson.Feature
|
||||
destinationgeo *geojson.Feature
|
||||
)
|
||||
|
||||
departureTime := time.Now()
|
||||
timestamp := timestamppb.New(dateParsed)
|
||||
|
||||
timestamp := timestamppb.New(departureTime)
|
||||
|
||||
if departure != "" && destination != "" {
|
||||
if PickupDate != "" && DepartureAddress != "" && DestinationAddress != "" {
|
||||
// searched = true
|
||||
|
||||
var err error
|
||||
|
||||
departuregeo, err = geojson.UnmarshalFeature([]byte(departure))
|
||||
departuregeo, err = geojson.UnmarshalFeature([]byte(DepartureAddress))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
destinationgeo, err = geojson.UnmarshalFeature([]byte(destination))
|
||||
destinationgeo, err = geojson.UnmarshalFeature([]byte(DestinationAddress))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
@@ -52,42 +63,61 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
|
||||
fmt.Println(departuregeo, destinationgeo, "departuregeo")
|
||||
}
|
||||
|
||||
|
||||
request := &solidarity_service.DriverJourneysRequest{
|
||||
DepartureDate: timestamp,
|
||||
Departure: &solidarity_service.Feature{
|
||||
Lat: departuregeo.Geometry.Point[0],
|
||||
Long: departuregeo.Geometry.Point[1],
|
||||
Address: departure,
|
||||
Address: DepartureAddress,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
drivers, err := h.services.GRPC.SolidarityService.DriverJourneys(context.TODO(), request)
|
||||
|
||||
|
||||
booking := solidarity_service.BookingSolidarityRequest {
|
||||
PassengerId: r.FormValue("account_id"),
|
||||
DepartureAddress: &solidarity_service.Feature{
|
||||
Lat: departuregeo.Geometry.Point[0],
|
||||
Long: departuregeo.Geometry.Point[1],
|
||||
Address: DepartureAddress,
|
||||
},
|
||||
DestinationAddress: &solidarity_service.Feature{
|
||||
Lat: destinationgeo.Geometry.Point[0],
|
||||
Long: destinationgeo.Geometry.Point[1],
|
||||
Address: DepartureAddress,
|
||||
},
|
||||
PickupDate : timestamp,
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("drivers: ", drivers)
|
||||
h.Renderer.SolidarityServiceBookingList(w, r, drivers)
|
||||
fmt.Println("request: ", request)
|
||||
h.Renderer.SolidarityServiceBookingListDrivers(w, r, drivers, accounts, &booking, cacheid)
|
||||
|
||||
} else {
|
||||
departureTime := time.Now()
|
||||
} else {
|
||||
|
||||
timestamp := timestamppb.New(departureTime)
|
||||
DepartureAddress := "0 rue A";
|
||||
PickupDate := r.FormValue("date");
|
||||
|
||||
layout := "2006-01-02T15:04"
|
||||
dateParsed, err := time.Parse(layout, PickupDate)
|
||||
|
||||
timestamp := timestamppb.New(dateParsed)
|
||||
|
||||
request := &solidarity_service.DriverJourneysRequest{
|
||||
DepartureDate: timestamp,
|
||||
Departure: &solidarity_service.Feature{
|
||||
Lat: 0,
|
||||
Long: 0,
|
||||
Address: "Null Island (default)",
|
||||
Address: DepartureAddress,
|
||||
},
|
||||
}
|
||||
|
||||
drivers, err := h.services.GRPC.SolidarityService.DriverJourneys(context.TODO(), request)
|
||||
|
||||
if err != nil {
|
||||
@@ -95,8 +125,46 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
h.Renderer.SolidarityServiceBookingList(w, r, drivers)
|
||||
|
||||
h.Renderer.SolidarityService(w, r, drivers, accounts, cacheid)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// func (h *ApplicationHandler) CreatePendingBooking(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// if r.Method == "POST" {
|
||||
|
||||
// formvalue := solidarity_service.BookingSolidarityRequest{
|
||||
// PassengerId : "0",
|
||||
// DriverId : "0",
|
||||
// // Status : "0",
|
||||
// DepartureAddress : booking.DepartureAddress,
|
||||
// DestinationAddress : booking.DestinationAddress,
|
||||
// PickupDate : booking.PickupDate,
|
||||
// }
|
||||
|
||||
// request := &solidarity_service.BookingSolidarityRequest{
|
||||
// // Id
|
||||
// PassengerId : formvalue.PassengerId,
|
||||
// DriverId : formvalue.DriverId,
|
||||
// //Status : formvalue.Status,
|
||||
// DepartureAddress : booking.DepartureAddress,
|
||||
// DestinationAddress : booking.DestinationAddress,
|
||||
// PickupDate : formvalue.PickupDate,
|
||||
// }
|
||||
|
||||
// booking, err := h.services.GRPC.SolidarityService.CreateBookingSolidarity(context.TODO(), request)
|
||||
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// w.WriteHeader(http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
|
||||
// h.Renderer.SolidarityServiceBooking(w, r , booking)
|
||||
|
||||
// }
|
||||
|
||||
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user