Compare commits
30 Commits
groupsCovo
...
vehicleLis
| Author | SHA1 | Date | |
|---|---|---|---|
| f09d9d0a16 | |||
|
|
11e2375456 | ||
|
|
e11514b6d5 | ||
|
|
3bfce72512 | ||
|
|
335656ec75 | ||
| f698891865 | |||
|
|
5d33ba3dcb | ||
| 193f5dfb6f | |||
|
|
af9626e2c4 | ||
| 49de2f22c4 | |||
|
|
d3df781e33 | ||
| ab8cbf6f73 | |||
| 10bde53c5e | |||
| 28c8fa8a90 | |||
| 11851fec61 | |||
| 696cd1d87f | |||
|
|
372647b3b9 | ||
|
|
56c1b45f45 | ||
|
|
62f64747c3 | ||
| 56d0914568 | |||
|
|
57accbddbb | ||
|
|
40cf6012a6 | ||
|
|
774a3c2301 | ||
| 1b847ea216 | |||
| 0c0a9d0496 | |||
|
|
e03f31d3f4 | ||
|
|
a2b644d548 | ||
|
|
d531fe63ff | ||
|
|
47a2b1a3cb | ||
|
|
d9f5721a15 |
4
go.mod
4
go.mod
@@ -4,11 +4,11 @@ go 1.18
|
|||||||
|
|
||||||
// replace git.coopgo.io/coopgo-platform/mobility-accounts => ../../coopgo-platform/mobility-accounts/
|
// replace git.coopgo.io/coopgo-platform/mobility-accounts => ../../coopgo-platform/mobility-accounts/
|
||||||
|
|
||||||
//replace git.coopgo.io/coopgo-platform/groups-management => ../../coopgo-platform/groups-management/
|
replace git.coopgo.io/coopgo-platform/groups-management => ../../coopgo-platform/groups-management/
|
||||||
|
|
||||||
// replace git.coopgo.io/coopgo-platform/fleets => ../../coopgo-platform/fleets/
|
// replace git.coopgo.io/coopgo-platform/fleets => ../../coopgo-platform/fleets/
|
||||||
|
|
||||||
// replace git.coopgo.io/coopgo-platform/agenda => ../../coopgo-platform/agenda/
|
replace git.coopgo.io/coopgo-platform/agenda => ../../coopgo-platform/agenda/
|
||||||
|
|
||||||
// replace git.coopgo.io/coopgo-platform/emailing => ../../coopgo-platform/emailing/
|
// replace git.coopgo.io/coopgo-platform/emailing => ../../coopgo-platform/emailing/
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
||||||
|
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
|
||||||
|
"git.coopgo.io/coopgo-platform/fleets/storage"
|
||||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||||
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||||
accounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
accounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||||
@@ -86,6 +88,8 @@ func (h *ApplicationHandler) AdministrationCreateGroup(w http.ResponseWriter, r
|
|||||||
"agenda": r.FormValue("modules.agenda") == "on",
|
"agenda": r.FormValue("modules.agenda") == "on",
|
||||||
"groups": r.FormValue("modules.groups") == "on",
|
"groups": r.FormValue("modules.groups") == "on",
|
||||||
"administration": r.FormValue("modules.administration") == "on",
|
"administration": r.FormValue("modules.administration") == "on",
|
||||||
|
"support": r.FormValue("modules.support") == "on",
|
||||||
|
"group_module": r.FormValue("modules.group_module") == "on",
|
||||||
}
|
}
|
||||||
|
|
||||||
groupid := uuid.NewString()
|
groupid := uuid.NewString()
|
||||||
@@ -329,6 +333,31 @@ func (h *ApplicationHandler) AdministrationGroupInviteMember(w http.ResponseWrit
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h ApplicationHandler) AdminStatVehicles(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
request := &fleets.GetBookingsRequest{}
|
||||||
|
resp, err := h.services.GRPC.Fleets.GetBookings(context.TODO(), request)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
bookings := []storage.Booking{}
|
||||||
|
|
||||||
|
for _, b := range resp.Bookings {
|
||||||
|
booking := b.ToStorageType()
|
||||||
|
bookings = append(bookings, booking)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Sort(sorting.BookingsByStartdate(bookings))
|
||||||
|
|
||||||
|
vehicles, _ := h.services.GetVehiclesMap()
|
||||||
|
groups, _ := h.services.GetGroupsMap()
|
||||||
|
|
||||||
|
h.Renderer.VehicleBookingsList(w, r, bookings, vehicles, groups)
|
||||||
|
}
|
||||||
|
|
||||||
func (h *ApplicationHandler) members() ([]*accounts.Account, error) {
|
func (h *ApplicationHandler) members() ([]*accounts.Account, error) {
|
||||||
resp, err := h.services.GRPC.MobilityAccounts.GetAccounts(context.TODO(), &accounts.GetAccountsRequest{
|
resp, err := h.services.GRPC.MobilityAccounts.GetAccounts(context.TODO(), &accounts.GetAccountsRequest{
|
||||||
Namespaces: []string{"parcoursmob"},
|
Namespaces: []string{"parcoursmob"},
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
formvalidators "git.coopgo.io/coopgo-apps/parcoursmob/utils/form-validators"
|
formvalidators "git.coopgo.io/coopgo-apps/parcoursmob/utils/form-validators"
|
||||||
@@ -107,6 +108,7 @@ func (h *ApplicationHandler) AgendaCreateEvent(w http.ResponseWriter, r *http.Re
|
|||||||
Allday: eventForm.Allday,
|
Allday: eventForm.Allday,
|
||||||
MaxSubscribers: int64(eventForm.MaxSubscribers),
|
MaxSubscribers: int64(eventForm.MaxSubscribers),
|
||||||
Data: data,
|
Data: data,
|
||||||
|
Deleted: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +121,7 @@ func (h *ApplicationHandler) AgendaCreateEvent(w http.ResponseWriter, r *http.Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
http.Redirect(w, r, fmt.Sprintf("/app/agenda/%s", resp.Event.Id), http.StatusFound)
|
http.Redirect(w, r, fmt.Sprintf("/app/agenda/%s", resp.Event.Id), http.StatusFound)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
h.Renderer.AgendaCreateEvent(w, r)
|
h.Renderer.AgendaCreateEvent(w, r)
|
||||||
}
|
}
|
||||||
@@ -225,13 +227,13 @@ func (h *ApplicationHandler) AgendaSubscribeEvent(w http.ResponseWriter, r *http
|
|||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
subscriber := r.FormValue("subscriber")
|
subscriber := r.FormValue("subscriber")
|
||||||
data := map[string]any{
|
data := map[string]any{
|
||||||
"subscribed_by": map[string]any{
|
"subscribed_by": map[string]any{
|
||||||
"user": map[string]any{
|
"user": map[string]any{
|
||||||
"id": current_user_token.Subject,
|
"id": current_user_token.Subject,
|
||||||
"display_name": current_user_claims["display_name"],
|
"display_name": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
|
||||||
|
"email": current_user_claims["email"].(string),
|
||||||
},
|
},
|
||||||
"group": map[string]any{
|
"group": map[string]any{
|
||||||
"id": current_group.ID,
|
"id": current_group.ID,
|
||||||
@@ -330,11 +332,322 @@ func contains(s []*agenda.Subscription, e string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// func contains[V string](s []V, e V) bool {
|
///////////////////////////////Update Event/////////////////////////////////////////
|
||||||
// for _, a := range s {
|
func (h *ApplicationHandler) AgendaUpdateEvent(w http.ResponseWriter, r *http.Request) {
|
||||||
// if a == e {
|
adm := strings.Split(r.URL.Path, "/")
|
||||||
// return true
|
eventID := adm[3]
|
||||||
// }
|
request := &agenda.GetEventRequest{
|
||||||
// }
|
Id: eventID,
|
||||||
// return false
|
}
|
||||||
// }
|
|
||||||
|
resp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), request)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if r.Method == "POST" {
|
||||||
|
g := r.Context().Value(identification.GroupKey)
|
||||||
|
if g == nil {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
group := g.(storage.Group)
|
||||||
|
|
||||||
|
eventForm, err := parseEventsForm(r)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data, _ := structpb.NewStruct(map[string]any{
|
||||||
|
"address": eventForm.Address,
|
||||||
|
})
|
||||||
|
|
||||||
|
request := &agenda.UpdateEventRequest{
|
||||||
|
Event: &agenda.Event{
|
||||||
|
Namespace: "parcoursmob_dispositifs",
|
||||||
|
Id: eventID,
|
||||||
|
Owners: []string{group.ID},
|
||||||
|
Type: eventForm.Type,
|
||||||
|
Name: eventForm.Name,
|
||||||
|
Description: eventForm.Description,
|
||||||
|
Startdate: timestamppb.New(*eventForm.Startdate),
|
||||||
|
Enddate: timestamppb.New(*eventForm.Enddate),
|
||||||
|
Starttime: eventForm.Starttime,
|
||||||
|
Endtime: eventForm.Endtime,
|
||||||
|
Allday: eventForm.Allday,
|
||||||
|
MaxSubscribers: int64(eventForm.MaxSubscribers),
|
||||||
|
Data: data,
|
||||||
|
Subscriptions: resp.Event.Subscriptions,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.services.GRPC.Agenda.UpdateEvent(context.TODO(), request)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Redirect(w, r, fmt.Sprintf("/app/agenda/%s", resp.Event.Id), http.StatusFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.Renderer.AgendaUpdateEvent(w, r, resp.Event.ToStorageType())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ApplicationHandler) AgendaDeleteEvent(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
eventID := vars["eventid"]
|
||||||
|
request := &agenda.GetEventRequest{
|
||||||
|
Id: eventID,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), request)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.Method == "POST" {
|
||||||
|
|
||||||
|
request := &agenda.UpdateEventRequest{
|
||||||
|
Event: &agenda.Event{
|
||||||
|
Namespace: resp.Event.Namespace,
|
||||||
|
Id: resp.Event.Id,
|
||||||
|
Owners: resp.Event.Owners,
|
||||||
|
Type: resp.Event.Type,
|
||||||
|
Name: resp.Event.Name,
|
||||||
|
Description: resp.Event.Description,
|
||||||
|
Startdate: resp.Event.Startdate,
|
||||||
|
Enddate: resp.Event.Enddate,
|
||||||
|
Starttime: resp.Event.Starttime,
|
||||||
|
Endtime: resp.Event.Endtime,
|
||||||
|
Allday: resp.Event.Allday,
|
||||||
|
MaxSubscribers: int64(resp.Event.MaxSubscribers),
|
||||||
|
Data: resp.Event.Data,
|
||||||
|
Subscriptions: resp.Event.Subscriptions,
|
||||||
|
Deleted: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := h.services.GRPC.Agenda.UpdateEvent(context.TODO(), request)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Redirect(w, r, "/app/agenda/", http.StatusFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.Renderer.AgendaDeleteEvent(w, r, resp.Event.ToStorageType())
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////Delete subscriber///////////////////////////////
|
||||||
|
func (h *ApplicationHandler) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r *http.Request) {
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
eventId := vars["eventid"]
|
||||||
|
subscribeid := vars["subscribeid"]
|
||||||
|
s_b_id := ""
|
||||||
|
s_b_name := ""
|
||||||
|
s_b_email := ""
|
||||||
|
s_b_group_id := ""
|
||||||
|
s_b_group_name := ""
|
||||||
|
request := &agenda.GetEventRequest{
|
||||||
|
Id: eventId,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), request)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range resp.Event.Subscriptions {
|
||||||
|
if resp.Event.Subscriptions[i].Subscriber == subscribeid {
|
||||||
|
subscribed_by_id := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["user"].GetStructValue().Fields["id"].GetStringValue()
|
||||||
|
subscribed_by_name := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["user"].GetStructValue().Fields["display_name"].GetStringValue()
|
||||||
|
subscribed_by_email := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["user"].GetStructValue().Fields["email"].GetStringValue()
|
||||||
|
subscribed_by_group_id := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["group"].GetStructValue().Fields["id"].GetStringValue()
|
||||||
|
subscribed_by_group_name := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["group"].GetStructValue().Fields["name"].GetStringValue()
|
||||||
|
s_b_id = subscribed_by_id
|
||||||
|
s_b_name = subscribed_by_name
|
||||||
|
s_b_email = subscribed_by_email
|
||||||
|
s_b_group_id = subscribed_by_group_id
|
||||||
|
s_b_group_name = subscribed_by_group_name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
current_group, err := h.currentGroup(r)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
current_user_token, current_user_claims, err := h.currentUser(r)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := map[string]any{
|
||||||
|
"subscribed_by": map[string]any{
|
||||||
|
"user": map[string]any{
|
||||||
|
"id": s_b_id,
|
||||||
|
"display_name": s_b_name,
|
||||||
|
"email": s_b_email,
|
||||||
|
},
|
||||||
|
"group": map[string]any{
|
||||||
|
"id": s_b_group_id,
|
||||||
|
"name": s_b_group_name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"unsubscribed_by": map[string]any{
|
||||||
|
"user": map[string]any{
|
||||||
|
"id": current_user_token.Subject,
|
||||||
|
"display_name": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
|
||||||
|
"email": current_user_claims["email"],
|
||||||
|
},
|
||||||
|
"group": map[string]any{
|
||||||
|
"id": current_group.ID,
|
||||||
|
"name": current_group.Data["name"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"motif": r.FormValue("motif"),
|
||||||
|
}
|
||||||
|
|
||||||
|
datapb, err := structpb.NewStruct(data)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.Method == "POST" {
|
||||||
|
request := &agenda.DeleteSubscriptionRequest{
|
||||||
|
Subscriber: subscribeid,
|
||||||
|
Eventid: eventId,
|
||||||
|
Data: datapb,
|
||||||
|
}
|
||||||
|
|
||||||
|
data := map[string]any{
|
||||||
|
"motif": r.FormValue("motif"),
|
||||||
|
"user": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
|
||||||
|
"subscriber": fmt.Sprintf("http://localhost:9000/app/beneficiaries/%s", subscribeid),
|
||||||
|
"link": fmt.Sprintf("http://localhost:9000/app/agenda/%s", eventId),
|
||||||
|
}
|
||||||
|
|
||||||
|
// récupérer l'adresse mail de l'utilisateur qui a créé l'événement
|
||||||
|
mail := s_b_email
|
||||||
|
fmt.Println(mail)
|
||||||
|
|
||||||
|
_, err := h.services.GRPC.Agenda.DeleteSubscription(context.TODO(), request)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := h.emailing.Send("delete_subscriber.request", mail, data); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Redirect(w, r, fmt.Sprintf("/app/agenda/%s", eventId), http.StatusFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.Renderer.AgendaDeleteSubscribeEvent(w, r, eventId)
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////
|
||||||
|
// /////////////////////History Event////////////////////////
|
||||||
|
func (h *ApplicationHandler) AgendaHistoryEvent(w http.ResponseWriter, r *http.Request) {
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
eventId := vars["eventid"]
|
||||||
|
request := &agenda.GetEventRequest{
|
||||||
|
Id: eventId,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), request)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
grouprequest := &groupsmanagement.GetGroupRequest{
|
||||||
|
Id: resp.Event.Owners[0],
|
||||||
|
}
|
||||||
|
|
||||||
|
groupresp, err := h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), grouprequest)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
subscribers := map[string]any{}
|
||||||
|
|
||||||
|
accids := []string{}
|
||||||
|
for _, v := range resp.Event.DeletedSubscription {
|
||||||
|
accids = append(accids, v.Subscriber)
|
||||||
|
}
|
||||||
|
|
||||||
|
subscriberresp, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(
|
||||||
|
context.TODO(),
|
||||||
|
&mobilityaccounts.GetAccountsBatchRequest{
|
||||||
|
Accountids: accids,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
for _, sub := range subscriberresp.Accounts {
|
||||||
|
subscribers[sub.Id] = sub.ToStorageType()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g := r.Context().Value(identification.GroupKey)
|
||||||
|
if g == nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
group := g.(storage.Group)
|
||||||
|
|
||||||
|
accountids := []string{}
|
||||||
|
for _, m := range group.Members {
|
||||||
|
if !contains(resp.Event.DeletedSubscription, m) {
|
||||||
|
accountids = append(accountids, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
accountresp, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(
|
||||||
|
context.TODO(),
|
||||||
|
&mobilityaccounts.GetAccountsBatchRequest{
|
||||||
|
Accountids: accountids,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
accounts := []any{}
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
for _, acc := range accountresp.Accounts {
|
||||||
|
accounts = append(accounts, acc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
h.Renderer.AgendaHistoryEvent(w, r, resp.Event.ToStorageType(), groupresp.Group.ToStorageType(), subscribers, accounts)
|
||||||
|
}
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ func (h *ApplicationHandler) BeneficiariesList(w http.ResponseWriter, r *http.Re
|
|||||||
func (h *ApplicationHandler) BeneficiaryCreate(w http.ResponseWriter, r *http.Request) {
|
func (h *ApplicationHandler) BeneficiaryCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
g := r.Context().Value(identification.GroupKey)
|
g := r.Context().Value(identification.GroupKey)
|
||||||
if g == nil {
|
if g == nil {
|
||||||
|
fmt.Println("Create beneficiary : could not find group")
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -24,16 +25,6 @@ import (
|
|||||||
var Depart any
|
var Depart any
|
||||||
var Arrive any
|
var Arrive any
|
||||||
|
|
||||||
// type Typep string
|
|
||||||
|
|
||||||
// const (
|
|
||||||
// rec Typep = "rec"
|
|
||||||
// pon Typep = "pon"
|
|
||||||
// )
|
|
||||||
|
|
||||||
// var departdate string
|
|
||||||
// var departTime string
|
|
||||||
|
|
||||||
func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Request) {
|
func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Request) {
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
|
|
||||||
@@ -193,11 +184,9 @@ func (h *ApplicationHandler) GroupsGestion(w http.ResponseWriter, r *http.Reques
|
|||||||
g := group.ToStorageType()
|
g := group.ToStorageType()
|
||||||
groups = append(groups, g)
|
groups = append(groups, g)
|
||||||
}
|
}
|
||||||
//////////////////
|
|
||||||
|
|
||||||
cacheid := uuid.NewString()
|
cacheid := uuid.NewString()
|
||||||
|
|
||||||
/////////////////
|
|
||||||
sort.Sort(GroupsModule(groups))
|
sort.Sort(GroupsModule(groups))
|
||||||
h.cache.PutWithTTL(cacheid, groups, 1*time.Hour)
|
h.cache.PutWithTTL(cacheid, groups, 1*time.Hour)
|
||||||
|
|
||||||
@@ -224,16 +213,9 @@ func (h *ApplicationHandler) CreateGroup(w http.ResponseWriter, r *http.Request)
|
|||||||
dstinationgeo *geojson.Feature
|
dstinationgeo *geojson.Feature
|
||||||
)
|
)
|
||||||
searched := false
|
searched := false
|
||||||
// var accounts = []any{}
|
|
||||||
// cacheid := uuid.NewString()
|
|
||||||
// accountsBeneficaire, err := h.beneficiaries(r)
|
|
||||||
// if err != nil {
|
|
||||||
// fmt.Println(err)
|
|
||||||
// w.WriteHeader(http.StatusBadRequest)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
if r.FormValue("beneficiaryid") != "" {
|
if r.FormValue("beneficiaryid") != "" {
|
||||||
// Handler form
|
|
||||||
searched = true
|
searched = true
|
||||||
|
|
||||||
requestbeneficiary := &mobilityaccounts.GetAccountRequest{
|
requestbeneficiary := &mobilityaccounts.GetAccountRequest{
|
||||||
@@ -250,8 +232,6 @@ func (h *ApplicationHandler) CreateGroup(w http.ResponseWriter, r *http.Request)
|
|||||||
beneficiary = respbeneficiary.Account.ToStorageType()
|
beneficiary = respbeneficiary.Account.ToStorageType()
|
||||||
|
|
||||||
if r.Method == "POST" {
|
if r.Method == "POST" {
|
||||||
fmt.Println("herrre")
|
|
||||||
///////////////////////////////////////////
|
|
||||||
departure := r.FormValue("departure")
|
departure := r.FormValue("departure")
|
||||||
destination := r.FormValue("destination")
|
destination := r.FormValue("destination")
|
||||||
|
|
||||||
@@ -273,7 +253,6 @@ func (h *ApplicationHandler) CreateGroup(w http.ResponseWriter, r *http.Request)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
if r.FormValue("departure") != "" {
|
if r.FormValue("departure") != "" {
|
||||||
var a any
|
var a any
|
||||||
json.Unmarshal([]byte(r.FormValue("departure")), &a)
|
json.Unmarshal([]byte(r.FormValue("departure")), &a)
|
||||||
@@ -288,41 +267,20 @@ func (h *ApplicationHandler) CreateGroup(w http.ResponseWriter, r *http.Request)
|
|||||||
}
|
}
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
|
|
||||||
/////////////////
|
|
||||||
// locTime, errTime := time.LoadLocation("Europe/Paris")
|
|
||||||
// if errTime != nil {
|
|
||||||
// fmt.Println("Loading timezone location Europe/Paris error : ")
|
|
||||||
// fmt.Println("Missing zones in container ? ")
|
|
||||||
// panic(errTime)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// departdate := r.FormValue("departuredate")
|
|
||||||
// departTime := r.FormValue("departuretime")
|
|
||||||
//departuredatetime, _ := time.ParseInLocation("2006-01-02 15:04", fmt.Sprintf("%s %s", departuredate, departuretime), locTime)
|
|
||||||
|
|
||||||
////////////////
|
|
||||||
if r.FormValue("name") == "" {
|
if r.FormValue("name") == "" {
|
||||||
|
|
||||||
fmt.Println("invalid name")
|
fmt.Println("invalid name")
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// if r.FormValue("driver") == "" {
|
|
||||||
|
|
||||||
// fmt.Println("invalid name")
|
|
||||||
// w.WriteHeader(http.StatusBadRequest)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
if r.FormValue("number") == "" {
|
if r.FormValue("number") == "" {
|
||||||
|
|
||||||
fmt.Println("invalid number of personne")
|
fmt.Println("invalid number of personne")
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// planType := map[string]any{
|
|
||||||
// "rrecurrent": r.FormValue("recurrent") == "on",
|
|
||||||
// "pponctuelle": r.FormValue("ponctuelle") == "on",
|
|
||||||
// }
|
|
||||||
planDays := map[string]any{
|
planDays := map[string]any{
|
||||||
"lundi": r.FormValue("lundi") == "on",
|
"lundi": r.FormValue("lundi") == "on",
|
||||||
"mardi": r.FormValue("mardi") == "on",
|
"mardi": r.FormValue("mardi") == "on",
|
||||||
@@ -332,10 +290,9 @@ func (h *ApplicationHandler) CreateGroup(w http.ResponseWriter, r *http.Request)
|
|||||||
"samedi": r.FormValue("samedi") == "on",
|
"samedi": r.FormValue("samedi") == "on",
|
||||||
"dimanche": r.FormValue("dimanche") == "on",
|
"dimanche": r.FormValue("dimanche") == "on",
|
||||||
}
|
}
|
||||||
// var rec bool = r.FormValue("recurrent")
|
|
||||||
// var ponc bool
|
|
||||||
groupidd := uuid.NewString()
|
groupidd := uuid.NewString()
|
||||||
fmt.Println("herrr&e")
|
|
||||||
dataMap := map[string]any{
|
dataMap := map[string]any{
|
||||||
"name": r.FormValue("name"),
|
"name": r.FormValue("name"),
|
||||||
"number": r.FormValue("number"),
|
"number": r.FormValue("number"),
|
||||||
@@ -348,15 +305,12 @@ func (h *ApplicationHandler) CreateGroup(w http.ResponseWriter, r *http.Request)
|
|||||||
"enddate": r.FormValue("enddate"),
|
"enddate": r.FormValue("enddate"),
|
||||||
"departtime": r.FormValue("departtime"),
|
"departtime": r.FormValue("departtime"),
|
||||||
"time": r.FormValue("time"),
|
"time": r.FormValue("time"),
|
||||||
// "ponctdate": r.FormValue("ponctdate"),
|
|
||||||
//"planType": planType,
|
|
||||||
"planDays": planDays,
|
"planDays": planDays,
|
||||||
"recurrent": r.FormValue("recurrent"),
|
"recurrent": r.FormValue("recurrent"),
|
||||||
"pontuelle": r.FormValue("ponctuelle"),
|
"pontuelle": r.FormValue("ponctuelle"),
|
||||||
// "r": rec,
|
|
||||||
// "p": pon,
|
|
||||||
}
|
}
|
||||||
fmt.Println(dataMap["ponctuelle"])
|
|
||||||
data, err := structpb.NewValue(dataMap)
|
data, err := structpb.NewValue(dataMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
@@ -378,25 +332,9 @@ func (h *ApplicationHandler) CreateGroup(w http.ResponseWriter, r *http.Request)
|
|||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//////////////////////////////////////////////////
|
|
||||||
// request_organizatio := &groupsmanagement.AddGroupMemberRequest{
|
|
||||||
// Group: &groupsmanagement.GroupMember{
|
|
||||||
// Id: groupidd,
|
|
||||||
// //Namespace: "parcoursmob_groups_covoiturage",
|
|
||||||
// Data: data.GetStructValue(),
|
|
||||||
// },
|
|
||||||
// }
|
|
||||||
|
|
||||||
// _, err = h.services.GRPC.GroupsManagement.AddGroupMember(context.TODO(), request_organizatio)
|
|
||||||
// if err != nil {
|
|
||||||
// fmt.Println(err)
|
|
||||||
// w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
////////////////////////////////////////////////
|
|
||||||
http.Redirect(w, r, fmt.Sprintf("/app/journeys/groups_covoiturage/create/%s", request_organization.Group.ToStorageType().ID), http.StatusFound)
|
http.Redirect(w, r, fmt.Sprintf("/app/journeys/groups_covoiturage/create/%s", request_organization.Group.ToStorageType().ID), http.StatusFound)
|
||||||
|
|
||||||
//http.Redirect(w, r, fmt.Print("/app/journeys"), http.StatusFound)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -433,9 +371,7 @@ func (h *ApplicationHandler) DisplayGroupCovoiturage(w http.ResponseWriter, r *h
|
|||||||
}
|
}
|
||||||
|
|
||||||
ressp, _ := h.services.GRPC.MobilityAccounts.GetAccountsBatch(context.TODO(), requesst)
|
ressp, _ := h.services.GRPC.MobilityAccounts.GetAccountsBatch(context.TODO(), requesst)
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
for _, account := range ressp.Accounts {
|
for _, account := range ressp.Accounts {
|
||||||
if filterAcc(r, account) {
|
if filterAcc(r, account) {
|
||||||
a := account.ToStorageType()
|
a := account.ToStorageType()
|
||||||
@@ -448,12 +384,10 @@ func (h *ApplicationHandler) DisplayGroupCovoiturage(w http.ResponseWriter, r *h
|
|||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
|
|
||||||
var beneficiary any
|
var beneficiary any
|
||||||
|
|
||||||
searched := false
|
searched := false
|
||||||
|
|
||||||
// if r.Method == "POST" {
|
|
||||||
if r.FormValue("beneficiaryid") != "" {
|
if r.FormValue("beneficiaryid") != "" {
|
||||||
// Handler form
|
|
||||||
searched = true
|
searched = true
|
||||||
|
|
||||||
requestbeneficiary := &mobilityaccounts.GetAccountRequest{
|
requestbeneficiary := &mobilityaccounts.GetAccountRequest{
|
||||||
@@ -476,6 +410,48 @@ func (h *ApplicationHandler) DisplayGroupCovoiturage(w http.ResponseWriter, r *h
|
|||||||
|
|
||||||
_, err = h.services.GRPC.GroupsManagement.Subscribe(context.TODO(), subscribe)
|
_, err = h.services.GRPC.GroupsManagement.Subscribe(context.TODO(), subscribe)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
/*******************Code to store more information about mermbers groupscovoiturage**************/
|
||||||
|
if r.FormValue("departure") != "" {
|
||||||
|
var a any
|
||||||
|
json.Unmarshal([]byte(r.FormValue("departure")), &a)
|
||||||
|
|
||||||
|
Depart = a
|
||||||
|
}
|
||||||
|
if r.FormValue("destination") != "" {
|
||||||
|
var a any
|
||||||
|
json.Unmarshal([]byte(r.FormValue("destination")), &a)
|
||||||
|
|
||||||
|
Arrive = a
|
||||||
|
}
|
||||||
|
r.ParseForm()
|
||||||
|
dataMap := map[string]any{
|
||||||
|
|
||||||
|
"depart": Depart,
|
||||||
|
"arrive": Arrive,
|
||||||
|
}
|
||||||
|
id := uuid.NewString()
|
||||||
|
data, err := structpb.NewValue(dataMap)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
request_organizatio := &groupsmanagement.AddGroupMemberRequest{
|
||||||
|
Group: &groupsmanagement.GroupMember{
|
||||||
|
Id: id,
|
||||||
|
Memberid: respbeneficiary.Account.Id,
|
||||||
|
Groupid: resp.Group.ToStorageType().ID,
|
||||||
|
Data: data.GetStructValue(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = h.services.GRPC.GroupsManagement.AddGroupMember(context.TODO(), request_organizatio)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
@@ -485,7 +461,30 @@ func (h *ApplicationHandler) DisplayGroupCovoiturage(w http.ResponseWriter, r *h
|
|||||||
http.Redirect(w, r, fmt.Sprintf("/app/journeys/groups_covoiturage/create/%s", resp.Group.ToStorageType().ID), http.StatusFound)
|
http.Redirect(w, r, fmt.Sprintf("/app/journeys/groups_covoiturage/create/%s", resp.Group.ToStorageType().ID), http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//////////find all groups to store the adresse passenger///////
|
||||||
|
// grp := &groupsmanagement.GetGroupsBatchMemberRequest{
|
||||||
|
|
||||||
|
// Groupids: []string{resp.Group.ToStorageType().ID},
|
||||||
|
// }
|
||||||
|
// s, err := h.services.GRPC.GroupsManagement.GetGroupsBatchMember(context.TODO(), grp)
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Println(err)
|
||||||
|
// w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// groups := map[string]any{}
|
||||||
|
|
||||||
|
// if err == nil {
|
||||||
|
// for _, g := range s.Groups {
|
||||||
|
// groups[g.Memberid] = g.ToStorageType()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//////////find all groups to store the adresse passenger///////
|
||||||
|
///////////try to optimise the code ////////////////////////////
|
||||||
|
groups, _ := h.services.GetGroupsMemberMap(resp.Group.ToStorageType().ID)
|
||||||
|
//fmt.Println(groups)
|
||||||
|
var number string = strconv.Itoa(len(resp.Group.Members))
|
||||||
|
/////////////////////
|
||||||
accountsBeneficaire, err := h.beneficiaries(r)
|
accountsBeneficaire, err := h.beneficiaries(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
@@ -493,6 +492,77 @@ func (h *ApplicationHandler) DisplayGroupCovoiturage(w http.ResponseWriter, r *h
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//h.Renderer.BeneficaireSearch(w, r, accounts, searched, beneficiary, resp.Group.ToStorageType())
|
h.Renderer.DisplayGroupCovoiturage(w, r, number, resp.Group.ToStorageType().ID, Depart, Arrive, accounts, cacheid, searched, beneficiary, resp.Group.ToStorageType(), accountsBeneficaire, groups)
|
||||||
h.Renderer.DisplayGroupCovoiturage(w, r, resp.Group.ToStorageType().ID, accounts, cacheid, searched, beneficiary, resp.Group.ToStorageType(), accountsBeneficaire)
|
}
|
||||||
|
|
||||||
|
func (h *ApplicationHandler) UpdateGroupCovoiturage(w http.ResponseWriter, r *http.Request) {
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
id := vars["id"]
|
||||||
|
groupid := vars["groupid"]
|
||||||
|
memberid := vars["memberid"]
|
||||||
|
|
||||||
|
if r.Method == "POST" {
|
||||||
|
|
||||||
|
//////////get groupid covoiturage//////////
|
||||||
|
request := &groupsmanagement.GetGroupRequest{
|
||||||
|
Id: groupid,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), request)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////get group member////////////////////////////////
|
||||||
|
|
||||||
|
reequest := &groupsmanagement.GetGroupMemberRequest{
|
||||||
|
Id: id,
|
||||||
|
}
|
||||||
|
|
||||||
|
ressp, err := h.services.GRPC.GroupsManagement.GetGroupMember(context.TODO(), reequest)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req := &groupsmanagement.UnsubscribeMemberRequest{
|
||||||
|
Id: ressp.Group.Id,
|
||||||
|
}
|
||||||
|
|
||||||
|
_, errr := h.services.GRPC.GroupsManagement.UnsubscribeMember(context.TODO(), req)
|
||||||
|
if errr != nil {
|
||||||
|
fmt.Println(errr)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
members := resp.Group.Members
|
||||||
|
for i := 0; i < len(members); i++ {
|
||||||
|
if members[i] == memberid {
|
||||||
|
members = append(members[:i], members[(i+1):]...)
|
||||||
|
resp.Group.Members = members
|
||||||
|
reequest := &groupsmanagement.UnsubscribeRequest{
|
||||||
|
Groupid: resp.Group.ToStorageType().ID,
|
||||||
|
Memberid: memberid,
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := h.services.GRPC.GroupsManagement.Unsubscribe(context.TODO(), reequest)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
http.Redirect(w, r, fmt.Sprintf("/app/journeys/groups_covoiturage/create/%s", groupid), http.StatusFound)
|
||||||
|
/*
|
||||||
|
I must add "return" to resolve the err
|
||||||
|
http: superfluous response.WriteHeader call from git.coopgo.io/coopgo-apps/parcoursmob/renderer.(*Renderer).Render (renderer.go:50)
|
||||||
|
*/
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.Renderer.UpdateGroupCovoiturage(w, r, groupid, memberid)
|
||||||
}
|
}
|
||||||
|
|||||||
128
handlers/application/members.go
Normal file
128
handlers/application/members.go
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
package application
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
formvalidators "git.coopgo.io/coopgo-apps/parcoursmob/utils/form-validators"
|
||||||
|
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||||
|
"google.golang.org/protobuf/types/known/structpb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserForm struct {
|
||||||
|
FirstName string `json:"first_name" validate:"required"`
|
||||||
|
LastName string `json:"last_name" validate:"required"`
|
||||||
|
Email string `json:"email" validate:"required,email"`
|
||||||
|
PhoneNumber string `json:"phone_number" `
|
||||||
|
Address any `json:"address,omitempty"`
|
||||||
|
Gender string `json:"gender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ApplicationHandler) MemberDisplay(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
adm := strings.Split(r.URL.Path, "/")
|
||||||
|
adminid := adm[3]
|
||||||
|
|
||||||
|
request := &mobilityaccounts.GetAccountRequest{
|
||||||
|
Id: adminid,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), request)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
h.Renderer.MemberDisplay(w, r, resp.Account.ToStorageType())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ApplicationHandler) MemberUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
adm := strings.Split(r.URL.Path, "/")
|
||||||
|
userID := adm[3]
|
||||||
|
|
||||||
|
if r.Method == "POST" {
|
||||||
|
|
||||||
|
dataMap, err := parseUserForm(r)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := structpb.NewValue(dataMap)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
request := &mobilityaccounts.UpdateDataRequest{
|
||||||
|
Account: &mobilityaccounts.Account{
|
||||||
|
Id: userID,
|
||||||
|
Namespace: "parcoursmob",
|
||||||
|
Data: data.GetStructValue(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.services.GRPC.MobilityAccounts.UpdateData(context.TODO(), request)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Redirect(w, r, fmt.Sprintf("/app/members/%s", resp.Account.Id), http.StatusFound)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
request := &mobilityaccounts.GetAccountRequest{
|
||||||
|
Id: userID,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), request)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
h.Renderer.MemberUpdate(w, r, resp.Account.ToStorageType())
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseUserForm(r *http.Request) (map[string]any, error) {
|
||||||
|
if err := r.ParseForm(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
formData := UserForm{
|
||||||
|
FirstName: r.PostFormValue("first_name"),
|
||||||
|
LastName: r.PostFormValue("last_name"),
|
||||||
|
Email: r.PostFormValue("email"),
|
||||||
|
PhoneNumber: r.PostFormValue("phone_number"),
|
||||||
|
Gender: r.PostFormValue("gender"),
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataMap, nil
|
||||||
|
}
|
||||||
@@ -136,14 +136,7 @@ func (h ApplicationHandler) VehiclesSearch(w http.ResponseWriter, r *http.Reques
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
|
func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
|
||||||
// Get Group
|
fmt.Println("Book")
|
||||||
// g := r.Context().Value(identification.GroupKey)
|
|
||||||
// if g == nil {
|
|
||||||
// fmt.Println("no current group")
|
|
||||||
// w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// current_group := g.(storage.Group)
|
|
||||||
current_group, err := h.currentGroup(r)
|
current_group, err := h.currentGroup(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
@@ -151,24 +144,6 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get current user ID
|
|
||||||
// u := r.Context().Value(identification.IdtokenKey)
|
|
||||||
// if u == nil {
|
|
||||||
// fmt.Println("no current user")
|
|
||||||
// w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// current_user_token := u.(*oidc.IDToken)
|
|
||||||
|
|
||||||
// // Get current user claims
|
|
||||||
// c := r.Context().Value(identification.ClaimsKey)
|
|
||||||
// if c == nil {
|
|
||||||
// fmt.Println("no current user claims")
|
|
||||||
// w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// current_user_claims := c.(map[string]any)
|
|
||||||
|
|
||||||
current_user_token, current_user_claims, err := h.currentUser(r)
|
current_user_token, current_user_claims, err := h.currentUser(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
@@ -191,7 +166,7 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
r.ParseMultipartForm(10 * 1024 * 1024)
|
r.ParseMultipartForm(100 * 1024 * 1024)
|
||||||
|
|
||||||
start := r.FormValue("startdate")
|
start := r.FormValue("startdate")
|
||||||
end := r.FormValue("enddate")
|
end := r.FormValue("enddate")
|
||||||
@@ -203,7 +178,7 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
|
|||||||
"booked_by": map[string]any{
|
"booked_by": map[string]any{
|
||||||
"user": map[string]any{
|
"user": map[string]any{
|
||||||
"id": current_user_token.Subject,
|
"id": current_user_token.Subject,
|
||||||
"display_name": current_user_claims["display_name"],
|
"display_name": fmt.Sprintf("%s %s", current_user_claims["first_name"], current_user_claims["last_name"]),
|
||||||
},
|
},
|
||||||
"group": map[string]any{
|
"group": map[string]any{
|
||||||
"id": current_group.ID,
|
"id": current_group.ID,
|
||||||
@@ -233,7 +208,6 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
|
|||||||
Booking: booking,
|
Booking: booking,
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(r.FormFile("doc-identity_proof"))
|
|
||||||
for _, v := range h.config.GetStringSlice("modules.fleets.booking_documents.mandatory") {
|
for _, v := range h.config.GetStringSlice("modules.fleets.booking_documents.mandatory") {
|
||||||
existing_file := r.FormValue("type-" + v)
|
existing_file := r.FormValue("type-" + v)
|
||||||
if existing_file == "" {
|
if existing_file == "" {
|
||||||
@@ -282,11 +256,13 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
} else {
|
} else {
|
||||||
for _, m := range members {
|
for _, m := range members {
|
||||||
h.emailing.Send("fleets.bookings.creation_admin_alert", m.Data["email"].(string), map[string]string{
|
if email, ok := m.Data["email"].(string); ok {
|
||||||
|
h.emailing.Send("fleets.bookings.creation_admin_alert", email, map[string]string{
|
||||||
"bookingid": booking.Id,
|
"bookingid": booking.Id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
http.Redirect(w, r, fmt.Sprintf("/app/vehicles/bookings/%s", booking.Id), http.StatusFound)
|
http.Redirect(w, r, fmt.Sprintf("/app/vehicles/bookings/%s", booking.Id), http.StatusFound)
|
||||||
|
|
||||||
@@ -314,9 +290,9 @@ func (h ApplicationHandler) VehicleBookingDisplay(w http.ResponseWriter, r *http
|
|||||||
|
|
||||||
beneficiaryresp, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), beneficiaryrequest)
|
beneficiaryresp, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), beneficiaryrequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
beneficiaryresp = &mobilityaccounts.GetAccountResponse{
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
Account: &mobilityaccounts.Account{},
|
||||||
return
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
grouprequest := &groupsmanagement.GetGroupRequest{
|
grouprequest := &groupsmanagement.GetGroupRequest{
|
||||||
@@ -370,7 +346,10 @@ func (h ApplicationHandler) VehiclesBookingsList(w http.ResponseWriter, r *http.
|
|||||||
|
|
||||||
sort.Sort(sorting.BookingsByStartdate(bookings))
|
sort.Sort(sorting.BookingsByStartdate(bookings))
|
||||||
|
|
||||||
h.Renderer.VehicleBookingsList(w, r, bookings)
|
vehicles, _ := h.services.GetVehiclesMap()
|
||||||
|
groups, _ := h.services.GetGroupsMap()
|
||||||
|
|
||||||
|
h.Renderer.VehicleBookingsList(w, r, bookings, vehicles, groups)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ApplicationHandler) BookingDocumentDownload(w http.ResponseWriter, r *http.Request) {
|
func (h *ApplicationHandler) BookingDocumentDownload(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
13
handlers/auth/disconnect.go
Normal file
13
handlers/auth/disconnect.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package auth
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
func (h *AuthHandler) Disconnect(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, err := h.idp.SessionsStore.Get(r, "parcoursmob_session")
|
||||||
|
if err == nil {
|
||||||
|
session.Options.MaxAge = -1
|
||||||
|
session.Save(r, w)
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Redirect(w, r, "/", http.StatusOK)
|
||||||
|
}
|
||||||
@@ -37,7 +37,7 @@ func (h *AuthHandler) Onboarding(w http.ResponseWriter, r *http.Request) {
|
|||||||
if onboardingmap["admin"].(bool) {
|
if onboardingmap["admin"].(bool) {
|
||||||
groups = append(groups, onboardingmap["group"].(string)+":admin")
|
groups = append(groups, onboardingmap["group"].(string)+":admin")
|
||||||
}
|
}
|
||||||
|
display_name := fmt.Sprint(r.FormValue("first_name")) + " " + fmt.Sprint(r.FormValue("last_name"))
|
||||||
account := &ma.Account{
|
account := &ma.Account{
|
||||||
Authentication: ma.AccountAuth{
|
Authentication: ma.AccountAuth{
|
||||||
Local: ma.LocalAuth{
|
Local: ma.LocalAuth{
|
||||||
@@ -46,7 +46,9 @@ func (h *AuthHandler) Onboarding(w http.ResponseWriter, r *http.Request) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Namespace: "parcoursmob",
|
Namespace: "parcoursmob",
|
||||||
|
|
||||||
Data: map[string]any{
|
Data: map[string]any{
|
||||||
|
"display_name": display_name,
|
||||||
"first_name": r.FormValue("first_name"),
|
"first_name": r.FormValue("first_name"),
|
||||||
"last_name": r.FormValue("last_name"),
|
"last_name": r.FormValue("last_name"),
|
||||||
"email": onboardingmap["username"],
|
"email": onboardingmap["username"],
|
||||||
|
|||||||
16
main.go
16
main.go
@@ -61,6 +61,7 @@ func main() {
|
|||||||
r.PathPrefix("/public/").Handler(http.StripPrefix("/public/", http.FileServer(http.Dir(templates_public_dir))))
|
r.PathPrefix("/public/").Handler(http.StripPrefix("/public/", http.FileServer(http.Dir(templates_public_dir))))
|
||||||
|
|
||||||
r.HandleFunc("/auth/onboarding", authHandler.Onboarding)
|
r.HandleFunc("/auth/onboarding", authHandler.Onboarding)
|
||||||
|
r.HandleFunc("/auth/disconnect", authHandler.Disconnect)
|
||||||
r.HandleFunc("/auth/lost-password", authHandler.LostPasswordInit)
|
r.HandleFunc("/auth/lost-password", authHandler.LostPasswordInit)
|
||||||
r.HandleFunc("/auth/lost-password/recover", authHandler.LostPasswordRecover)
|
r.HandleFunc("/auth/lost-password/recover", authHandler.LostPasswordRecover)
|
||||||
r.HandleFunc("/auth/groups/", authHandler.Groups)
|
r.HandleFunc("/auth/groups/", authHandler.Groups)
|
||||||
@@ -84,6 +85,8 @@ func main() {
|
|||||||
application.HandleFunc("/beneficiaries/{beneficiaryid}/documents/{document}", applicationHandler.BeneficiaryDocumentDownload)
|
application.HandleFunc("/beneficiaries/{beneficiaryid}/documents/{document}", applicationHandler.BeneficiaryDocumentDownload)
|
||||||
application.HandleFunc("/beneficiaries/{beneficiaryid}/picture", applicationHandler.BeneficiaryPicture)
|
application.HandleFunc("/beneficiaries/{beneficiaryid}/picture", applicationHandler.BeneficiaryPicture)
|
||||||
application.HandleFunc("/members/{beneficiaryid}/picture", applicationHandler.BeneficiaryPicture)
|
application.HandleFunc("/members/{beneficiaryid}/picture", applicationHandler.BeneficiaryPicture)
|
||||||
|
application.HandleFunc("/members/{adminid}", applicationHandler.MemberDisplay)
|
||||||
|
application.HandleFunc("/members/{adminid}/update", applicationHandler.MemberUpdate)
|
||||||
application.HandleFunc("/journeys/", applicationHandler.JourneysSearch)
|
application.HandleFunc("/journeys/", applicationHandler.JourneysSearch)
|
||||||
application.HandleFunc("/vehicles/", applicationHandler.VehiclesSearch)
|
application.HandleFunc("/vehicles/", applicationHandler.VehiclesSearch)
|
||||||
application.HandleFunc("/vehicles/bookings/", applicationHandler.VehiclesBookingsList)
|
application.HandleFunc("/vehicles/bookings/", applicationHandler.VehiclesBookingsList)
|
||||||
@@ -97,11 +100,15 @@ func main() {
|
|||||||
application.HandleFunc("/vehicles-management/fleet/{vehicleid}/update", applicationHandler.VehiclesFleetUpdate)
|
application.HandleFunc("/vehicles-management/fleet/{vehicleid}/update", applicationHandler.VehiclesFleetUpdate)
|
||||||
application.HandleFunc("/vehicles-management/bookings/", applicationHandler.VehiclesManagementBookingsList)
|
application.HandleFunc("/vehicles-management/bookings/", applicationHandler.VehiclesManagementBookingsList)
|
||||||
application.HandleFunc("/vehicles-management/bookings/{bookingid}", applicationHandler.VehicleManagementBookingDisplay)
|
application.HandleFunc("/vehicles-management/bookings/{bookingid}", applicationHandler.VehicleManagementBookingDisplay)
|
||||||
application.HandleFunc("/vehicles-management/bookings/{bookingid}/change-vehicle", applicationHandler.VehicleManagementBookingChangeVehicle)
|
|
||||||
application.HandleFunc("/vehicles-management/bookings/{bookingid}/documents/{document}", applicationHandler.BookingDocumentDownload)
|
application.HandleFunc("/vehicles-management/bookings/{bookingid}/documents/{document}", applicationHandler.BookingDocumentDownload)
|
||||||
application.HandleFunc("/agenda/", applicationHandler.AgendaHome)
|
application.HandleFunc("/agenda/", applicationHandler.AgendaHome)
|
||||||
application.HandleFunc("/agenda/create-event", applicationHandler.AgendaCreateEvent)
|
application.HandleFunc("/agenda/create-event", applicationHandler.AgendaCreateEvent)
|
||||||
application.HandleFunc("/agenda/{eventid}", applicationHandler.AgendaDisplayEvent)
|
application.HandleFunc("/agenda/{eventid}", applicationHandler.AgendaDisplayEvent)
|
||||||
|
///////////////////////////////Code to modify event///////////////////////
|
||||||
|
application.HandleFunc("/agenda/{eventid}/update", applicationHandler.AgendaUpdateEvent)
|
||||||
|
application.HandleFunc("/agenda/{eventid}/delete", applicationHandler.AgendaDeleteEvent)
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
application.HandleFunc("/agenda/{eventid}/subscribe", applicationHandler.AgendaSubscribeEvent)
|
application.HandleFunc("/agenda/{eventid}/subscribe", applicationHandler.AgendaSubscribeEvent)
|
||||||
application.HandleFunc("/directory/", applicationHandler.DirectoryHome)
|
application.HandleFunc("/directory/", applicationHandler.DirectoryHome)
|
||||||
|
|
||||||
@@ -112,6 +119,7 @@ func main() {
|
|||||||
application.HandleFunc("/journeys/groups_covoiturage", applicationHandler.GroupsGestion)
|
application.HandleFunc("/journeys/groups_covoiturage", applicationHandler.GroupsGestion)
|
||||||
application.HandleFunc("/journeys/groups_covoiturage/create", applicationHandler.CreateGroup)
|
application.HandleFunc("/journeys/groups_covoiturage/create", applicationHandler.CreateGroup)
|
||||||
application.HandleFunc("/journeys/groups_covoiturage/create/{groupid}", applicationHandler.DisplayGroupCovoiturage)
|
application.HandleFunc("/journeys/groups_covoiturage/create/{groupid}", applicationHandler.DisplayGroupCovoiturage)
|
||||||
|
application.HandleFunc("/journeys/groups_covoiturage/create/{id}/{groupid}/{memberid}", applicationHandler.UpdateGroupCovoiturage)
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
|
|
||||||
/********************Code Supprt Emailing************************/
|
/********************Code Supprt Emailing************************/
|
||||||
@@ -133,8 +141,12 @@ func main() {
|
|||||||
appAdmin.HandleFunc("/groups/{groupid}", applicationHandler.AdministrationGroupDisplay)
|
appAdmin.HandleFunc("/groups/{groupid}", applicationHandler.AdministrationGroupDisplay)
|
||||||
appAdmin.HandleFunc("/groups/{groupid}/invite-admin", applicationHandler.AdministrationGroupInviteAdmin)
|
appAdmin.HandleFunc("/groups/{groupid}/invite-admin", applicationHandler.AdministrationGroupInviteAdmin)
|
||||||
appAdmin.HandleFunc("/groups/{groupid}/invite-member", applicationHandler.AdministrationGroupInviteMember)
|
appAdmin.HandleFunc("/groups/{groupid}/invite-member", applicationHandler.AdministrationGroupInviteMember)
|
||||||
//TODO Secure with Middleware checking for modules
|
appAdmin.HandleFunc("/stats/vehicles", applicationHandler.AdminStatVehicles)
|
||||||
|
|
||||||
|
/////////////////////////////////////Delete subscriber///////////////////////////////////////////////
|
||||||
|
application.HandleFunc("/agenda/{eventid}/{subscribeid}/delete", applicationHandler.AgendaDeleteSubscribeEvent)
|
||||||
|
application.HandleFunc("/agenda/{eventid}/history", applicationHandler.AgendaHistoryEvent)
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
fmt.Println("-> HTTP server listening on", address)
|
fmt.Println("-> HTTP server listening on", address)
|
||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ func (renderer *Renderer) AgendaCreateEvent(w http.ResponseWriter, r *http.Reque
|
|||||||
func (renderer *Renderer) AgendaDisplayEvent(w http.ResponseWriter, r *http.Request, event any, group any, subscribers map[string]any, beneficiaries any) {
|
func (renderer *Renderer) AgendaDisplayEvent(w http.ResponseWriter, r *http.Request, event any, group any, subscribers map[string]any, beneficiaries any) {
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.agenda.display_event.files")
|
files := renderer.ThemeConfig.GetStringSlice("views.agenda.display_event.files")
|
||||||
state := NewState(r, renderer.ThemeConfig, agendaMenu)
|
state := NewState(r, renderer.ThemeConfig, agendaMenu)
|
||||||
|
|
||||||
state.ViewState = map[string]any{
|
state.ViewState = map[string]any{
|
||||||
"event": event,
|
"event": event,
|
||||||
"group": group,
|
"group": group,
|
||||||
@@ -38,3 +39,53 @@ func (renderer *Renderer) AgendaDisplayEvent(w http.ResponseWriter, r *http.Requ
|
|||||||
|
|
||||||
renderer.Render("agenda create event", w, r, files, state)
|
renderer.Render("agenda create event", w, r, files, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////DElete subscriber//////////////////////////////////
|
||||||
|
func (renderer *Renderer) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r *http.Request, eventid string) {
|
||||||
|
files := renderer.ThemeConfig.GetStringSlice("views.agenda.delete_subscriber.files")
|
||||||
|
state := NewState(r, renderer.ThemeConfig, agendaMenu)
|
||||||
|
state.ViewState = map[string]any{
|
||||||
|
"eventid": eventid,
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.Render("agenda delete subscriber", w, r, files, state)
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//////////////////////////History Event//////////////////////////////////
|
||||||
|
func (renderer *Renderer) AgendaHistoryEvent(w http.ResponseWriter, r *http.Request, event any, group any, subscribers map[string]any, beneficiaries any) {
|
||||||
|
files := renderer.ThemeConfig.GetStringSlice("views.agenda.history_event.files")
|
||||||
|
state := NewState(r, renderer.ThemeConfig, agendaMenu)
|
||||||
|
state.ViewState = map[string]any{
|
||||||
|
"event": event,
|
||||||
|
"group": group,
|
||||||
|
"subscribers": subscribers,
|
||||||
|
"beneficiaries": beneficiaries,
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.Render("agenda history event", w, r, files, state)
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
func (renderer *Renderer) AgendaUpdateEvent(w http.ResponseWriter, r *http.Request, event any) {
|
||||||
|
files := renderer.ThemeConfig.GetStringSlice("views.agenda.update.files")
|
||||||
|
state := NewState(r, renderer.ThemeConfig, agendaMenu)
|
||||||
|
|
||||||
|
state.ViewState = map[string]any{
|
||||||
|
"event": event,
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.Render("event_update", w, r, files, state)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (renderer *Renderer) AgendaDeleteEvent(w http.ResponseWriter, r *http.Request, event any) {
|
||||||
|
files := renderer.ThemeConfig.GetStringSlice("views.agenda.delete.files")
|
||||||
|
state := NewState(r, renderer.ThemeConfig, agendaMenu)
|
||||||
|
|
||||||
|
state.ViewState = map[string]any{
|
||||||
|
"event": event,
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.Render("event_deleteEvent", w, r, files, state)
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ type BeneficiariesCovoiturage struct {
|
|||||||
Beneficiaries []any `json:"beneficiaries"`
|
Beneficiaries []any `json:"beneficiaries"`
|
||||||
}
|
}
|
||||||
type BeneficiariesCovoiturageA struct {
|
type BeneficiariesCovoiturageA struct {
|
||||||
//Group string `json:"group"`
|
|
||||||
Count int `json:"count"`
|
Count int `json:"count"`
|
||||||
CacheId string `json:"cache_id"`
|
CacheId string `json:"cache_id"`
|
||||||
Beneficiaries []any `json:"beneficiaries"`
|
Beneficiaries []any `json:"beneficiaries"`
|
||||||
@@ -73,11 +72,7 @@ func (s BeneficiariesListstate) JSONWithLimits(a int, b int) template.JS {
|
|||||||
func (renderer *Renderer) GroupsGestion(w http.ResponseWriter, r *http.Request, groups []groupstorage.Group, cacheid string) {
|
func (renderer *Renderer) GroupsGestion(w http.ResponseWriter, r *http.Request, groups []groupstorage.Group, cacheid string) {
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.journeys.list.files")
|
files := renderer.ThemeConfig.GetStringSlice("views.journeys.list.files")
|
||||||
state := NewState(r, renderer.ThemeConfig, journeysMenu)
|
state := NewState(r, renderer.ThemeConfig, journeysMenu)
|
||||||
// state.ViewState = map[string]any{
|
|
||||||
// "groups": groups,
|
|
||||||
// }
|
|
||||||
|
|
||||||
//state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
|
|
||||||
state.ViewState = BeneficiariesListstate{
|
state.ViewState = BeneficiariesListstate{
|
||||||
Count: len(groups),
|
Count: len(groups),
|
||||||
CacheId: cacheid,
|
CacheId: cacheid,
|
||||||
@@ -90,14 +85,6 @@ func (renderer *Renderer) GroupsGestion(w http.ResponseWriter, r *http.Request,
|
|||||||
func (renderer *Renderer) CreateGroup(w http.ResponseWriter, r *http.Request, depart any, arrive any, searched bool, beneficiary any, beneficiaries []mobilityaccountsstorage.Account, departure any, destination any) {
|
func (renderer *Renderer) CreateGroup(w http.ResponseWriter, r *http.Request, depart any, arrive any, searched bool, beneficiary any, beneficiaries []mobilityaccountsstorage.Account, departure any, destination any) {
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.journeys.create.files")
|
files := renderer.ThemeConfig.GetStringSlice("views.journeys.create.files")
|
||||||
state := NewState(r, renderer.ThemeConfig, journeysMenu)
|
state := NewState(r, renderer.ThemeConfig, journeysMenu)
|
||||||
// state.ViewState = map[string]any{
|
|
||||||
// "departure": depart,
|
|
||||||
// "destination": arrive,
|
|
||||||
// //"beneficiary": beneficiary,
|
|
||||||
// //"accounts": accounts,
|
|
||||||
// // "cacheid": cacheid,
|
|
||||||
// // "searched": searched,
|
|
||||||
// }
|
|
||||||
viewstate := map[string]any{
|
viewstate := map[string]any{
|
||||||
"deeparture": depart,
|
"deeparture": depart,
|
||||||
"deestination": arrive,
|
"deestination": arrive,
|
||||||
@@ -105,8 +92,6 @@ func (renderer *Renderer) CreateGroup(w http.ResponseWriter, r *http.Request, de
|
|||||||
"searched": searched,
|
"searched": searched,
|
||||||
"departure": departure,
|
"departure": departure,
|
||||||
"destination": destination,
|
"destination": destination,
|
||||||
// "departuredate": departuredate,
|
|
||||||
// "departuretime": departuretime,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if searched {
|
if searched {
|
||||||
@@ -120,7 +105,7 @@ func (renderer *Renderer) CreateGroup(w http.ResponseWriter, r *http.Request, de
|
|||||||
renderer.Render("journeys", w, r, files, state)
|
renderer.Render("journeys", w, r, files, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (renderer *Renderer) DisplayGroupCovoiturage(w http.ResponseWriter, r *http.Request, groupid string, accounts []any, cacheid string, searched bool, beneficiary any, group any, beneficiaries []mobilityaccountsstorage.Account) {
|
func (renderer *Renderer) DisplayGroupCovoiturage(w http.ResponseWriter, r *http.Request, number string, groupid string, depart any, arrive any, accounts []any, cacheid string, searched bool, beneficiary any, group any, beneficiaries []mobilityaccountsstorage.Account, groups map[string]any) {
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.journeys.display.files")
|
files := renderer.ThemeConfig.GetStringSlice("views.journeys.display.files")
|
||||||
state := NewState(r, renderer.ThemeConfig, journeysMenu)
|
state := NewState(r, renderer.ThemeConfig, journeysMenu)
|
||||||
|
|
||||||
@@ -128,6 +113,11 @@ func (renderer *Renderer) DisplayGroupCovoiturage(w http.ResponseWriter, r *http
|
|||||||
"beneficiaries": beneficiaries,
|
"beneficiaries": beneficiaries,
|
||||||
"searched": searched,
|
"searched": searched,
|
||||||
"group": group,
|
"group": group,
|
||||||
|
"deeparture": depart,
|
||||||
|
"deestination": arrive,
|
||||||
|
"groups": groups,
|
||||||
|
"ben": accounts,
|
||||||
|
"number": number,
|
||||||
"list": BeneficiariesCovoiturage{
|
"list": BeneficiariesCovoiturage{
|
||||||
Group: groupid,
|
Group: groupid,
|
||||||
Count: len(accounts),
|
Count: len(accounts),
|
||||||
@@ -142,8 +132,19 @@ func (renderer *Renderer) DisplayGroupCovoiturage(w http.ResponseWriter, r *http
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
state.ViewState = viewstate
|
state.ViewState = viewstate
|
||||||
|
|
||||||
renderer.Render("journeys", w, r, files, state)
|
renderer.Render("journeys", w, r, files, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (renderer *Renderer) UpdateGroupCovoiturage(w http.ResponseWriter, r *http.Request, groupid string, memberid string) {
|
||||||
|
files := renderer.ThemeConfig.GetStringSlice("views.journeys.update.files")
|
||||||
|
state := NewState(r, renderer.ThemeConfig, journeysMenu)
|
||||||
|
|
||||||
|
state.ViewState = map[string]any{
|
||||||
|
"groupid": groupid,
|
||||||
|
"memberid": memberid,
|
||||||
|
}
|
||||||
|
renderer.Render("journeys", w, r, files, state)
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
24
renderer/members.go
Normal file
24
renderer/members.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package renderer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
const membersMenu = "members"
|
||||||
|
|
||||||
|
func (renderer *Renderer) MemberDisplay(w http.ResponseWriter, r *http.Request, admins any) {
|
||||||
|
files := renderer.ThemeConfig.GetStringSlice("views.members.display.files")
|
||||||
|
|
||||||
|
state := NewState(r, renderer.ThemeConfig, membersMenu)
|
||||||
|
state.ViewState = map[string]any{
|
||||||
|
"admins": admins,
|
||||||
|
}
|
||||||
|
renderer.Render("members_list", w, r, files, state)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (renderer *Renderer) MemberUpdate(w http.ResponseWriter, r *http.Request, user any) {
|
||||||
|
files := renderer.ThemeConfig.GetStringSlice("views.members.update.files")
|
||||||
|
state := NewState(r, renderer.ThemeConfig, membersMenu)
|
||||||
|
state.ViewState = user
|
||||||
|
renderer.Render("members_update", w, r, files, state)
|
||||||
|
}
|
||||||
@@ -240,7 +240,14 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
|
|||||||
Icon: "hero:outline/document-text",
|
Icon: "hero:outline/document-text",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if modules["conseillers"] != nil && modules["conseillers"].(bool) {
|
||||||
|
ls.MenuItems = append(ls.MenuItems, MenuItem{
|
||||||
|
Title: "Conseillers",
|
||||||
|
Link: "/app/conseillers/",
|
||||||
|
Active: menuState == membersMenu,
|
||||||
|
Icon: "hero:outline/user-group",
|
||||||
|
})
|
||||||
|
}
|
||||||
return RenderState{
|
return RenderState{
|
||||||
IconSet: icons.NewIconSet(iconset),
|
IconSet: icons.NewIconSet(iconset),
|
||||||
Group: group,
|
Group: group,
|
||||||
|
|||||||
@@ -67,11 +67,13 @@ func (renderer *Renderer) VehicleBookingDisplay(w http.ResponseWriter, r *http.R
|
|||||||
renderer.Render("vehicles search", w, r, files, state)
|
renderer.Render("vehicles search", w, r, files, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (renderer *Renderer) VehicleBookingsList(w http.ResponseWriter, r *http.Request, bookings []storage.Booking) {
|
func (renderer *Renderer) VehicleBookingsList(w http.ResponseWriter, r *http.Request, bookings []storage.Booking, vehiclesMap any, groupsMap any) {
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.vehicles.bookings_list.files")
|
files := renderer.ThemeConfig.GetStringSlice("views.vehicles.bookings_list.files")
|
||||||
state := NewState(r, renderer.ThemeConfig, vehiclesMenu)
|
state := NewState(r, renderer.ThemeConfig, vehiclesMenu)
|
||||||
state.ViewState = map[string]any{
|
state.ViewState = map[string]any{
|
||||||
"bookings": bookings,
|
"bookings": bookings,
|
||||||
|
"vehicles_map": vehiclesMap,
|
||||||
|
"groups_map": groupsMap,
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.Render("vehicles search", w, r, files, state)
|
renderer.Render("vehicles search", w, r, files, state)
|
||||||
|
|||||||
@@ -52,3 +52,17 @@ func (s *ServicesHandler) GetBookings() (bookings []storage.Booking, err error)
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ServicesHandler) GetVehiclesMap() (vehicles map[string]storage.Vehicle, err error) {
|
||||||
|
vehicles = map[string]storage.Vehicle{}
|
||||||
|
|
||||||
|
request := &fleets.GetVehiclesRequest{}
|
||||||
|
resp, err := s.GRPC.Fleets.GetVehicles(context.TODO(), request)
|
||||||
|
if err == nil {
|
||||||
|
for _, vehicle := range resp.Vehicles {
|
||||||
|
vehicles[vehicle.Id] = vehicle.ToStorageType()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package services
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||||
|
"git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,3 +24,35 @@ func NewGroupsManagementService(groupsManagementDial string) (*GroupsManagementS
|
|||||||
GroupsManagementClient: client,
|
GroupsManagementClient: client,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ServicesHandler) GetGroupsMap() (groups map[string]storage.Group, err error) {
|
||||||
|
groups = map[string]storage.Group{}
|
||||||
|
|
||||||
|
request := &groupsmanagement.GetGroupsRequest{
|
||||||
|
Namespaces: []string{"parcoursmob_organizations"},
|
||||||
|
}
|
||||||
|
resp, err := s.GRPC.GroupsManagement.GetGroups(context.TODO(), request)
|
||||||
|
if err == nil {
|
||||||
|
for _, group := range resp.Groups {
|
||||||
|
groups[group.Id] = group.ToStorageType()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////optimize the code//////////////////////////////////////
|
||||||
|
func (s *ServicesHandler) GetGroupsMemberMap(id string) (groups map[string]any, err error) {
|
||||||
|
groups = map[string]any{}
|
||||||
|
|
||||||
|
request := &groupsmanagement.GetGroupsBatchMemberRequest{
|
||||||
|
Groupids: []string{id},
|
||||||
|
}
|
||||||
|
resp, err := s.GRPC.GroupsManagement.GetGroupsBatchMember(context.TODO(), request)
|
||||||
|
if err == nil {
|
||||||
|
for _, group := range resp.Groups {
|
||||||
|
groups[group.Memberid] = group.ToStorageType()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user