<commit_before>module Api
  module V1
    class LocationsController < ApplicationController
      include TokenValidator
      include PaginationHeaders
      include CustomErrors

      def index
        locations = Location.includes(:organization, :address, :phones).
                            page(params[:page]).per(params[:per_page]).
                            order('created_at DESC')

        render json: locations, each_serializer: LocationsSerializer, status: 200
        generate_pagination_headers(locations)
      end

      def show
        location = Location.includes(
          contacts: :phones,
          services: [:categories, :regular_schedules, :holiday_schedules]
          ).find(params[:id])
        render json: location, status: 200
        expires_in ENV['EXPIRES_IN'].to_i.minutes, public: true
      end

      def update
        location = Location.find(params[:id])
        location.update!(params)
        render json: location, status: 200
      end

      def create
        org = Organization.find(params[:organization_id])
        location = org.locations.create!(params)
        response_hash = {
          id: location.id,<commit_msg>Fix N+1 query with Service Contacts.<commit_after>module Api
  module V1
    class LocationsController < ApplicationController
      include TokenValidator
      include PaginationHeaders
      include CustomErrors

      def index
        locations = Location.includes(:organization, :address, :phones).
                            page(params[:page]).per(params[:per_page]).
                            order('created_at DESC')

        render json: locations, each_serializer: LocationsSerializer, status: 200
        generate_pagination_headers(locations)
      end

      def show
        location = Location.includes(
          contacts: :phones,
          services: [:contacts, :categories, :regular_schedules, :holiday_schedules]
          ).find(params[:id])
        render json: location, status: 200
        expires_in ENV['EXPIRES_IN'].to_i.minutes, public: true
      end

      def update
        location = Location.find(params[:id])
        location.update!(params)
        render json: location, status: 200
      end

      def create
        org = Organization.find(params[:organization_id])
        location = org.locations.create!(params)
        response_hash = {
          id: location.id,
{'fraction_non_alphanumeric': 0.08619246861924686, 'fraction_numerical': 0.008786610878661089, 'mean_word_length': 2.3208333333333333, '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': '7580798', 'n_tokens_mistral': 631, 'n_tokens_neox': 594, 'n_words': 149}