add address od members and draw position map
This commit is contained in:
parent
e03f31d3f4
commit
774a3c2301
2
go.mod
2
go.mod
|
@ -4,7 +4,7 @@ go 1.18
|
|||
|
||||
// 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/
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -183,11 +184,9 @@ func (h *ApplicationHandler) GroupsGestion(w http.ResponseWriter, r *http.Reques
|
|||
g := group.ToStorageType()
|
||||
groups = append(groups, g)
|
||||
}
|
||||
//////////////////
|
||||
|
||||
cacheid := uuid.NewString()
|
||||
|
||||
/////////////////
|
||||
sort.Sort(GroupsModule(groups))
|
||||
h.cache.PutWithTTL(cacheid, groups, 1*time.Hour)
|
||||
|
||||
|
@ -254,7 +253,6 @@ func (h *ApplicationHandler) CreateGroup(w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
if r.FormValue("departure") != "" {
|
||||
var a any
|
||||
json.Unmarshal([]byte(r.FormValue("departure")), &a)
|
||||
|
@ -386,7 +384,6 @@ func (h *ApplicationHandler) DisplayGroupCovoiturage(w http.ResponseWriter, r *h
|
|||
r.ParseForm()
|
||||
|
||||
var beneficiary any
|
||||
|
||||
searched := false
|
||||
|
||||
if r.FormValue("beneficiaryid") != "" {
|
||||
|
@ -437,7 +434,7 @@ func (h *ApplicationHandler) DisplayGroupCovoiturage(w http.ResponseWriter, r *h
|
|||
"depart": Depart,
|
||||
"arrive": Arrive,
|
||||
}
|
||||
|
||||
id := uuid.NewString()
|
||||
data, err := structpb.NewValue(dataMap)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
@ -445,26 +442,46 @@ func (h *ApplicationHandler) DisplayGroupCovoiturage(w http.ResponseWriter, r *h
|
|||
return
|
||||
}
|
||||
|
||||
request_organizatio := &groupsmanagement.SubscribeMemberRequest{
|
||||
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.SubscribeMember(context.TODO(), request_organizatio)
|
||||
_, 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()
|
||||
}
|
||||
}
|
||||
|
||||
var number string = strconv.Itoa(len(resp.Group.Members))
|
||||
/////////////////////
|
||||
accountsBeneficaire, err := h.beneficiaries(r)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
@ -472,5 +489,77 @@ func (h *ApplicationHandler) DisplayGroupCovoiturage(w http.ResponseWriter, r *h
|
|||
return
|
||||
}
|
||||
|
||||
h.Renderer.DisplayGroupCovoiturage(w, r, resp.Group.ToStorageType().ID, Depart, Arrive, accounts, cacheid, searched, beneficiary, resp.Group.ToStorageType(), accountsBeneficaire)
|
||||
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)
|
||||
}
|
||||
|
|
1
main.go
1
main.go
|
@ -112,6 +112,7 @@ func main() {
|
|||
application.HandleFunc("/journeys/groups_covoiturage", applicationHandler.GroupsGestion)
|
||||
application.HandleFunc("/journeys/groups_covoiturage/create", applicationHandler.CreateGroup)
|
||||
application.HandleFunc("/journeys/groups_covoiturage/create/{groupid}", applicationHandler.DisplayGroupCovoiturage)
|
||||
application.HandleFunc("/journeys/groups_covoiturage/create/{id}/{groupid}/{memberid}", applicationHandler.UpdateGroupCovoiturage)
|
||||
/****************************************************************/
|
||||
|
||||
/********************Code Supprt Emailing************************/
|
||||
|
|
|
@ -105,7 +105,7 @@ func (renderer *Renderer) CreateGroup(w http.ResponseWriter, r *http.Request, de
|
|||
renderer.Render("journeys", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) DisplayGroupCovoiturage(w http.ResponseWriter, r *http.Request, groupid string, depart any, arrive any, 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")
|
||||
state := NewState(r, renderer.ThemeConfig, journeysMenu)
|
||||
|
||||
|
@ -115,6 +115,9 @@ func (renderer *Renderer) DisplayGroupCovoiturage(w http.ResponseWriter, r *http
|
|||
"group": group,
|
||||
"deeparture": depart,
|
||||
"deestination": arrive,
|
||||
"groups": groups,
|
||||
"ben": accounts,
|
||||
"number": number,
|
||||
"list": BeneficiariesCovoiturage{
|
||||
Group: groupid,
|
||||
Count: len(accounts),
|
||||
|
@ -129,8 +132,19 @@ func (renderer *Renderer) DisplayGroupCovoiturage(w http.ResponseWriter, r *http
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue