solidarity-service/handler/services.go

97 lines
3.0 KiB
Go
Raw Normal View History

2023-10-20 11:41:39 +00:00
package handler
import (
"context"
"solidarity-service/internal"
2024-09-25 13:16:34 +00:00
"github.com/paulmach/orb/geojson"
2023-10-20 11:41:39 +00:00
)
func (s *SolidarityServiceHandler) GetPassenger(ctx context.Context, id string) (passenger internal.Passenger, err error) {
passenger, err = s.Storage.GetPassenger(id)
if err != nil {
return internal.Passenger{}, err
}
return passenger, nil
}
2024-09-25 13:16:34 +00:00
func (s *SolidarityServiceHandler) GetAllPassengers(ctx context.Context) (passengers []internal.Passenger, err error) {
passengers, err = s.Storage.GetAllPassengers()
if err != nil {
return []internal.Passenger{}, err
}
return passengers, nil
}
2023-10-20 11:41:39 +00:00
func (s *SolidarityServiceHandler) GetDriver(ctx context.Context, id string) (driver internal.Driver, err error) {
driver, err = s.Storage.GetDriver(id)
if err != nil {
return internal.Driver{}, err
}
return driver, nil
}
func (s *SolidarityServiceHandler) SetDriverAvailabilities(ctx context.Context, driver internal.Driver) (err error) {
driver.Driver.Operator = "internal-grpc"
err = s.Storage.CreateDriver(driver)
2023-12-08 06:31:41 +00:00
return err
2023-10-20 11:41:39 +00:00
}
func (s *SolidarityServiceHandler) SetPassengerTrip(ctx context.Context, passenger internal.Passenger) (err error) {
passenger.Passenger.Operator = "internal-grpc"
err = s.Storage.CreatePassenger(passenger)
if err != nil {
return err
}
return nil
}
func (s *SolidarityServiceHandler) CreateBooking(ctx context.Context, bookingRequest internal.BookingRequest) (passenger internal.Passenger, driver internal.Driver, err error) {
bookingRequest.Operator = "internal-grpc"
err = s.Storage.CreateBooking(bookingRequest)
if err != nil {
return internal.Passenger{}, internal.Driver{}, err
}
passenger, err = s.Storage.GetPassenger(bookingRequest.Passenger_id)
if err != nil {
return internal.Passenger{}, internal.Driver{}, err
}
driver, err = s.Storage.GetDriver(bookingRequest.Driver_id)
if err != nil {
return internal.Passenger{}, internal.Driver{}, err
}
return passenger, driver, nil
}
func (s *SolidarityServiceHandler) UpdateBooking(ctx context.Context, bookingId string, status internal.BookingStatus) (err error) {
err = s.Storage.UpdateBookingStatus(bookingId, status)
if err != nil {
return err
}
return nil
}
2023-12-08 06:31:41 +00:00
func (s *SolidarityServiceHandler) GetBooking(ctx context.Context, bookingId string) (booking internal.Booking, err error) {
2023-10-20 11:41:39 +00:00
booking, err = s.Storage.GetBooking(bookingId)
if err != nil {
2023-12-08 06:31:41 +00:00
return internal.Booking{}, err
2023-10-20 11:41:39 +00:00
}
2023-12-08 06:31:41 +00:00
return booking, nil
2023-10-20 11:41:39 +00:00
}
func (s *SolidarityServiceHandler) GetBookingsByStatus(ctx context.Context, status string, filterType string, id string) (bookings []internal.Booking, err error) {
bookings, err = s.Storage.FilterUserBookingsByStatus(filterType, internal.BookingStatus(status), id)
if err != nil {
return nil, err
}
return bookings, nil
}
func (s *SolidarityServiceHandler) GetDriverJourneys(ctx context.Context, departure_route *geojson.Feature, departure_date int64) (drivers []internal.Driver, err error) {
drivers, err = s.Storage.DriverJourneys(departure_route, departure_date)
if err != nil {
return nil, err
}
return drivers, nil
}