Many improvements

This commit is contained in:
Arnaud Delcasse
2025-09-16 08:54:51 +02:00
parent 9ab7b66b68
commit 8c0b6f7d5c
15 changed files with 367 additions and 31 deletions

View File

@@ -128,16 +128,18 @@ func (h *ApplicationHandler) AdministrationCreateGroup(w http.ResponseWriter, r
}
modules := map[string]any{
"beneficiaries": r.FormValue("modules.beneficiaries") == "on",
"journeys": r.FormValue("modules.journeys") == "on",
"vehicles": r.FormValue("modules.vehicles") == "on",
"vehicles_management": r.FormValue("modules.vehicles_management") == "on",
"events": r.FormValue("modules.events") == "on",
"agenda": r.FormValue("modules.agenda") == "on",
"groups": r.FormValue("modules.groups") == "on",
"administration": r.FormValue("modules.administration") == "on",
"support": r.FormValue("modules.support") == "on",
"group_module": r.FormValue("modules.group_module") == "on",
"beneficiaries": r.FormValue("modules.beneficiaries") == "on",
"journeys": r.FormValue("modules.journeys") == "on",
"vehicles": r.FormValue("modules.vehicles") == "on",
"vehicles_management": r.FormValue("modules.vehicles_management") == "on",
"events": r.FormValue("modules.events") == "on",
"agenda": r.FormValue("modules.agenda") == "on",
"groups": r.FormValue("modules.groups") == "on",
"administration": r.FormValue("modules.administration") == "on",
"support": r.FormValue("modules.support") == "on",
"group_module": r.FormValue("modules.group_module") == "on",
"organized_carpool": r.FormValue("modules.organized_carpool") == "on",
"solidarity_transport": r.FormValue("modules.solidarity_transport") == "on",
}
groupid := uuid.NewString()

View File

@@ -313,6 +313,7 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
Passengerid: beneficiaryID,
StartDate: timestamppb.New(time.Now().Add(-36 * 730 * time.Hour)),
EndDate: timestamppb.New(time.Now().Add(12 * 730 * time.Hour)),
Status: "VALIDATED",
})
solidarityTransportStats := map[string]int64{
"count": 0,

View File

@@ -65,7 +65,8 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
destination := r.FormValue("destination")
kb_results := []any{}
searched := false
passengerid := r.FormValue("passengerid")
solidarityTransportExcludeDriver := r.FormValue("solidarity_transport_exclude_driver")
var (
departuregeo *geojson.Feature
@@ -74,11 +75,26 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
// carpoolresults []any
)
if departuredate != "" && departuretime != "" && departure != "" && destination != "" {
searched = true
var err error
if departure == "" && passengerid != "" {
log.Debug().Msg("departure empty and passengerid set")
p, err := h.services.GetAccount(passengerid)
if err != nil {
log.Error().Err(err).Msg("could not retrieve passenger")
w.WriteHeader(http.StatusNotFound)
return
}
departureBytes, err := json.Marshal(p.Data["address"])
if err != nil {
log.Error().Err(err).Any("address", p.Data["address"]).Msg("could not marshal address")
} else {
departuregeo, err = geojson.UnmarshalFeature(departureBytes)
}
}
var err error
searched := false
if departure != "" {
log.Debug().Str("departure", departure).Msg("departure value")
departuregeo, err = geojson.UnmarshalFeature([]byte(departure))
if err != nil {
log.Error().Err(err).Msg("error unmarshalling departure")
@@ -86,12 +102,19 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
return
}
}
if destination != "" {
destinationgeo, err = geojson.UnmarshalFeature([]byte(destination))
if err != nil {
log.Error().Err(err).Msg("error unmarshalling destination")
w.WriteHeader(http.StatusBadRequest)
return
}
}
if departuredate != "" && departuretime != "" && departure != "" && destination != "" {
searched = true
// SOLIDARITY TRANSPORT
drivers, err = h.services.GetAccountsInNamespacesMap([]string{"solidarity_drivers", "organized_carpool_drivers"})
@@ -121,6 +144,9 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
}
}
}
if dj.DriverId == solidarityTransportExcludeDriver {
continue
}
if !yield(dj) {
return
}
@@ -247,7 +273,7 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
return
}
h.Renderer.JourneysSearch(w, r, carpool_results, transit_results, vehicle_results, searched, departuregeo, destinationgeo, departuredate, departuretime, driverJourneys, drivers, organizedCarpools, beneficiaries, kb_results)
h.Renderer.JourneysSearch(w, r, carpool_results, transit_results, vehicle_results, searched, departuregeo, destinationgeo, departuredate, departuretime, driverJourneys, drivers, organizedCarpools, beneficiaries, kb_results, passengerid)
}
func (h *ApplicationHandler) vehicleRequest(vehiclech chan fleetsstorage.Vehicle, start time.Time, end time.Time) {

View File

@@ -144,6 +144,54 @@ func (h *ApplicationHandler) OrganizedCarpoolCreateDriver(w http.ResponseWriter,
h.Renderer.OrganizedCarpoolCreateDriver(w, r)
}
func (h *ApplicationHandler) OrganizedCarpoolUpdateDriver(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
driverID := vars["driverid"]
driver, err := h.services.GetAccount(driverID)
if err != nil {
log.Error().Err(err).Msg("Issue retrieving driver account")
w.WriteHeader(http.StatusInternalServerError)
return
}
if r.Method == "POST" {
dataMap, err := parseOrganizedCarpoolDriversUpdateForm(r)
if err != nil {
log.Error().Err(err).Msg("")
w.WriteHeader(http.StatusBadRequest)
return
}
data, err := structpb.NewValue(dataMap)
if err != nil {
log.Error().Err(err).Msg("")
w.WriteHeader(http.StatusInternalServerError)
return
}
request := &mobilityaccounts.UpdateDataRequest{
Account: &mobilityaccounts.Account{
Id: driverID,
Namespace: "organized_carpool_drivers",
Data: data.GetStructValue(),
},
}
resp, err := h.services.GRPC.MobilityAccounts.UpdateData(context.TODO(), request)
if err != nil {
log.Error().Err(err).Msg("")
w.WriteHeader(http.StatusInternalServerError)
return
}
http.Redirect(w, r, fmt.Sprintf("/app/organized-carpool/drivers/%s", resp.Account.Id), http.StatusFound)
return
}
h.Renderer.OrganizedCarpoolUpdateDriver(w, r, driver)
}
func (h *ApplicationHandler) OrganizedCarpoolDriverDisplay(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
driverID := vars["driverid"]
@@ -637,3 +685,76 @@ func parseOrganizedCarpoolDriversForm(r *http.Request) (map[string]any, error) {
return dataMap, nil
}
func parseOrganizedCarpoolDriversUpdateForm(r *http.Request) (map[string]any, error) {
if err := r.ParseForm(); err != nil {
return nil, err
}
log.Info().Any("form content", r.Form).Msg("parsing update form")
var date *time.Time
if r.PostFormValue("birthdate") != "" {
d, err := time.Parse("2006-01-02", r.PostFormValue("birthdate"))
if err != nil {
return nil, err
}
date = &d
}
formData := OrganizedCarpoolDriversForm{
FirstName: r.PostFormValue("first_name"),
LastName: r.PostFormValue("last_name"),
Email: r.PostFormValue("email"),
Birthdate: date,
PhoneNumber: r.PostFormValue("phone_number"),
FileNumber: r.PostFormValue("file_number"),
Gender: r.PostFormValue("gender"),
}
if r.PostFormValue("address") != "" {
var a any
json.Unmarshal([]byte(r.PostFormValue("address")), &a)
formData.Address = a
}
if r.PostFormValue("address_destination") != "" {
var a any
json.Unmarshal([]byte(r.PostFormValue("address_destination")), &a)
formData.AddressDestination = a
}
validate := formvalidators.New()
if err := validate.Struct(formData); err != nil {
return nil, err
}
d, err := json.Marshal(formData)
if err != nil {
return nil, err
}
var dataMap map[string]any
err = json.Unmarshal(d, &dataMap)
if err != nil {
return nil, err
}
// Handle other_properties for update form
if r.PostFormValue("other_properties") != "" {
var otherProps map[string]any
if err := json.Unmarshal([]byte(r.PostFormValue("other_properties")), &otherProps); err == nil {
if dataMap["other_properties"] == nil {
dataMap["other_properties"] = make(map[string]any)
}
for k, v := range otherProps {
dataMap["other_properties"].(map[string]any)[k] = v
}
}
}
return dataMap, nil
}

View File

@@ -4,6 +4,7 @@ import (
"context"
"net/http"
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/proto/gen"
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/transformers"
"github.com/gorilla/mux"
@@ -72,6 +73,32 @@ func (h *ApplicationHandler) SolidarityTransportExternalBookingProposal(w http.R
w.WriteHeader(http.StatusInternalServerError)
return
}
// NOTIFY GROUP MEMBERS
groupsrequest := &groupsmanagement.GetGroupsRequest{
Namespaces: []string{"parcoursmob_organizations"},
Member: booking.PassengerId,
}
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroups(context.TODO(), groupsrequest)
if err != nil {
log.Error().Err(err).Msg("")
}
if len(groupsresp.Groups) > 0 {
members, _, err := h.groupmembers(groupsresp.Groups[0].Id)
if err != nil {
log.Error().Err(err).Msg("could not retrieve groupe members")
} else {
for _, m := range members {
if email, ok := m.Data["email"].(string); ok {
h.emailing.Send("solidarity_transport.booking_driver_decline", email, map[string]string{
"bookingid": booking.Id,
"baseUrl": h.config.GetString("base_url"),
})
}
}
}
}
}
}
}

