Changed naming from Routes to Controllers; fixed some Sinatra modular layout stuff; added RSpec for testing and some basic tests
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
61
src/controllers/benchmark.rb
Normal file
61
src/controllers/benchmark.rb
Normal file
@@ -0,0 +1,61 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'base_controller'
|
||||
require_relative '../models/benchmark'
|
||||
|
||||
# /benchmark routes
|
||||
class BenchmarkController < BaseController
|
||||
|
||||
get '/benchmark' do
|
||||
benchmarks = Benchmark.reverse(:updated_at).limit(10).all()
|
||||
|
||||
erb :'benchmark/index', locals: {
|
||||
title: 'List of Benchmarks',
|
||||
benchmarks: benchmarks
|
||||
}
|
||||
end
|
||||
|
||||
get '/benchmark/add' do
|
||||
erb :'benchmark/add', locals: {
|
||||
title: 'Add Benchmark'
|
||||
}
|
||||
end
|
||||
post '/benchmark/add' do
|
||||
benchmark = Benchmark.create(
|
||||
name: params[:benchmark_name],
|
||||
scoring: params[:benchmark_scoring],
|
||||
description: params[:benchmark_description]
|
||||
)
|
||||
|
||||
redirect "/benchmark/#{benchmark.id}"
|
||||
end
|
||||
|
||||
get '/benchmark/:benchmark_id' do
|
||||
benchmark = Benchmark.where(id: params[:benchmark_id]).first()
|
||||
erb :'benchmark/view', locals: {
|
||||
title: benchmark.name,
|
||||
benchmark: benchmark
|
||||
}
|
||||
end
|
||||
|
||||
get '/benchmark/:benchmark_id/edit' do
|
||||
benchmark = Benchmark.where(id: params[:benchmark_id]).first()
|
||||
erb :'benchmark/edit', locals: {
|
||||
title: "Editing: #{benchmark.name}",
|
||||
benchmark: benchmark
|
||||
}
|
||||
end
|
||||
|
||||
post '/benchmark/:benchmark_id/edit' do
|
||||
benchmark = Benchmark.where(id: params[:benchmark_id]).first()
|
||||
|
||||
benchmark.update(
|
||||
name: params[:benchmark_name],
|
||||
scoring: params[:benchmark_scoring],
|
||||
description: params[:benchmark_description]
|
||||
)
|
||||
|
||||
redirect "/benchmark/#{benchmark.id}"
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user