27 Commits

Author SHA1 Message Date
f09d9d0a16 sending mail to the prescripteur when beneficiary is delete 2023-02-23 12:33:20 +01:00
soukainna
11e2375456 fix profile err 2023-02-23 09:52:11 +01:00
soukainna
e11514b6d5 fix agenda file to compile 2023-02-22 15:00:07 +01:00
soukainna
3bfce72512 Merge branch 'infoAboutGroupMember' into dev 2023-02-22 14:04:09 +01:00
soukainna
335656ec75 Merge branch 'modifyAnEvent' into dev 2023-02-22 12:47:29 +01:00
f698891865 sending mail to the prescripteur 2023-02-22 11:50:53 +01:00
soukainna
5d33ba3dcb fix the update profile err 2023-02-17 17:24:10 +01:00
193f5dfb6f display_name is functional for unsubscribe data 2023-02-17 14:51:43 +01:00
soukainna
af9626e2c4 fix display name for all subscribed_by 2023-02-17 14:24:29 +01:00
49de2f22c4 delete consol log 2023-02-15 14:26:10 +01:00
soukainna
d3df781e33 try to fix display name 2023-02-15 11:22:18 +01:00
ab8cbf6f73 add visualization off history page 2023-02-15 10:12:58 +01:00
10bde53c5e add 'History' page 2023-02-08 09:36:12 +01:00
28c8fa8a90 add 'suscribed_by' in Data on DB 2023-02-03 15:23:49 +01:00
11851fec61 add 'suscribed_by' in Data on DB 2023-02-03 15:23:37 +01:00
696cd1d87f add 'Motif' in DB 2023-02-03 10:04:19 +01:00
soukainna
372647b3b9 delete subscription and store it in the delete 2023-02-01 16:06:18 +01:00
soukainna
56c1b45f45 store eventid and subid 2023-02-01 11:51:46 +01:00
soukainna
62f64747c3 add function to store eventid and subscriberid 2023-02-01 10:47:19 +01:00
56d0914568 init 2023-02-01 10:06:32 +01:00
soukainna
57accbddbb add function to update and delete event 2023-02-01 09:53:01 +01:00
soukainna
40cf6012a6 optimize code 2023-01-23 10:15:23 +01:00
soukainna
774a3c2301 add address od members and draw position map 2023-01-17 14:45:09 +01:00
soukainna
e03f31d3f4 fix some err 2023-01-04 16:12:49 +01:00
soukainna
a2b644d548 add more information about beneficaire in groupCovoiturage 2023-01-04 11:55:18 +01:00
soukainna
4c42d3efd3 Merge branch 'main' into groupsCovoiturage 2022-12-19 13:09:07 +01:00
soukainna
12a8a359ab create groups journeys 2022-12-07 11:12:43 +01:00
9 changed files with 966 additions and 24 deletions

4
go.mod
View File

@@ -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/

View File

@@ -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)
}

View File

