66 lines
1.4 KiB
Go
Executable File
66 lines
1.4 KiB
Go
Executable File
package services
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi"
|
|
"git.coopgo.io/coopgo-platform/agenda/storage"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
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
|
|
}
|