diff --git a/handlers/application/journeys.go b/handlers/application/journeys.go index 3aa2055..c8f143b 100644 --- a/handlers/application/journeys.go +++ b/handlers/application/journeys.go @@ -462,24 +462,27 @@ func (h *ApplicationHandler) DisplayGroupCovoiturage(w http.ResponseWriter, r *h return } //////////find all groups to store the adresse passenger/////// - grp := &groupsmanagement.GetGroupsBatchMemberRequest{ + // 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() - } - } + // 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) diff --git a/services/groupsmanagement.go b/services/groupsmanagement.go index f5bf047..08647b7 100644 --- a/services/groupsmanagement.go +++ b/services/groupsmanagement.go @@ -1,7 +1,10 @@ package services import ( + "context" + groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi" + "git.coopgo.io/coopgo-platform/groups-management/storage" "google.golang.org/grpc" ) @@ -21,3 +24,35 @@ func NewGroupsManagementService(groupsManagementDial string) (*GroupsManagementS GroupsManagementClient: client, }, 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 +}