View File

@@ -52,6 +52,15 @@ const (
)
func (h *ApplicationHandler) SolidarityTransportOverview(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
tab := r.FormValue("tab")
startdateStr := r.FormValue("date_start")
enddateStr := r.FormValue("date_end")
bookingstatusStr := r.FormValue("status")
filters := map[string]string{}
hist_filters := map[string]string{}
accounts, err := h.solidarityDrivers(r)
if err != nil {
log.Error().Err(err).Msg("issue getting solidarity drivers")
@@ -69,9 +78,32 @@ func (h *ApplicationHandler) SolidarityTransportOverview(w http.ResponseWriter,
beneficiariesMap = map[string]mobilityaccountsstorage.Account{}
}
// Get filters
startdate := time.Now()
enddate := time.Now().Add(24 * 365 * time.Hour)
bookingstatus := ""
if tab == "solidarityService" {
if startdateStr != "" {
startdate, _ = time.Parse("2006-01-02", startdateStr)
}
if enddateStr != "" {
enddate, _ = time.Parse("2006-01-02", enddateStr)
enddate = enddate.Add(24 * time.Hour)
}
bookingstatus = bookingstatusStr
filters = map[string]string{
"tab": tab,
"date_start": startdateStr,
"date_end": enddateStr,
"status": bookingstatusStr,
}
}
bookingsproto, err := h.services.GRPC.SolidarityTransport.GetSolidarityTransportBookings(context.Background(), &gen.GetSolidarityTransportBookingsRequest{
StartDate: timestamppb.Now(),
EndDate: timestamppb.New(time.Now().Add(24 * 365 * time.Hour)),
StartDate: timestamppb.New(startdate),
EndDate: timestamppb.New(enddate),
Status: bookingstatus,
})
if err != nil {
log.Error().Err(err).Msg("issue retreving bookings")
@@ -85,9 +117,33 @@ func (h *ApplicationHandler) SolidarityTransportOverview(w http.ResponseWriter,
bookings = append(bookings, booking)
}
}
// filters
hist_enddate := time.Now()
hist_startdate := time.Now().Add(-1 * 24 * 365 * time.Hour)
hist_bookingstatus := ""
if tab == "solidarityHistory" {
if startdateStr != "" {
hist_startdate, _ = time.Parse("2006-01-02", startdateStr)
}
if enddateStr != "" {
enddate, _ = time.Parse("2006-01-02", enddateStr)
hist_enddate = enddate.Add(24 * time.Hour)
}
hist_bookingstatus = bookingstatusStr
hist_filters = map[string]string{
"tab": tab,
"date_start": startdateStr,
"date_end": enddateStr,
"status": bookingstatusStr,
}
}
bookingshistoryproto, err := h.services.GRPC.SolidarityTransport.GetSolidarityTransportBookings(context.Background(), &gen.GetSolidarityTransportBookingsRequest{
EndDate: timestamppb.Now(),
StartDate: timestamppb.New(time.Now().Add(-1 * 24 * 365 * time.Hour)),
EndDate: timestamppb.New(hist_enddate),
StartDate: timestamppb.New(hist_startdate),
Status: hist_bookingstatus,
})
if err != nil {
log.Error().Err(err).Msg("issue retreving bookings")
@@ -115,7 +171,7 @@ func (h *ApplicationHandler) SolidarityTransportOverview(w http.ResponseWriter,
return cmp.Compare(a.Journey.PassengerPickupDate.Unix(), b.Journey.PassengerPickupDate.Unix())
})
h.Renderer.SolidarityTransportOverview(w, r, accounts, accountsMap, beneficiariesMap, bookings, bookingshistory)
h.Renderer.SolidarityTransportOverview(w, r, accounts, accountsMap, beneficiariesMap, bookings, bookingshistory, filters, hist_filters, tab)
}
func (h *ApplicationHandler) SolidarityTransportCreateDriver(w http.ResponseWriter, r *http.Request) {