solidarity-service/interoperability/solidarity-api/server/openapi/api_passenger_trip_request_...

64 lines
2.6 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/spf13/viper"
"net/http"
"solidarity-service/handler"
"solidarity-service/internal"
"solidarity-service/storage"
)
// 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.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 {
return Response(http.StatusInternalServerError, nil), errors.New("DriverPunctualAvailabilitiesPost internal server error")
} else {
return Response(201, "Trip request created"), nil
}
}