initial commit

This commit is contained in:
2023-03-27 20:54:56 +02:00
commit 77c8576254
40 changed files with 7460 additions and 0 deletions

18
servers/ocss-api/book.go Normal file
View File

@@ -0,0 +1,18 @@
package ocssapi
import (
"context"
"errors"
"git.coopgo.io/coopgo-platform/carpool-service/interoperability/ocss"
)
func (s *OCSSApiService) PostBookings(ctx context.Context, booking ocss.Booking) (*ocss.Booking, error) {
return nil, errors.New("method not implmeented - PostBookings")
}
func (s *OCSSApiService) PatchBooking(ctx context.Context, bookingId string, status ocss.BookingStatus, message *string) error {
return errors.New("method not implmeented - PatchBooking")
}
func (s *OCSSApiService) GetBooking(ctx context.Context, bookingId string) (*ocss.Booking, error) {
return nil, errors.New("method not implmeented - GetBooking")
}

View File

@@ -0,0 +1,12 @@
package ocssapi
import (
"context"
"errors"
"git.coopgo.io/coopgo-platform/carpool-service/interoperability/ocss"
)
func (s *OCSSApiService) PostBookingEvents(ctx context.Context, event ocss.CarpoolBookingEvent) error {
return errors.New("method not implmeented - GetBooking")
}

View File

@@ -0,0 +1,53 @@
package ocssapi
import (
"net/http"
"time"
"github.com/rs/zerolog/log"
"git.coopgo.io/coopgo-platform/carpool-service/handler"
"git.coopgo.io/coopgo-platform/carpool-service/interoperability/ocss"
"github.com/spf13/viper"
)
type OCSSApiService struct {
Handler *handler.CarpoolServiceHandler
}
func NewOCSSApiService(handler *handler.CarpoolServiceHandler) (*OCSSApiService, error) {
return &OCSSApiService{
Handler: handler,
}, nil
}
// Status
func (s *OCSSApiService) Status() error {
return nil
}
func Run(done chan error, cfg *viper.Viper, handler *handler.CarpoolServiceHandler) {
var (
address = ":" + cfg.GetString("services.ocss_api.port")
)
service, err := NewOCSSApiService(handler)
if err != nil {
log.Fatal().Err(err).Msg("could not initialize OCSS api service")
return
}
err = http.ListenAndServe(address, ocss.NewServer(service))
srv := &http.Server{
Handler: ocss.NewServer(service),
Addr: address,
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
err = srv.ListenAndServe()
log.Error().Err(err).Msg("OCSS api error")
done <- err
}

View File

@@ -0,0 +1,42 @@
package ocssapi
import (
"context"
"errors"
"time"
"git.coopgo.io/coopgo-platform/carpool-service/interoperability/ocss"
"github.com/paulmach/orb"
)
func (s *OCSSApiService) GetDriverJourneys(ctx context.Context, departureLat float64, departureLng float64, arrivalLat float64, arrivalLng float64, departureDate time.Time, timeDelta *time.Duration, departureRadius *float64, arrivalRadius *float64, count *int64) ([]ocss.DriverJourney, error) {
departure := orb.Point{departureLng, departureLat}
arrival := orb.Point{arrivalLng, arrivalLat}
td := 900 * time.Second
if timeDelta != nil {
td = *timeDelta
}
minDate := departureDate.Add(-td * time.Second)
maxDate := departureDate.Add(td * time.Second)
result, err := s.Handler.GetDriverJourneys(departure, arrival, minDate, maxDate)
if err != nil {
return nil, err
}
return result, nil
}
func (s *OCSSApiService) GetPassengerJourneys(ctx context.Context, departureLat float64, departureLng float64, arrivalLat float64, arrivalLng float64, departureDate time.Time, timeDelta *time.Duration, departureRadius *float64, arrivalRadius *float64, count *int64) ([]ocss.PassengerJourney, error) {
return nil, errors.New("method not implmeented - GetPassengerJourneys")
}
func (s *OCSSApiService) GetDriverRegularTrips(ctx context.Context, departureLat float64, departureLng float64, arrivalLat float64, arrivalLng float64, departureTimeOfDay string, departureWeekDays *[]string, timeDelta *time.Duration, departureRadius *float64, arrivalRadius *float64, minDepartureDate *time.Time, maxDepartureDate *time.Time, count *int64) ([]ocss.DriverTrip, error) {
return []ocss.DriverTrip{}, nil
}
func (s *OCSSApiService) GetPassengerRegularTrips(ctx context.Context, departureLat float64, departureLng float64, arrivalLat float64, arrivalLng float64, departureTimeOfDay string, departureWeekDays *[]string, timeDelta *time.Duration, departureRadius *float64, arrivalRadius *float64, minDepartureDate *time.Time, maxDepartureDate *time.Time, count *int64) ([]ocss.PassengerTrip, error) {
return []ocss.PassengerTrip{}, nil
}