fix form and request
This commit is contained in:
parent
4232bca50d
commit
5593f8d563
|
@ -534,7 +534,7 @@ func parseBeneficiariesForm(r *http.Request) (map[string]any, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
date = &d
|
date = &d
|
||||||
}
|
}
|
||||||
|
|
||||||
formData := BeneficiariesForm{
|
formData := BeneficiariesForm{
|
||||||
|
|
|
@ -1,44 +1,102 @@
|
||||||
package application
|
package application
|
||||||
|
|
||||||
// import (
|
import (
|
||||||
// "context"
|
"context"
|
||||||
// "fmt"
|
"fmt"
|
||||||
// "net/http"
|
"net/http"
|
||||||
// "time"
|
"time"
|
||||||
|
|
||||||
// solidarity_service "git.coopgo.io/coopgo-apps/silvermobi/servers/grpcapi/proto"
|
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
||||||
// "google.golang.org/protobuf/types/known/timestamppb"
|
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" {
|
||||||
|
|
||||||
|
// firstname := r.FormValue("first_name")
|
||||||
|
// lastname := r.FormValue("last_name")
|
||||||
|
departure := r.FormValue("departure")
|
||||||
|
destination := r.FormValue("destination")
|
||||||
|
//date := r.FormValue("date")
|
||||||
|
|
||||||
|
var (
|
||||||
|
departuregeo *geojson.Feature
|
||||||
|
destinationgeo *geojson.Feature
|
||||||
|
)
|
||||||
|
|
||||||
|
departureTime := time.Now()
|
||||||
|
|
||||||
|
timestamp := timestamppb.New(departureTime)
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(departuregeo, destinationgeo, "departuregeo")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
request := &solidarity_service.DriverJourneysRequest{
|
||||||
// func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Request) {
|
DepartureDate: timestamp,
|
||||||
|
Departure: &solidarity_service.Feature{
|
||||||
// if r.Method == "POST" {
|
Lat: departuregeo.Geometry.Point[0],
|
||||||
|
Long: departuregeo.Geometry.Point[1],
|
||||||
// departureTime := time.Now()
|
Address: departure,
|
||||||
|
},
|
||||||
// timestamp := timestamppb.New(departureTime)
|
}
|
||||||
|
|
||||||
// request := &solidarity_service.DriverJourneysRequest{
|
|
||||||
// DepartureDate: timestamp,
|
|
||||||
// Departure: &solidarity_service.Feature{
|
|
||||||
// Lat: 0,
|
|
||||||
// Long: 0,
|
|
||||||
// Address: "7 rue D",
|
|
||||||
// },
|
|
||||||
// }
|
|
||||||
// _, 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, 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)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
2
main.go
2
main.go
|
@ -138,7 +138,7 @@ func main() {
|
||||||
/*********************** CODE GROUP **************************/
|
/*********************** CODE GROUP **************************/
|
||||||
|
|
||||||
//=================================silvermobi====================================
|
//=================================silvermobi====================================
|
||||||
//application.HandleFunc("/solidarity_service/", applicationHandler.DriversJourney)
|
application.HandleFunc("/solidarity_service/", applicationHandler.DriversJourney)
|
||||||
|
|
||||||
appGroup := application.PathPrefix("/group_module").Subrouter()
|
appGroup := application.PathPrefix("/group_module").Subrouter()
|
||||||
appGroup.HandleFunc("/", applicationHandler.Groups)
|
appGroup.HandleFunc("/", applicationHandler.Groups)
|
||||||
|
|
|
@ -23,7 +23,7 @@ func (s BeneficiariesListState) JSON() template.JS {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s BeneficiariesListState) JSONWithLimits(a int, b int) template.JS {
|
func (s BeneficiariesListState) JSONWithLimits(a int, b int) template.JS {
|
||||||
if b < len(s.Beneficiaries) {
|
if b < len(s.Beneficiaries) {
|
||||||
s.Beneficiaries = s.Beneficiaries[a:b]
|
s.Beneficiaries = s.Beneficiaries[a:b]
|
||||||
}
|
}
|
||||||
return s.JSON()
|
return s.JSON()
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
package renderer
|
package renderer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
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) {
|
func (renderer *Renderer) SolidarityServiceBookingList(w http.ResponseWriter, r *http.Request, drivers *solidarity_service.DriverJourneysResponse) {
|
||||||
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.ViewState = map[string]any{
|
||||||
|
"drivers": drivers,
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.Render("solidarity_service", w, r, files, state)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (renderer *Renderer) SolidarityServiceBookingCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
||||||
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
||||||
|
|
||||||
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) {
|
|
||||||
files:= renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
|
||||||
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
|
||||||
|
|
||||||
renderer.Render("solidarity_service", w, r, files, state)
|
|
||||||
fmt.Println("renderer")
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue