<commit_before>require_dependency "landable/api_controller"

module Landable
  module Api
    class AuditsController < ApiController
      def index
        determine_which_index
        respond_with @audits
      end

      def show
        respond_with Audit.find(params[:id])
      end

      def create
        determine_type_of_audit
        audit = Audit.new audit_params.merge(auditable_id: @type_id,
                                             auditable_type: @type)
        audit.save!

        respond_with audit, status: :created, location: audit_url(audit)
      end

      private
        def audit_params
          params[:audit][:flags] ||= []
          params.require(:audit).permit(:id, :approver, :notes, :created_at, flags: [])
        end

        def determine_which_index
          if params[:auditable_id].present?
            @audits = Audit.where(auditable_id: params[:auditable_id])
          else
            @audits = Audit.all
          end<commit_msg>sort audits correctly<commit_after>require_dependency "landable/api_controller"

module Landable
  module Api
    class AuditsController < ApiController
      def index
        determine_which_index
        respond_with @audits
      end

      def show
        respond_with Audit.find(params[:id])
      end

      def create
        determine_type_of_audit
        audit = Audit.new audit_params.merge(auditable_id: @type_id,
                                             auditable_type: @type)
        audit.save!

        respond_with audit, status: :created, location: audit_url(audit)
      end

      private
        def audit_params
          params[:audit][:flags] ||= []
          params.require(:audit).permit(:id, :approver, :notes, :created_at, flags: [])
        end

        def determine_which_index
          if params[:auditable_id].present?
            @audits = Audit.where(auditable_id: params[:auditable_id])
          else
            @audits = Audit.order('created_at DESC')
          end
{'fraction_non_alphanumeric': 0.08128449573507275, 'fraction_numerical': 0.0, 'mean_word_length': 2.0303951367781155, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4325953', 'n_tokens_mistral': 565, 'n_tokens_neox': 564, 'n_words': 118}