parent
5593f8d563
commit
c03fcb31d6
|
@ -7,42 +7,53 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
||||||
|
"github.com/google/uuid"
|
||||||
geojson "github.com/paulmach/go.geojson"
|
geojson "github.com/paulmach/go.geojson"
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Request) {
|
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")
|
cacheid := uuid.NewString()
|
||||||
// lastname := r.FormValue("last_name")
|
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
|
||||||
departure := r.FormValue("departure")
|
|
||||||
destination := r.FormValue("destination")
|
if r.Method == "POST" {
|
||||||
//date := r.FormValue("date")
|
|
||||||
|
DepartureAddress := r.FormValue("departure");
|
||||||
|
DestinationAddress := r.FormValue("destination");
|
||||||
|
PickupDate := r.FormValue("date");
|
||||||
|
|
||||||
|
layout := "2006-01-02T15:04"
|
||||||
|
dateParsed, err := time.Parse(layout, PickupDate)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
departuregeo *geojson.Feature
|
departuregeo *geojson.Feature
|
||||||
destinationgeo *geojson.Feature
|
destinationgeo *geojson.Feature
|
||||||
)
|
)
|
||||||
|
|
||||||
departureTime := time.Now()
|
timestamp := timestamppb.New(dateParsed)
|
||||||
|
|
||||||
timestamp := timestamppb.New(departureTime)
|
if PickupDate != "" && DepartureAddress != "" && DestinationAddress != "" {
|
||||||
|
|
||||||
if departure != "" && destination != "" {
|
|
||||||
// searched = true
|
// searched = true
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
departuregeo, err = geojson.UnmarshalFeature([]byte(departure))
|
departuregeo, err = geojson.UnmarshalFeature([]byte(DepartureAddress))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
destinationgeo, err = geojson.UnmarshalFeature([]byte(destination))
|
destinationgeo, err = geojson.UnmarshalFeature([]byte(DestinationAddress))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
@ -52,42 +63,61 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
|
||||||
fmt.Println(departuregeo, destinationgeo, "departuregeo")
|
fmt.Println(departuregeo, destinationgeo, "departuregeo")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
request := &solidarity_service.DriverJourneysRequest{
|
request := &solidarity_service.DriverJourneysRequest{
|
||||||
DepartureDate: timestamp,
|
DepartureDate: timestamp,
|
||||||
Departure: &solidarity_service.Feature{
|
Departure: &solidarity_service.Feature{
|
||||||
Lat: departuregeo.Geometry.Point[0],
|
Lat: departuregeo.Geometry.Point[0],
|
||||||
Long: departuregeo.Geometry.Point[1],
|
Long: departuregeo.Geometry.Point[1],
|
||||||
Address: departure,
|
Address: DepartureAddress,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
drivers, err := h.services.GRPC.SolidarityService.DriverJourneys(context.TODO(), request)
|
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 {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("drivers: ", drivers)
|
fmt.Println("request: ", request)
|
||||||
h.Renderer.SolidarityServiceBookingList(w, r, drivers)
|
h.Renderer.SolidarityServiceBookingListDrivers(w, r, drivers, accounts, &booking, cacheid)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
departureTime := time.Now()
|
|
||||||
|
|
||||||
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{
|
request := &solidarity_service.DriverJourneysRequest{
|
||||||
DepartureDate: timestamp,
|
DepartureDate: timestamp,
|
||||||
Departure: &solidarity_service.Feature{
|
Departure: &solidarity_service.Feature{
|
||||||
Lat: 0,
|
Lat: 0,
|
||||||
Long: 0,
|
Long: 0,
|
||||||
Address: "Null Island (default)",
|
Address: DepartureAddress,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
drivers, err := h.services.GRPC.SolidarityService.DriverJourneys(context.TODO(), request)
|
drivers, err := h.services.GRPC.SolidarityService.DriverJourneys(context.TODO(), request)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -95,8 +125,46 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
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)
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
2
main.go
2
main.go
|
@ -139,6 +139,8 @@ func main() {
|
||||||
|
|
||||||
//=================================silvermobi====================================
|
//=================================silvermobi====================================
|
||||||
application.HandleFunc("/solidarity_service/", applicationHandler.DriversJourney)
|
application.HandleFunc("/solidarity_service/", applicationHandler.DriversJourney)
|
||||||
|
//application.HandleFunc("/solidarity_service/", applicationHandler.CreatePendingBooking)
|
||||||
|
|
||||||
|
|
||||||
appGroup := application.PathPrefix("/group_module").Subrouter()
|
appGroup := application.PathPrefix("/group_module").Subrouter()
|
||||||
appGroup.HandleFunc("/", applicationHandler.Groups)
|
appGroup.HandleFunc("/", applicationHandler.Groups)
|
||||||
|
|
|
@ -34,7 +34,7 @@ func (renderer *Renderer) BeneficiariesList(w http.ResponseWriter, r *http.Reque
|
||||||
|
|
||||||
state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
|
state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
|
||||||
state.ViewState = BeneficiariesListState{
|
state.ViewState = BeneficiariesListState{
|
||||||
Count: len(accounts),
|
Count: len(accounts),
|
||||||
CacheId: cacheid,
|
CacheId: cacheid,
|
||||||
Beneficiaries: accounts,
|
Beneficiaries: accounts,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,69 @@
|
||||||
package renderer
|
package renderer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||||
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
const solidarityserviceMenu = "solidarity_service"
|
const solidarityserviceMenu = "solidarity_service"
|
||||||
|
|
||||||
func (renderer *Renderer) SolidarityServiceBookingList(w http.ResponseWriter, r *http.Request, drivers *solidarity_service.DriverJourneysResponse) {
|
|
||||||
|
type SolidarityListState struct {
|
||||||
|
Count int `json:"count"`
|
||||||
|
CacheId string `json:"cache_id"`
|
||||||
|
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
|
||||||
|
Drivers *solidarity_service.DriverJourneysResponse `json:"drivers"`
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s SolidarityListState) JSON() template.JS {
|
||||||
|
result, _ := json.Marshal(s)
|
||||||
|
return template.JS(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s SolidarityListState) JSONWithLimits(a int, b int) template.JS {
|
||||||
|
if b < len(s.Beneficiaries) {
|
||||||
|
s.Beneficiaries = s.Beneficiaries[a:b]
|
||||||
|
}
|
||||||
|
return s.JSON()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (renderer *Renderer) SolidarityService(w http.ResponseWriter, r *http.Request, drivers *solidarity_service.DriverJourneysResponse, accounts []mobilityaccountsstorage.Account, cacheid string) {
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
||||||
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
||||||
state.ViewState = map[string]any{
|
state.ViewState = SolidarityListState {
|
||||||
"drivers": drivers,
|
Count: len(accounts),
|
||||||
|
Beneficiaries: accounts,
|
||||||
|
CacheId: cacheid,
|
||||||
|
Drivers: drivers,
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.Render("solidarity_service", w, r, files, state)
|
renderer.Render("solidarity_service", w, r, files, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (renderer *Renderer) SolidarityServiceBookingCreate(w http.ResponseWriter, r *http.Request) {
|
func (renderer *Renderer) SolidarityServiceBooking(w http.ResponseWriter, r *http.Request, booking *solidarity_service.BookingSolidarityRequest) {
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
||||||
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
||||||
|
state.ViewState = map[string]any{
|
||||||
|
"booking": booking,
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.Render("solidarity_service", w, r, files, state)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (renderer *Renderer) SolidarityServiceBookingListDrivers(w http.ResponseWriter, r *http.Request, drivers *solidarity_service.DriverJourneysResponse, accounts []mobilityaccountsstorage.Account, booking *solidarity_service.BookingSolidarityRequest, cacheid string) {
|
||||||
|
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
||||||
|
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
||||||
|
state.ViewState = SolidarityListState {
|
||||||
|
Count: len(accounts),
|
||||||
|
Beneficiaries: accounts,
|
||||||
|
CacheId: cacheid,
|
||||||
|
Drivers: drivers,
|
||||||
|
}
|
||||||
|
|
||||||
renderer.Render("solidarity_service", w, r, files, state)
|
renderer.Render("solidarity_service", w, r, files, state)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue