2022-09-05 05:25:05 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
2024-11-20 23:54:52 +00:00
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2022-09-05 05:25:05 +00:00
|
|
|
agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi"
|
2024-11-20 23:54:52 +00:00
|
|
|
"git.coopgo.io/coopgo-platform/agenda/storage"
|
2022-09-05 05:25:05 +00:00
|
|
|
"google.golang.org/grpc"
|
2024-11-20 23:54:52 +00:00
|
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
2022-09-05 05:25:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type AgendaService struct {
|
|
|
|
agenda.AgendaClient
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAgendaService(dial string) (*AgendaService, error) {
|
|
|
|
conn, err := grpc.Dial(dial, grpc.WithInsecure())
|
|
|
|
|
|
|
|
client := agenda.NewAgendaClient(conn)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &AgendaService{
|
|
|
|
AgendaClient: client,
|
|
|
|
}, nil
|
|
|
|
}
|
2024-11-20 23:54:52 +00:00
|
|
|
|
|
|
|
func (s *ServicesHandler) GetAgendaEvents() ([]AgendaEvent, error) {
|
|
|
|
resp, err := s.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
|
|
|
Namespaces: []string{"parcoursmob_dispositifs"},
|
|
|
|
Mindate: timestamppb.New(time.Now().Add(-24 * time.Hour)),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
groups, err := s.GetGroupsMap()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error in groups request : %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
events := []AgendaEvent{}
|
|
|
|
|
|
|
|
for _, e := range resp.Events {
|
|
|
|
newEvent := AgendaEvent{
|
|
|
|
Event: e.ToStorageType(),
|
|
|
|
}
|
|
|
|
for _, o := range e.Owners {
|
|
|
|
newEvent.OwnersGroups = append(newEvent.OwnersGroups, GroupsManagementGroup{Group: groups[o]})
|
|
|
|
}
|
|
|
|
events = append(events, newEvent)
|
|
|
|
}
|
|
|
|
|
|
|
|
return events, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enriched types
|
|
|
|
|
|
|
|
type AgendaEvent struct {
|
|
|
|
OwnersGroups []GroupsManagementGroup
|
|
|
|
storage.Event
|
|
|
|
}
|