@@ -5,14 +5,26 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"sort"
"strconv"
"strings"
"time" "time"
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi" fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
"github.com/google/uuid"
"github.com/gorilla/mux"
geojson "github.com/paulmach/go.geojson" geojson "github.com/paulmach/go.geojson"
"gitlab.scity.coop/maas/navitia-golang" "gitlab.scity.coop/maas/navitia-golang"
"gitlab.scity.coop/maas/navitia-golang/types" "gitlab.scity.coop/maas/navitia-golang/types"
"google.golang.org/protobuf/types/known/structpb"
) )
var Depart any
var Arrive any
func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Request) { func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Request) {
r.ParseForm() r.ParseForm()
@@ -144,3 +156,413 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
h.Renderer.JourneysSearch(w, r, carpoolresults, journeys, vehicles, searched, departuregeo, destinationgeo, departuredate, departuretime) h.Renderer.JourneysSearch(w, r, carpoolresults, journeys, vehicles, searched, departuregeo, destinationgeo, departuredate, departuretime)
} }
type GroupsModule []groupstorage.Group
func (a GroupsModule) Len() int { return len(a) }
func (a GroupsModule) Less(i, j int) bool {
return strings.Compare(a[i].Data["name"].(string), a[j].Data["name"].(string)) < 0
}
func (a GroupsModule) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (h *ApplicationHandler) GroupsGestion(w http.ResponseWriter, r *http.Request) {
request := &groupsmanagement.GetGroupsRequest{
Namespaces: []string{"parcoursmob_groups_covoiturage"},
}
resp, err := h.services.GRPC.GroupsManagement.GetGroups(context.TODO(), request)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
var groups = []groupstorage.Group{}
for _, group := range resp.Groups {
g := group.ToStorageType()
groups = append(groups, g)
}
cacheid := uuid.NewString()
sort.Sort(GroupsModule(groups))
h.cache.PutWithTTL(cacheid, groups, 1*time.Hour)
h.Renderer.GroupsGestion(w, r, groups, cacheid)
}
func filterAcc(r *http.Request, a *mobilityaccounts.Account) bool {
searchFilter, ok := r.URL.Query()["search"]
if ok && len(searchFilter[0]) > 0 {
name := a.Data.AsMap()["first_name"].(string) + " " + a.Data.AsMap()["last_name"].(string)
if !strings.Contains(strings.ToLower(name), strings.ToLower(searchFilter[0])) {
return false
}
}
return true
}
func (h *ApplicationHandler) CreateGroup(w http.ResponseWriter, r *http.Request) {
var beneficiary any
var (
departurgeo *geojson.Feature
dstinationgeo *geojson.Feature
)
searched := false
if r.FormValue("beneficiaryid") != "" {
searched = true
requestbeneficiary := &mobilityaccounts.GetAccountRequest{
Id: r.FormValue("beneficiaryid"),
}
respbeneficiary, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), requestbeneficiary)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
beneficiary = respbeneficiary.Account.ToStorageType()
if r.Method == "POST" {
departure := r.FormValue("departure")
destination := r.FormValue("destination")
if departure != "" && destination != "" {
var err error
departurgeo, err = geojson.UnmarshalFeature([]byte(departure))
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
dstinationgeo, err = geojson.UnmarshalFeature([]byte(destination))
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
}
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()
if r.FormValue("name") == "" {
fmt.Println("invalid name")
w.WriteHeader(http.StatusBadRequest)
return
}
if r.FormValue("number") == "" {
fmt.Println("invalid number of personne")
w.WriteHeader(http.StatusBadRequest)
return
}
planDays := map[string]any{
"lundi": r.FormValue("lundi") == "on",
"mardi": r.FormValue("mardi") == "on",
"mercredi": r.FormValue("mercredi") == "on",
"jeudi": r.FormValue("jeudi") == "on",
"vendredi": r.FormValue("vendredi") == "on",
"samedi": r.FormValue("samedi") == "on",
"dimanche": r.FormValue("dimanche") == "on",
}
groupidd := uuid.NewString()
dataMap := map[string]any{
"name": r.FormValue("name"),
"number": r.FormValue("number"),
"driver_first_name": respbeneficiary.Account.ToStorageType().Data["first_name"],
"driver_last_name": respbeneficiary.Account.ToStorageType().Data["last_name"],
"depart": Depart,
"arrive": Arrive,
"departdate": r.FormValue("departdate"),
"date": r.FormValue("date"),
"enddate": r.FormValue("enddate"),
"departtime": r.FormValue("departtime"),
"time": r.FormValue("time"),
"planDays": planDays,
"recurrent": r.FormValue("recurrent"),
"pontuelle": r.FormValue("ponctuelle"),
}
data, err := structpb.NewValue(dataMap)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
request_organization := &groupsmanagement.AddGroupRequest{
Group: &groupsmanagement.Group{
Id: groupidd,
Namespace: "parcoursmob_groups_covoiturage",
Data: data.GetStructValue(),
},
}
_, err = h.services.GRPC.GroupsManagement.AddGroup(context.TODO(), request_organization)
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)
return
}
}
accountsBeneficaire, err := h.beneficiaries(r)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
h.Renderer.CreateGroup(w, r, Depart, Arrive, searched, beneficiary, accountsBeneficaire, departurgeo, dstinationgeo)
}
func (h *ApplicationHandler) DisplayGroupCovoiturage(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
groupid := vars["groupid"]
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
}
var accounts = []any{}
requesst := &mobilityaccounts.GetAccountsBatchRequest{
Accountids: resp.Group.Members,
}
ressp, _ := h.services.GRPC.MobilityAccounts.GetAccountsBatch(context.TODO(), requesst)
for _, account := range ressp.Accounts {
if filterAcc(r, account) {
a := account.ToStorageType()
accounts = append(accounts, a)
}
}
cacheid := uuid.NewString()
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
r.ParseForm()
var beneficiary any
searched := false
if r.FormValue("beneficiaryid") != "" {
searched = true
requestbeneficiary := &mobilityaccounts.GetAccountRequest{
Id: r.FormValue("beneficiaryid"),
}
respbeneficiary, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), requestbeneficiary)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
beneficiary = respbeneficiary.Account.ToStorageType()
subscribe := &groupsmanagement.SubscribeRequest{
Groupid: resp.Group.ToStorageType().ID,
Memberid: respbeneficiary.Account.Id,
}
_, 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 {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
http.Redirect(w, r, fmt.Sprintf("/app/journeys/groups_covoiturage/create/%s", resp.Group.ToStorageType().ID), http.StatusFound)
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)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
h.Renderer.DisplayGroupCovoiturage(w, r, number, resp.Group.ToStorageType().ID, Depart, Arrive, accounts, cacheid, searched, beneficiary, resp.Group.ToStorageType(), accountsBeneficaire, groups)
}
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)
}

