2022-08-11 15:26:55 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
2022-12-05 19:06:22 +00:00
|
|
|
"context"
|
|
|
|
|
2022-08-11 15:26:55 +00:00
|
|
|
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
2022-12-05 19:06:22 +00:00
|
|
|
"git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
2022-08-11 15:26:55 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MobilityAccountService struct {
|
|
|
|
mobilityaccounts.MobilityAccountsClient
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMobilityAccountService(mobilityAccountsDial string) (*MobilityAccountService, error) {
|
|
|
|
mobilityAccountsConn, err := grpc.Dial(mobilityAccountsDial, grpc.WithInsecure())
|
|
|
|
|
|
|
|
client := mobilityaccounts.NewMobilityAccountsClient(mobilityAccountsConn)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &MobilityAccountService{
|
|
|
|
MobilityAccountsClient: client,
|
|
|
|
}, nil
|
|
|
|
}
|
2022-12-05 19:06:22 +00:00
|
|
|
|
|
|
|
func (s *ServicesHandler) GetBeneficiaries() (accounts []storage.Account, err error) {
|
|
|
|
accounts = []storage.Account{}
|
|
|
|
request := &mobilityaccounts.GetAccountsRequest{
|
|
|
|
Namespaces: []string{"parcoursmob_beneficiaries"},
|
|
|
|
}
|
|
|
|
resp, err := s.GRPC.MobilityAccounts.GetAccounts(context.TODO(), request)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
for _, v := range resp.Accounts {
|
|
|
|
a := v.ToStorageType()
|
|
|
|
accounts = append(accounts, a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-11-19 14:53:40 +00:00
|
|
|
func (s *ServicesHandler) GetBeneficiariesMap() (accounts map[string]storage.Account, err error) {
|
|
|
|
accounts = map[string]storage.Account{}
|
|
|
|
request := &mobilityaccounts.GetAccountsRequest{
|
|
|
|
Namespaces: []string{"parcoursmob_beneficiaries"},
|
|
|
|
}
|
|
|
|
resp, err := s.GRPC.MobilityAccounts.GetAccounts(context.TODO(), request)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
for _, v := range resp.Accounts {
|
|
|
|
accounts[v.Id] = v.ToStorageType()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-05 19:06:22 +00:00
|
|
|
func (s *ServicesHandler) GetAccounts() (accounts []storage.Account, err error) {
|
|
|
|
accounts = []storage.Account{}
|
|
|
|
request := &mobilityaccounts.GetAccountsRequest{
|
|
|
|
Namespaces: []string{"parcoursmob"},
|
|
|
|
}
|
|
|
|
resp, err := s.GRPC.MobilityAccounts.GetAccounts(context.TODO(), request)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
for _, v := range resp.Accounts {
|
|
|
|
a := v.ToStorageType()
|
|
|
|
accounts = append(accounts, a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|