Skip to content

Commit

Permalink
BASIRA #292 - Adding skip authentication action to GET /api/people an…
Browse files Browse the repository at this point in the history
…d GET /api/places API endpoints; Updating qualifiable concern to manage sort
  • Loading branch information
dleadbetter committed Dec 24, 2024
1 parent 8bfaa27 commit 0582e34
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/controllers/api/people_controller.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions app/controllers/api/places_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ class Api::PlacesController < Api::BaseController

# Preloads
preloads :qualifications, only: :show

# Actions
skip_before_action :authenticate_user!, only: :index
end
15 changes: 15 additions & 0 deletions app/controllers/concerns/api/qualifiable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0582e34

Please sign in to comment.