View File

@@ -16,7 +16,7 @@ type UserForm struct {
FirstName string `json:"first_name" validate:"required"` FirstName string `json:"first_name" validate:"required"`
LastName string `json:"last_name" validate:"required"` LastName string `json:"last_name" validate:"required"`
Email string `json:"email" validate:"required,email"` Email string `json:"email" validate:"required,email"`
PhoneNumber string `json:"phone_number" validate:"required,phoneNumber"` PhoneNumber string `json:"phone_number" `
Address any `json:"address,omitempty"` Address any `json:"address,omitempty"`
Gender string `json:"gender"` Gender string `json:"gender"`
} }
@@ -76,7 +76,7 @@ func (h *ApplicationHandler) MemberUpdate(w http.ResponseWriter, r *http.Request
return return
} }
http.Redirect(w, r, fmt.Sprintf("/app/profile/%s", resp.Account.Id), http.StatusFound) http.Redirect(w, r, fmt.Sprintf("/app/members/%s", resp.Account.Id), http.StatusFound)
return return
} }

View File

@@ -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,11 +46,13 @@ func (h *AuthHandler) Onboarding(w http.ResponseWriter, r *http.Request) {
}, },
}, },
Namespace: "parcoursmob", Namespace: "parcoursmob",
Data: map[string]any{ Data: map[string]any{
"first_name": r.FormValue("first_name"), "display_name": display_name,
"last_name": r.FormValue("last_name"), "first_name": r.FormValue("first_name"),
"email": onboardingmap["username"], "last_name": r.FormValue("last_name"),
"groups": groups, "email": onboardingmap["username"],
"groups": groups,
}, },
} }

16
main.go
View File

