<commit_before>class API::V1::TripsController < API::ApiController
  before_action :authenticate_customer
  before_action :get_trip, :validate_trip_customer_match, except: [:create]

  def create
    authenticate_provider
    authenticate_trip_purpose

    from_address_params = (params[:from_address] || {}).merge({
        customer_id: @customer.id,
        provider_id: @provider.id
        })

    to_address_params = (params[:to_address] || {}).merge({
        customer_id: @customer.id,
        provider_id: @provider.id,
        trip_purpose_id: @trip_purpose.id
        })

    from_address = Address.parse_api_params(from_address_params)
    to_address = Address.parse_api_params(to_address_params)
    @trip = Trip.new(
      customer: @customer, 
      mobility: @customer.mobility,
      funding_source: @customer.default_funding_source,
      medicaid_eligible: @customer.medicaid_eligible,
      service_level: @customer.service_level,
      provider: @provider,
      trip_purpose: @trip_purpose,
      direction: Trip.parse_leg_as_direction(params[:leg]),
      pickup_time: Time.parse(params[:pickup_time]).in_time_zone,
      appointment_time: Time.parse(params[:dropoff_time]).in_time_zone,
      guest_count: params[:guests],
      attendant_count: params[:attendants], 
      mobility_device_accommodations: params[:mobility_devices],
      pickup_address: from_address,
      dropoff_address: to_address
    )

    if @trip.save
      render json: @trip.as_profile_json
    else 
      error(:unprocessable_entity, @trip.errors.full_messages.join(';'))
    end
  end

  def show
    render json: @trip.as_profile_json
  end

  def destroy

    if !@trip.cancel!
      render json: {}
    else
      error(:unprocessable_entity, @trip.errors.full_messages.join(';'))
    end
  end

  private 

  def authenticate_customer
    @customer = Customer.where(id: params[:customer_id], token: params[:customer_token]).first<commit_msg>[#106044646] Return OK once trip is cancelled<commit_after>class API::V1::TripsController < API::ApiController
  before_action :authenticate_customer
  before_action :get_trip, :validate_trip_customer_match, except: [:create]

  def create
    authenticate_provider
    authenticate_trip_purpose

    from_address_params = (params[:from_address] || {}).merge({
        customer_id: @customer.id,
        provider_id: @provider.id
        })

    to_address_params = (params[:to_address] || {}).merge({
        customer_id: @customer.id,
        provider_id: @provider.id,
        trip_purpose_id: @trip_purpose.id
        })

    from_address = Address.parse_api_params(from_address_params)
    to_address = Address.parse_api_params(to_address_params)
    @trip = Trip.new(
      customer: @customer, 
      mobility: @customer.mobility,
      funding_source: @customer.default_funding_source,
      medicaid_eligible: @customer.medicaid_eligible,
      service_level: @customer.service_level,
      provider: @provider,
      trip_purpose: @trip_purpose,
      direction: Trip.parse_leg_as_direction(params[:leg]),
      pickup_time: Time.parse(params[:pickup_time]).in_time_zone,
      appointment_time: Time.parse(params[:dropoff_time]).in_time_zone,
      guest_count: params[:guests],
      attendant_count: params[:attendants], 
      mobility_device_accommodations: params[:mobility_devices],
      pickup_address: from_address,
      dropoff_address: to_address
    )

    if @trip.save
      render json: @trip.as_profile_json
    else 
      error(:unprocessable_entity, @trip.errors.full_messages.join(';'))
    end
  end

  def show
    render json: @trip.as_profile_json
  end

  def destroy

    if @trip.cancel!
      render json: {}
    else
      error(:unprocessable_entity, @trip.errors.full_messages.join(';'))
    end
  end

  private 

  def authenticate_customer
    @customer = Customer.where(id: params[:customer_id], token: params[:customer_token]).first
{'fraction_non_alphanumeric': 0.10486128785950624, 'fraction_numerical': 0.002799694578773225, 'mean_word_length': 3.729241877256318, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4895152', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1210, 'n_words': 207}