class School::ReportsController < ApplicationController
  def index
    render_success :ok, json: reports.map { |r| report_props(r) }
  end

  def show
    render_success :ok, json: { url: report.blob.service_url }
  end

  def destroy
    report.purge
    render_success :ok
  end

  private
    def reports
      current_user.reports
    end

    def report
      @report ||= reports.find_by(id: params[:id])
    end

    def report_props(report)
      {
        id: report.id,
        record_id: report.id,
        blob_id: report.blob_id,
        created_at: report.created_at,
        filename: report.filename,
        type: report.content_type
      }
    end
end