@@ -104,6 +104,11 @@ func main() {
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)
@@ -111,9 +116,10 @@ func main() {
application.HandleFunc("/group/settings/invite-member", applicationHandler.GroupSettingsInviteMember) application.HandleFunc("/group/settings/invite-member", applicationHandler.GroupSettingsInviteMember)
/****************************Groupe Déplacement ************************************/ /****************************Groupe Déplacement ************************************/
// 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************************/
@@ -137,6 +143,10 @@ func main() {
appAdmin.HandleFunc("/groups/{groupid}/invite-member", applicationHandler.AdministrationGroupInviteMember) appAdmin.HandleFunc("/groups/{groupid}/invite-member", applicationHandler.AdministrationGroupInviteMember)
appAdmin.HandleFunc("/stats/vehicles", applicationHandler.AdminStatVehicles) 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{

View File

@@ -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)
}

View File

@@ -1,9 +1,40 @@
package renderer package renderer
import "net/http" import (
"encoding/json"
"html/template"
"net/http"
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
)
const journeysMenu = "journeys" const journeysMenu = "journeys"
type BeneficiariesCovoiturage struct {
Group string `json:"group"`
Count int `json:"count"`
CacheId string `json:"cache_id"`
Beneficiaries []any `json:"beneficiaries"`
}
type BeneficiariesCovoiturageA struct {
Count int `json:"count"`
CacheId string `json:"cache_id"`
Beneficiaries []any `json:"beneficiaries"`
}
func (s BeneficiariesCovoiturage) JSON() template.JS {
result, _ := json.Marshal(s)
return template.JS(result)
}
func (s BeneficiariesCovoiturage) JSONWithLimits(a int, b int) template.JS {
if b < len(s.Beneficiaries) {
s.Beneficiaries = s.Beneficiaries[a:b]
}
return s.JSON()
}
func (renderer *Renderer) JourneysSearch(w http.ResponseWriter, r *http.Request, carpools any, transitjourneys any, vehicles []any, searched bool, departure any, destination any, departuredate string, departuretime string) { func (renderer *Renderer) JourneysSearch(w http.ResponseWriter, r *http.Request, carpools any, transitjourneys any, vehicles []any, searched bool, departure any, destination any, departuredate string, departuretime string) {
files := renderer.ThemeConfig.GetStringSlice("views.journeys.search.files") files := renderer.ThemeConfig.GetStringSlice("views.journeys.search.files")
state := NewState(r, renderer.ThemeConfig, journeysMenu) state := NewState(r, renderer.ThemeConfig, journeysMenu)
@@ -20,3 +51,100 @@ func (renderer *Renderer) JourneysSearch(w http.ResponseWriter, r *http.Request,
renderer.Render("journeys", w, r, files, state) renderer.Render("journeys", w, r, files, state)
} }
type BeneficiariesListstate struct {
Count int `json:"count"`
CacheId string `json:"cache_id"`
Beneficiaries []groupstorage.Group `json:"beneficiaries"`
}
func (s BeneficiariesListstate) JSON() template.JS {
result, _ := json.Marshal(s)
return template.JS(result)
}
func (s BeneficiariesListstate) JSONWithLimits(a int, b int) template.JS {
if b < len(s.Beneficiaries) {
s.Beneficiaries = s.Beneficiaries[a:b]
}
return s.JSON()
}
func (renderer *Renderer) GroupsGestion(w http.ResponseWriter, r *http.Request, groups []groupstorage.Group, cacheid string) {
files := renderer.ThemeConfig.GetStringSlice("views.journeys.list.files")
state := NewState(r, renderer.ThemeConfig, journeysMenu)
state.ViewState = BeneficiariesListstate{
Count: len(groups),
CacheId: cacheid,
Beneficiaries: groups,
}
renderer.Render("journeys", w, r, files, state)
}
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")
state := NewState(r, renderer.ThemeConfig, journeysMenu)
viewstate := map[string]any{
"deeparture": depart,
"deestination": arrive,
"beneficiaries": beneficiaries,
"searched": searched,
"departure": departure,
"destination": destination,
}
if searched {
viewstate["search"] = map[string]any{
"beneficiary": beneficiary,
}
}
state.ViewState = viewstate
renderer.Render("journeys", w, r, files, state)
}
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")
state := NewState(r, renderer.ThemeConfig, journeysMenu)
viewstate := map[string]any{
"beneficiaries": beneficiaries,
"searched": searched,
"group": group,
"deeparture": depart,
"deestination": arrive,
"groups": groups,
"ben": accounts,
"number": number,
"list": BeneficiariesCovoiturage{
Group: groupid,
Count: len(accounts),
CacheId: cacheid,
Beneficiaries: accounts,
},
}
if searched {
viewstate["search"] = map[string]any{
"beneficiary": beneficiary,
}
}
state.ViewState = viewstate
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)
}

View File

@@ -40,3 +40,19 @@ func (s *ServicesHandler) GetGroupsMap() (groups map[string]storage.Group, err e
return 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
}