2022-08-12 12:53:54 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
2022-12-05 19:06:22 +00:00
|
|
|
"context"
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
2022-08-12 12:53:54 +00:00
|
|
|
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
|
2022-12-05 19:06:22 +00:00
|
|
|
"git.coopgo.io/coopgo-platform/fleets/storage"
|
2022-08-12 12:53:54 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
type FleetsService struct {
|
|
|
|
fleets.FleetsClient
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewFleetsService(dial string) (*FleetsService, error) {
|
|
|
|
conn, err := grpc.Dial(dial, grpc.WithInsecure())
|
|
|
|
|
|
|
|
client := fleets.NewFleetsClient(conn)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &FleetsService{
|
|
|
|
FleetsClient: client,
|
|
|
|
}, nil
|
|
|
|
}
|
2022-12-05 19:06:22 +00:00
|
|
|
|
|
|
|
func (s *ServicesHandler) GetBooking(bookingid string) (booking storage.Booking, err error) {
|
|
|
|
request := &fleets.GetBookingRequest{
|
|
|
|
Bookingid: bookingid,
|
|
|
|
}
|
|
|
|
resp, err := s.GRPC.Fleets.GetBooking(context.TODO(), request)
|
|
|
|
if err == nil {
|
|
|
|
booking = resp.Booking.ToStorageType()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ServicesHandler) GetBookings() (bookings []storage.Booking, err error) {
|
|
|
|
bookings = []storage.Booking{}
|
|
|
|
|
|
|
|
request := &fleets.GetBookingsRequest{}
|
|
|
|
resp, err := s.GRPC.Fleets.GetBookings(context.TODO(), request)
|
|
|
|
if err == nil {
|
|
|
|
for _, booking := range resp.Bookings {
|
|
|
|
bookings = append(bookings, booking.ToStorageType())
|
|
|
|
}
|
|
|
|
sort.Sort(sorting.BookingsByStartdate(bookings))
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2023-01-17 07:31:07 +00:00
|
|
|
|
|
|
|
func (s *ServicesHandler) GetVehiclesMap() (vehicles map[string]storage.Vehicle, err error) {
|
|
|
|
vehicles = map[string]storage.Vehicle{}
|
|
|
|
|
|
|
|
request := &fleets.GetVehiclesRequest{}
|
|
|
|
resp, err := s.GRPC.Fleets.GetVehicles(context.TODO(), request)
|
|
|
|
if err == nil {
|
|
|
|
for _, vehicle := range resp.Vehicles {
|
|
|
|
vehicles[vehicle.Id] = vehicle.ToStorageType()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|