Class: Qa::TermsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Qa::TermsController
- Defined in:
- app/controllers/qa/terms_controller.rb
Overview
This controller is used for all requests to all authorities. It will verify params and figure out which class to instantiate based on the “vocab” param. All the authority classes inherit from a super class so they implement the same methods.
Instance Method Summary collapse
- #check_query_param ⇒ Object
- #check_vocab_param ⇒ Object
-
#fetch ⇒ Object
If the subauthority supports it, return all the information for a given term Expects uri to be a request parameter (e.g. my.app/qa/show/auth/subauth?uri=:uri).
-
#index ⇒ Object
If the subauthority supports it, return a list of all terms in the authority.
-
#init_authority ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#search ⇒ Object
Return a list of terms based on a query.
-
#show ⇒ Object
If the subauthority supports it, return all the information for a given term Expects id to be part of the request path (e.g. my.app/qa/show/auth/subauth/:id).
Instance Method Details
#check_query_param ⇒ Object
83 84 85 86 87 88 |
# File 'app/controllers/qa/terms_controller.rb', line 83 def check_query_param return if params[:q].present? msg = "Required param 'q' is missing or empty" logger.warn msg render json: { errors: msg }, status: :bad_request end |
#check_vocab_param ⇒ Object
64 65 66 67 68 69 |
# File 'app/controllers/qa/terms_controller.rb', line 64 def check_vocab_param return if params[:vocab].present? msg = "Required param 'vocab' is missing or empty" logger.warn msg render json: { errors: msg }, status: :bad_request end |
#fetch ⇒ Object
If the subauthority supports it, return all the information for a given term Expects uri to be a request parameter (e.g. my.app/qa/show/auth/subauth?uri=:uri)
52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/qa/terms_controller.rb', line 52 def fetch term = @authority.method(:find).arity == 2 ? @authority.find(params[:uri], self) : @authority.find(params[:uri]) cors_allow_origin_header(response) respond_to do |wants| wants.json { render json: term } wants.n3 { render json: term } wants.jsonld { render json: term } wants.ntriples { render json: term } wants.any { render json: term, content_type: json_content_type } end end |
#index ⇒ Object
If the subauthority supports it, return a list of all terms in the authority
16 17 18 19 20 21 22 23 |
# File 'app/controllers/qa/terms_controller.rb', line 16 def index cors_allow_origin_header(response) render json: begin @authority.all rescue NotImplementedError nil end end |
#init_authority ⇒ Object
rubocop:disable Metrics/MethodLength
71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/qa/terms_controller.rb', line 71 def # rubocop:disable Metrics/MethodLength @authority = Qa.(vocab: params[:vocab], subauthority: params[:subauthority], # Included to preserve error message text try_linked_data_config: false, context: self) rescue Qa::InvalidAuthorityError, Qa::InvalidSubAuthority, Qa::MissingSubAuthority => e msg = e. logger.warn msg render json: { errors: msg }, status: :bad_request end |
#search ⇒ Object
Return a list of terms based on a query
26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/qa/terms_controller.rb', line 26 def search terms = @authority.method(:search).arity == 2 ? @authority.search(url_search, self) : @authority.search(url_search) cors_allow_origin_header(response) respond_to do |wants| wants.json { render json: pagination_service(format: :json, results: terms).build_response } wants.jsonapi { render json: pagination_service(format: :jsonapi, results: terms).build_response } wants.any { render json: pagination_service(format: :json, results: terms).build_response, content_type: json_content_type } end end |
#show ⇒ Object
If the subauthority supports it, return all the information for a given term Expects id to be part of the request path (e.g. my.app/qa/show/auth/subauth/:id)
38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/qa/terms_controller.rb', line 38 def show term = @authority.method(:find).arity == 2 ? @authority.find(params[:id], self) : @authority.find(params[:id]) cors_allow_origin_header(response) respond_to do |wants| wants.json { render json: term } wants.n3 { render json: term } wants.jsonld { render json: term } wants.ntriples { render json: term } wants.any { render json: term, content_type: json_content_type } end end |