refactoring
This commit is contained in:
@@ -208,17 +208,26 @@ func (s MobilityAccountService) ToAccountModel(account ma.Account) *models.Accou
|
||||
if !ok {
|
||||
accountType = ""
|
||||
}
|
||||
phone_number, ok := account.Data["phone_number"].(string)
|
||||
if !ok {
|
||||
phone_number = ""
|
||||
}
|
||||
email, ok := account.Data["email"].(string)
|
||||
if !ok {
|
||||
email = ""
|
||||
}
|
||||
return &models.Account{
|
||||
ID: account.ID,
|
||||
FirstName: first_name,
|
||||
LastName: last_name,
|
||||
Email: email,
|
||||
BirthDate: birth_date,
|
||||
Type: accountType,
|
||||
LocalCredentials: models.LocalCredentials{
|
||||
Email: account.Authentication.Local.Email,
|
||||
EmailVerified: account.Authentication.Local.EmailValidation.Validated,
|
||||
EmailValidationCode: account.Authentication.Local.EmailValidation.ValidationCode,
|
||||
PhoneNumber: account.Authentication.Local.PhoneNumber,
|
||||
PhoneNumber: phone_number,
|
||||
PhoneNumberVerified: account.Authentication.Local.PhoneNumberValidation.Validated,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
|
||||
"github.com/appleboy/gorush/rpc/proto"
|
||||
"github.com/rs/zerolog/log"
|
||||
@@ -26,6 +27,8 @@ type Notification struct {
|
||||
Recipients []string
|
||||
Message string
|
||||
Title string
|
||||
Data *structpb.Struct
|
||||
ID string
|
||||
}
|
||||
|
||||
type PushService struct {
|
||||
@@ -53,6 +56,8 @@ func (s *PushService) Send(notification Notification) error {
|
||||
Msg("Send notification")
|
||||
|
||||
resp, err := s.Client.Send(context.Background(), &proto.NotificationRequest{
|
||||
Data: notification.Data,
|
||||
ID: notification.ID,
|
||||
Platform: notification.Platform,
|
||||
Tokens: notification.Recipients,
|
||||
Message: notification.Message,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"git.coopgo.io/coopgo-platform/geocode"
|
||||
routing "git.coopgo.io/coopgo-platform/routing-service"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
@@ -8,12 +10,18 @@ import (
|
||||
type ServicesHandler struct {
|
||||
MobilityAccounts MobilityAccountService
|
||||
Push *PushService
|
||||
Geocoder geocode.Geocoder
|
||||
Routing routing.RoutingService
|
||||
}
|
||||
|
||||
func NewServicesHandler(cfg *viper.Viper) (*ServicesHandler, error) {
|
||||
var (
|
||||
mobilityAccountsDial = cfg.GetString("services.internal.mobility_accounts.dial")
|
||||
pushDial = cfg.GetString("services.internal.push.dial")
|
||||
geocoder_type = cfg.GetString("geocoder.type")
|
||||
pelias_base_url = cfg.GetString("geocoder.pelias.base_url")
|
||||
routing_service_type = cfg.GetString("routing.type")
|
||||
valhalla_base_url = cfg.GetString("routing.valhalla.base_url")
|
||||
)
|
||||
mobilityAccounts, err := NewMobilityAccountService(mobilityAccountsDial)
|
||||
if err != nil {
|
||||
@@ -25,9 +33,22 @@ func NewServicesHandler(cfg *viper.Viper) (*ServicesHandler, error) {
|
||||
log.Fatal().Err(err).Msg("Could not connect to Push Notifications Service")
|
||||
return nil, err
|
||||
}
|
||||
geocoder, err := geocode.NewGeocoder(geocoder_type, pelias_base_url)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Could not initiate the Geocoder service")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
routing, err := routing.NewRoutingService(routing_service_type, valhalla_base_url)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Could not initiate the routing service")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ServicesHandler{
|
||||
MobilityAccounts: mobilityAccounts,
|
||||
Push: push,
|
||||
Geocoder: geocoder,
|
||||
Routing: routing,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user