parcoursmob/services/groupsmanagement.go

65 lines
1.6 KiB
Go
Raw Normal View History

package services
import (
2023-01-23 09:15:23 +00:00
"context"
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
2023-01-23 09:15:23 +00:00
"git.coopgo.io/coopgo-platform/groups-management/storage"
"google.golang.org/grpc"
)
type GroupsManagementService struct {
groupsmanagement.GroupsManagementClient
}
func NewGroupsManagementService(groupsManagementDial string) (*GroupsManagementService, error) {
groupsManagementConn, err := grpc.Dial(groupsManagementDial, grpc.WithInsecure())
client := groupsmanagement.NewGroupsManagementClient(groupsManagementConn)
if err != nil {
return nil, err
}
return &GroupsManagementService{
GroupsManagementClient: client,
}, nil
}
2023-01-23 09:15:23 +00:00
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//////////////////////////////////////
2023-01-23 09:15:23 +00:00
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
}
// Enriched types
type GroupsManagementGroup struct {
storage.Group
}