Added start of an API to return some basic stats of the app

This commit is contained in:
Gregory Ballantine 2023-03-09 23:43:26 -05:00
parent daa41ac8e4
commit a48ab93b08
2 changed files with 25 additions and 2 deletions

19
app/routes/api_v1.rb Normal file
View File

@ -0,0 +1,19 @@
class StageManager
class ApiV1Controller
get '/health' do
json :status => 'success'
end
get '/channels' do
channels = Channel.all().map!(&:to_hash)
json channels
end
get '/videos' do
videos = Video.all().map!(&:to_hash)
json videos
end
end
end

View File

@ -2,6 +2,7 @@ require 'logger'
require 'sequel'
require 'sqlite3'
require 'sinatra/base'
require 'sinatra/json'
require 'rack/protection'
# Load the Sequel timestamps plugin
@ -9,8 +10,7 @@ Sequel::Model.plugin :timestamps
# Initialize Sequel gem for database actions
DB = Sequel.connect(adapter: $conf.get('database.adapter'), database: $conf.get('database.database'))
# Load models
require_relative 'app/models/channel.rb'
require_relative 'app/models/video.rb'
Dir.glob('./app/models/*.rb').each { |f| require f }
class StageManager < Sinatra::Base
@@my_app = {}
@ -48,6 +48,10 @@ class StageManager < Sinatra::Base
class VideoController < StageManager
map '/video'
end
# API controllers
class ApiV1Controller < StageManager
map '/api/v1'
end
end
# Load controllers