86 lines
3.5 KiB
Go
86 lines
3.5 KiB
Go
/*
|
|
* Solidarity Mobility API
|
|
*
|
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
*
|
|
* API version: 1.0.0
|
|
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
|
|
*/
|
|
|
|
package openapi
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"github.com/paulmach/orb"
|
|
"github.com/paulmach/orb/geojson"
|
|
"github.com/spf13/viper"
|
|
"net/http"
|
|
"solidarity-service/handler"
|
|
"solidarity-service/internal"
|
|
"solidarity-service/storage"
|
|
"solidarity-service/utils"
|
|
"strings"
|
|
)
|
|
|
|
// PassengerTripRequestAPIService is a service that implements the logic for the PassengerTripRequestAPIServicer
|
|
// This service should implement the business logic for every endpoint for the PassengerTripRequestAPI API.
|
|
// Include any external packages or services that will be required by this service.
|
|
type PassengerTripRequestAPIService struct {
|
|
config *viper.Viper
|
|
handler *handler.SolidarityServiceHandler
|
|
storage storage.Storage
|
|
}
|
|
|
|
// NewPassengerTripRequestAPIService creates a default api service
|
|
func NewPassengerTripRequestAPIService(config *viper.Viper, handler *handler.SolidarityServiceHandler, storage storage.Storage) PassengerTripRequestAPIServicer {
|
|
return &PassengerTripRequestAPIService{
|
|
config: config,
|
|
handler: handler,
|
|
storage: storage,
|
|
}
|
|
}
|
|
|
|
// PassengerPost - Create a Passenger Trip Request
|
|
func (s *PassengerTripRequestAPIService) PassengerPost(ctx context.Context, passengerTripRequest PassengerTripRequest) (ImplResponse, error) {
|
|
passenger := internal.Passenger{}
|
|
passenger.Passenger_departure_address = &geojson.Feature{
|
|
Type: "Feature",
|
|
Geometry: orb.Geometry(orb.Point{passengerTripRequest.DepartureLatitude, passengerTripRequest.DepartureLongitude}),
|
|
Properties: geojson.Properties{
|
|
"name": passengerTripRequest.DepartureAddress,
|
|
},
|
|
}
|
|
passenger.Passenger_destination_address = &geojson.Feature{
|
|
Type: "Feature",
|
|
Geometry: orb.Geometry(orb.Point{passengerTripRequest.DestinationLatitude, passengerTripRequest.DestinationLongitude}),
|
|
Properties: geojson.Properties{
|
|
"name": passengerTripRequest.DestinationAddress,
|
|
},
|
|
}
|
|
passenger.Passenger_pickup_date = int64(passengerTripRequest.DepartureDate)
|
|
passenger.Passenger.ID = passengerTripRequest.User.Id
|
|
passenger.Passenger.Operator = passengerTripRequest.User.Operator
|
|
passenger.Passenger.Alias = passengerTripRequest.User.Alias
|
|
passenger.Passenger.FirstName = passengerTripRequest.User.FirstName
|
|
passenger.Passenger.LastName = passengerTripRequest.User.LastName
|
|
passenger.Passenger.Picture = passengerTripRequest.User.Picture
|
|
passenger.Passenger.Grade = int64(passengerTripRequest.User.Grade)
|
|
passenger.Passenger.Gender = passengerTripRequest.User.Gender
|
|
passenger.Passenger.VerifiedIdentity = passengerTripRequest.User.VerifiedIdentity
|
|
passenger.Preferences.Animals = passengerTripRequest.Preferences.Animals
|
|
passenger.Preferences.Luggage_size = int64(passengerTripRequest.Preferences.LuggageSize)
|
|
passenger.Preferences.Smoking = passengerTripRequest.Preferences.Smoking
|
|
passenger.Preferences.Is_talker = passengerTripRequest.Preferences.IsTalker
|
|
passenger.Preferences.Music = passengerTripRequest.Preferences.Music
|
|
err := s.storage.CreatePassenger(passenger)
|
|
if err != nil {
|
|
if strings.Contains(err.Error(), utils.SQL_DUPLICATE) {
|
|
return Response(http.StatusBadRequest, "ID already in use"), nil
|
|
}
|
|
return Response(http.StatusInternalServerError, nil), errors.New("DriverPunctualAvailabilitiesPost internal server error")
|
|
} else {
|
|
return Response(201, "Trip request created"), nil
|
|
}
|
|
}
|