Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup basic controller actions #651

Merged
merged 3 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions app/controllers/api/sushi_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# frozen_string_literal: true

# maybe rename to counter_metrics_controller?
module API
class SushiController < ApplicationController
# needs to include the following filters: begin & end date, item ID
def item_report
if params[:item_id]
# example of the URL with an item_id
# /api/sushi/r51/reports/ir?item_id=7fdf12a0-b8da-46c6-88dc-64dbb5bc31d7
# work_id = params[:item_id]
# work = ActiveFedora::Base.find(work_id)
# here we would return the JSON that only includes the specific work
render json: { "item_report" => 'hello single item report' }
else
# here we would return the JSON that includes all works in the Item Report
render json: { "item_report" => 'hello all items report' }
end
end

def platform_report
# Logic to retrieve platform report
render json: { "platform_report" => 'hi' }
end

def platform_usage_report
# Logic to retrieve platform usage report
render json: { "platform_usage_report" => 'message' }
end

def status
render json: { "status" => "ok" }
end

def members
# Logic to retrieve members data
render json: { "members" => 'message' }
end

def list_reports
# Logic to retrieve and list available reports
render json: { "reports" => 'message' }
end

private

def sushi_params
params.permit(:item_id, :report_id)
end
end
end
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,7 @@ class Application < Rails::Application
config.active_record.yaml_column_permitted_classes = [Symbol, Hash, Array, ActiveSupport::HashWithIndifferentAccess, ActiveModel::Attribute.const_get(:FromDatabase), User, Time]
end
end

config.autoload_paths << "#{Rails.root}/app/controllers/api"
end
end
16 changes: 16 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@
end
end


# routes for the api
namespace :api, defaults: { format: :json } do
resource :sushi do
collection do
get 'r51/status', to: 'sushi#status'
get 'r51/members', to: 'sushi#members'
get 'r51/reports', to: 'sushi#list_reports'
get 'r51/reports/pr', to: 'sushi#platform_report'
get 'r51/reports/pr_p1', to: 'sushi#platform_usage_report'
get 'r51/reports/ir', to: 'sushi#item_report'
end
end
end

get 'status', to: 'status#index'

mount BrowseEverything::Engine => '/browse'
Expand All @@ -46,6 +61,7 @@

root 'hyrax/homepage#index'


devise_for :users, controllers: { invitations: 'hyku/invitations', registrations: 'hyku/registrations' }
mount Qa::Engine => '/authorities'

Expand Down
55 changes: 55 additions & 0 deletions spec/requests/sushi_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

RSpec.describe 'api/sushi/r51', type: :request, singletenant: true do
describe 'GET /api/sushi/r51/reports/ir' do
it 'returns a 200 with correct response for item report' do
get '/api/sushi/r51/reports/ir'
expect(response).to have_http_status(200)
parsed_body = JSON.parse(response.body)
expect(parsed_body['item_report']).to eq 'hello all items report'
end

it 'returns a 200 with correct response for an specific work item report' do
work = create(:work)
get '/api/sushi/r51/reports/ir?item_id=' + work.id
expect(response).to have_http_status(200)
parsed_body = JSON.parse(response.body)
expect(parsed_body['item_report']).to eq 'hello single item report'
end

it 'returns a 200 with correct response for the platform report' do
get '/api/sushi/r51/reports/pr'
expect(response).to have_http_status(200)
parsed_body = JSON.parse(response.body)
expect(parsed_body['platform_report']).to eq 'hi'
end

it 'returns a 200 with correct response for the platform usage report' do
get '/api/sushi/r51/reports/pr_p1'
expect(response).to have_http_status(200)
parsed_body = JSON.parse(response.body)
expect(parsed_body['platform_usage_report']).to eq 'message'
end

it 'returns a 200 with correct response for the status' do
get '/api/sushi/r51/status'
expect(response).to have_http_status(200)
parsed_body = JSON.parse(response.body)
expect(parsed_body['status']).to eq 'ok'
end

it 'returns a 200 with correct response for the members' do
get '/api/sushi/r51/members'
expect(response).to have_http_status(200)
parsed_body = JSON.parse(response.body)
expect(parsed_body['members']).to eq 'message'
end

it 'returns a 200 with correct response for the reports list' do
get '/api/sushi/r51/reports'
expect(response).to have_http_status(200)
parsed_body = JSON.parse(response.body)
expect(parsed_body['reports']).to eq 'message'
end
end
end
Loading