diff --git a/app/controllers/api/sushi_controller.rb b/app/controllers/api/sushi_controller.rb new file mode 100644 index 000000000..25a9f3fba --- /dev/null +++ b/app/controllers/api/sushi_controller.rb @@ -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 diff --git a/config/application.rb b/config/application.rb index 59c9cb1c4..99d7709a6 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index f023183f6..c22586c95 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' @@ -46,6 +61,7 @@ root 'hyrax/homepage#index' + devise_for :users, controllers: { invitations: 'hyku/invitations', registrations: 'hyku/registrations' } mount Qa::Engine => '/authorities' diff --git a/spec/requests/sushi_spec.rb b/spec/requests/sushi_spec.rb new file mode 100644 index 000000000..f9d1cb764 --- /dev/null +++ b/spec/requests/sushi_spec.rb @@ -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