From 273a857670fbb4b29d883a60b40835756b6cb624 Mon Sep 17 00:00:00 2001 From: Summer Cook Date: Mon, 7 Aug 2023 16:22:53 -0300 Subject: [PATCH 1/3] create super basic JSON pages for each report --- app/controllers/api/sushi_controller.rb | 42 +++++++++++++++++++++++++ config/application.rb | 2 ++ config/routes.rb | 19 +++++++++++ 3 files changed, 63 insertions(+) create mode 100644 app/controllers/api/sushi_controller.rb diff --git a/app/controllers/api/sushi_controller.rb b/app/controllers/api/sushi_controller.rb new file mode 100644 index 000000000..0ab1ad7ef --- /dev/null +++ b/app/controllers/api/sushi_controller.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +# maybe rename to counter_metrics_controller? +module API + class SushiController < ApplicationController + + def get_item_report + # Logic to retrieve item report + render json: { "item_report" => 'hello' } + end + + def get_platform_report + # Logic to retrieve platform report + render json: { "platform_report" => 'hi' } + end + + def get_platform_usage_report + # Logic to retrieve platform usage report + render json: { "platform_usage_report" => 'message' } + end + + def get_status + render json: { "status" => "ok" } + end + + def get_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 + + def get_report + report_id = params[:report_id] + # Logic to retrieve specific report based on report_id + render json: { "report" => 'message' } + 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..4ce51ce19 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -36,6 +36,24 @@ end end + + # routes for the api + namespace :api do + resource :sushi do + defaults format: :json do + collection do + get 'r51/status', to: 'sushi#get_status' + get 'r51/members', to: 'sushi#get_members' + get 'r51/reports', to: 'sushi#list_reports' + get 'r51/reports/:report_id', to: 'sushi#get_report', as: :report + get 'r51/reports/pr', to: 'sushi#get_platform_report' + get 'r51/reports/pr_p1', to: 'sushi#get_platform_usage_report' + get 'r51/reports/ir', to: 'sushi#get_item_report' + end + end + end + end + get 'status', to: 'status#index' mount BrowseEverything::Engine => '/browse' @@ -46,6 +64,7 @@ root 'hyrax/homepage#index' + devise_for :users, controllers: { invitations: 'hyku/invitations', registrations: 'hyku/registrations' } mount Qa::Engine => '/authorities' From 891ff06d994dbe67c48651a804c02e21ab2344f8 Mon Sep 17 00:00:00 2001 From: Summer Cook Date: Mon, 7 Aug 2023 18:07:25 -0300 Subject: [PATCH 2/3] fix routes so they all work --- app/controllers/api/sushi_controller.rb | 26 +++++++++++++++++++------ config/routes.rb | 20 +++++++++---------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/app/controllers/api/sushi_controller.rb b/app/controllers/api/sushi_controller.rb index 0ab1ad7ef..ce2c5abad 100644 --- a/app/controllers/api/sushi_controller.rb +++ b/app/controllers/api/sushi_controller.rb @@ -4,9 +4,18 @@ module API class SushiController < ApplicationController + # needs to include the following filters: begin & end date, item ID def get_item_report - # Logic to retrieve item report - render json: { "item_report" => 'hello' } + # Need to find the id with + if params[:item_id] + #need to figure out how to look at all worktypes for the ID + #work = GenericWork.find(item_id) + # here we would return the JSON that only includes the specific work + render json: { "item_report" => 'hello' } + else + # here we would return the JSON that includes all works in the Item Report + render json: { "item_report" => 'hello2' } + end end def get_platform_report @@ -33,10 +42,15 @@ def list_reports render json: { "reports" => 'message' } end - def get_report - report_id = params[:report_id] - # Logic to retrieve specific report based on report_id - render json: { "report" => 'message' } + def get_item_report_for_single_item + # Logic to retrieve item report by id + render json: { "reports" => 'single item' } end + + private + + def sushi_params + params.permit(:item_id, :report_id) + end end end diff --git a/config/routes.rb b/config/routes.rb index 4ce51ce19..fac28f5ab 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -38,18 +38,16 @@ # routes for the api - namespace :api do + namespace :api, defaults: { format: :json } do resource :sushi do - defaults format: :json do - collection do - get 'r51/status', to: 'sushi#get_status' - get 'r51/members', to: 'sushi#get_members' - get 'r51/reports', to: 'sushi#list_reports' - get 'r51/reports/:report_id', to: 'sushi#get_report', as: :report - get 'r51/reports/pr', to: 'sushi#get_platform_report' - get 'r51/reports/pr_p1', to: 'sushi#get_platform_usage_report' - get 'r51/reports/ir', to: 'sushi#get_item_report' - end + collection do + get 'r51/status', to: 'sushi#get_status' + get 'r51/members', to: 'sushi#get_members' + get 'r51/reports', to: 'sushi#list_reports' + get 'r51/reports/pr', to: 'sushi#get_platform_report' + get 'r51/reports/pr_p1', to: 'sushi#get_platform_usage_report' + get 'r51/reports/ir', to: 'sushi#get_item_report' + get 'r51/reports/ir/:id', to: 'sushi#get_item_report_for_single_item' end end end From 6077a5f24675883ebcb19ad936ec45d8bb75d548 Mon Sep 17 00:00:00 2001 From: leaannbradford Date: Mon, 7 Aug 2023 16:06:26 -0700 Subject: [PATCH 3/3] add specs and rubocop renaming --- app/controllers/api/sushi_controller.rb | 27 +++++------- config/routes.rb | 11 +++-- spec/requests/sushi_spec.rb | 55 +++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 22 deletions(-) create mode 100644 spec/requests/sushi_spec.rb diff --git a/app/controllers/api/sushi_controller.rb b/app/controllers/api/sushi_controller.rb index ce2c5abad..25a9f3fba 100644 --- a/app/controllers/api/sushi_controller.rb +++ b/app/controllers/api/sushi_controller.rb @@ -3,36 +3,36 @@ # maybe rename to counter_metrics_controller? module API class SushiController < ApplicationController - # needs to include the following filters: begin & end date, item ID - def get_item_report - # Need to find the id with + def item_report if params[:item_id] - #need to figure out how to look at all worktypes for the ID - #work = GenericWork.find(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' } + 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" => 'hello2' } + render json: { "item_report" => 'hello all items report' } end end - def get_platform_report + def platform_report # Logic to retrieve platform report render json: { "platform_report" => 'hi' } end - def get_platform_usage_report + def platform_usage_report # Logic to retrieve platform usage report render json: { "platform_usage_report" => 'message' } end - def get_status + def status render json: { "status" => "ok" } end - def get_members + def members # Logic to retrieve members data render json: { "members" => 'message' } end @@ -42,11 +42,6 @@ def list_reports render json: { "reports" => 'message' } end - def get_item_report_for_single_item - # Logic to retrieve item report by id - render json: { "reports" => 'single item' } - end - private def sushi_params diff --git a/config/routes.rb b/config/routes.rb index fac28f5ab..c22586c95 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -41,13 +41,12 @@ namespace :api, defaults: { format: :json } do resource :sushi do collection do - get 'r51/status', to: 'sushi#get_status' - get 'r51/members', to: 'sushi#get_members' + 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#get_platform_report' - get 'r51/reports/pr_p1', to: 'sushi#get_platform_usage_report' - get 'r51/reports/ir', to: 'sushi#get_item_report' - get 'r51/reports/ir/:id', to: 'sushi#get_item_report_for_single_item' + 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 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