optimize code
This commit is contained in:
parent
774a3c2301
commit
40cf6012a6
|
@ -462,24 +462,27 @@ func (h *ApplicationHandler) DisplayGroupCovoiturage(w http.ResponseWriter, r *h
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//////////find all groups to store the adresse passenger///////
|
//////////find all groups to store the adresse passenger///////
|
||||||
grp := &groupsmanagement.GetGroupsBatchMemberRequest{
|
// grp := &groupsmanagement.GetGroupsBatchMemberRequest{
|
||||||
|
|
||||||
Groupids: []string{resp.Group.ToStorageType().ID},
|
// Groupids: []string{resp.Group.ToStorageType().ID},
|
||||||
}
|
// }
|
||||||
s, err := h.services.GRPC.GroupsManagement.GetGroupsBatchMember(context.TODO(), grp)
|
// s, err := h.services.GRPC.GroupsManagement.GetGroupsBatchMember(context.TODO(), grp)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
fmt.Println(err)
|
// fmt.Println(err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
// w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
groups := map[string]any{}
|
// groups := map[string]any{}
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
for _, g := range s.Groups {
|
|
||||||
groups[g.Memberid] = g.ToStorageType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 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))
|
var number string = strconv.Itoa(len(resp.Group.Members))
|
||||||
/////////////////////
|
/////////////////////
|
||||||
accountsBeneficaire, err := h.beneficiaries(r)
|
accountsBeneficaire, err := h.beneficiaries(r)
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue