mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-30 19:48:18 +08:00
Use service in controller
This commit is contained in:
parent
7fad5fc594
commit
88d96c0938
3 changed files with 14 additions and 13 deletions
|
@ -6,25 +6,18 @@ class ExternalProtocolsController < ApplicationController
|
|||
|
||||
# GET list_external_protocol
|
||||
def index
|
||||
# list_protocols = SearchService.call(index_params)
|
||||
succeed = true
|
||||
protocols = [
|
||||
{ name: 'Protocol1' },
|
||||
{ name: 'Protocol2' },
|
||||
{ name: 'Protocol3' }
|
||||
]
|
||||
service_call = ProtocolImporters::SearchProtocolsService
|
||||
.call(protocol_source: 'protocolsio/v3', query_params: index_params)
|
||||
|
||||
if succeed
|
||||
if service_call.succeed?
|
||||
render json: {
|
||||
html: render_to_string(
|
||||
partial: 'protocol_importers/list_of_protocol_cards.html.erb',
|
||||
locals: { protocols: protocols }
|
||||
locals: { protocols: service_call.protocols_list }
|
||||
)
|
||||
}
|
||||
else
|
||||
render json: {
|
||||
errors: { protocol: 'error_placeholder' }
|
||||
}, status: 400
|
||||
render json: { errors: service_call.errors }, status: 400
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ module ProtocolImporters
|
|||
@errors[:invalid_params][:key] = 'Key cannot be empty' if @query_params[:key].blank?
|
||||
|
||||
# try if page id is ok
|
||||
if @query_params[:page_id] && !@query_params[:page_id].positive?
|
||||
if @query_params[:page_id] && !@query_params[:page_id].to_i.positive?
|
||||
@errors[:invalid_params][:page_id] = 'Page needs to be positive'
|
||||
end
|
||||
|
||||
|
|
|
@ -24,6 +24,14 @@ describe ExternalProtocolsController, type: :controller do
|
|||
|
||||
let(:action) { get :index, params: params }
|
||||
|
||||
before do
|
||||
service = double('success_service')
|
||||
allow(service).to(receive(:succeed?)).and_return(true)
|
||||
allow(service).to(receive(:protocols_list)).and_return({})
|
||||
|
||||
allow_any_instance_of(ProtocolImporters::SearchProtocolsService).to(receive(:call)).and_return(service)
|
||||
end
|
||||
|
||||
it 'returns JSON, 200 response when protocol parsing was valid' do
|
||||
action
|
||||
expect(response).to have_http_status(:success)
|
||||
|
|
Loading…
Reference in a new issue