Commit 1ae9aefe authored by JB Vasseur's avatar JB Vasseur

Use application finder for Doorkeeper Applications

parent c47aea75
# frozen_string_literal: true
class ApplicationsFinder
attr_reader :params
def initialize(params = {})
@params = params
end
# rubocop: disable CodeReuse/ActiveRecord
def execute
applications = Doorkeeper::Application.where("owner_id IS NULL")
by_id(applications)
end
# rubocop: enable CodeReuse/ActiveRecord
private
# rubocop: disable CodeReuse/ActiveRecord
def by_id(applications)
return applications unless params[:id]
Doorkeeper::Application.find_by(id: params[:id])
end
# rubocop: enable CodeReuse/ActiveRecord
end
...@@ -25,24 +25,21 @@ module API ...@@ -25,24 +25,21 @@ module API
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
desc 'Get applications' do desc 'Get applications' do
success Entities::Application success Entities::Application
end end
get do get do
applications = Doorkeeper::Application.where("owner_id IS NULL") applications = ApplicationsFinder.new.execute
present applications, with: Entities::Application present applications, with: Entities::Application
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
desc 'Delete an application' desc 'Delete an application'
delete ':id' do delete ':id' do
Doorkeeper::Application.find_by(id: params[:id]).destroy application = ApplicationsFinder.new(params).execute
application.destroy
status 204 status 204
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment