From 0582e348bb610bb35b29276a8d5e0412a83f7e08 Mon Sep 17 00:00:00 2001 From: dleadbetter Date: Tue, 24 Dec 2024 09:32:38 -0500 Subject: [PATCH] BASIRA #292 - Adding skip authentication action to GET /api/people and GET /api/places API endpoints; Updating qualifiable concern to manage sort --- app/controllers/api/people_controller.rb | 6 ++++++ app/controllers/api/places_controller.rb | 3 +++ app/controllers/concerns/api/qualifiable.rb | 15 +++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/app/controllers/api/people_controller.rb b/app/controllers/api/people_controller.rb index db1397f..9ddd523 100644 --- a/app/controllers/api/people_controller.rb +++ b/app/controllers/api/people_controller.rb @@ -1,8 +1,14 @@ class Api::PeopleController < Api::BaseController + # Includes + include Api::Qualifiable + # Search columns search_attributes :name, :display_name # Preloads preloads qualifications: :value_list preloads participations: [participateable: [Artwork.primary_attachment_preload, :primary_title]], only: :show + + # Actions + skip_before_action :authenticate_user!, only: :index end diff --git a/app/controllers/api/places_controller.rb b/app/controllers/api/places_controller.rb index 5048b71..dfab7f9 100644 --- a/app/controllers/api/places_controller.rb +++ b/app/controllers/api/places_controller.rb @@ -4,4 +4,7 @@ class Api::PlacesController < Api::BaseController # Preloads preloads :qualifications, only: :show + + # Actions + skip_before_action :authenticate_user!, only: :index end diff --git a/app/controllers/concerns/api/qualifiable.rb b/app/controllers/concerns/api/qualifiable.rb index 36c1ef8..5d49ad3 100644 --- a/app/controllers/concerns/api/qualifiable.rb +++ b/app/controllers/concerns/api/qualifiable.rb @@ -3,5 +3,20 @@ module Api::Qualifiable included do preloads qualifications: :value_list, only: :show + + def apply_sort(query) + return super unless params[:sort_by_object].present? && params[:sort_by_group].present? + + if params[:sort_direction] == 'descending' + sort_column = ValueList.arel_table[:human_name].desc + else + sort_column = ValueList.arel_table[:human_name].asc + end + + query + .joins(qualifications: :value_list) + .where(value_lists: { object: params[:sort_by_object], group: params[:sort_by_group] }) + .order(sort_column) + end end end