Skip to content

Commit bd71b23

Browse files
committed
Add complete plan flag to plans_controller
- Edit plan query to check for user role to prevent eager loading - Add set_complete_param function that sets complete flag according to its value if its set to true in the API call
1 parent f4ea8f5 commit bd71b23

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

app/controllers/api/v2/plans_controller.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ module Api
44
module V2
55
class PlansController < BaseApiController # rubocop:todo Style/Documentation
66
respond_to :json
7+
before_action :set_complete_param, only: %i[show index]
78

89
# GET /api/v2/plans/:id
910
def show
1011
raise Pundit::NotAuthorizedError unless @scopes.include?('read')
1112

12-
@plan = Plan.find_by(id: params[:id])
13+
@plan = Plan.includes(roles: :user).find_by(id: params[:id])
1314

1415
raise Pundit::NotAuthorizedError unless @plan.present?
1516

@@ -28,6 +29,11 @@ def index
2829
@items = paginate_response(results: @plans)
2930
render '/api/v2/plans/index', status: :ok
3031
end
32+
33+
# GET /api/v2/plans?complete=true and /api/v2/plans/:id?complete=true
34+
def set_complete_param
35+
@complete = params[:complete].to_s.downcase == 'true'
36+
end
3137
end
3238
end
3339
end

0 commit comments

Comments
 (0)