# frozen_string_literal: true

require 'sinatra/json'

require_relative 'base_controller'
require_relative '../models/benchmark'
require_relative '../models/test'
require_relative '../models/result'

# /api/v1 routes
class APIv1Controller < BaseController

  get '/api/v1/benchmark/details' do
    benchmark_id = params[:benchmark_id]

    benchmark = Benchmark.where(id: benchmark_id).first()

    json benchmark.values()
  end

  get '/api/v1/result/list' do
    test_id = params[:test_id]
    benchmark_id = params[:benchmark_id]

    results = Result.where(test_id: test_id, benchmark_id: benchmark_id).all()

    json results.map(&:values)
  end

  get '/api/v1/test/details' do
    test_id = params[:test_id]

    tst = Test.where(id: test_id).first()

    json tst.values()
  end

end
