Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging static query case setup #889

Merged
merged 4 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/assets/javascripts/controllers/wizardModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ angular.module('QuepidApp')

$scope.isStaticCollapsed = true;
$scope.addedStaticQueries = false;
$scope.listOfStaticQueries = [];
$scope.showSearchApiJavaScriptEditor = true;
$scope.staticContent = {
content: null,
Expand Down Expand Up @@ -728,8 +729,7 @@ angular.module('QuepidApp')
function createSnapshot() {
$scope.staticContent.import.loading = true;
$scope.isStaticCollapsed = false;

$scope.listOfStaticQueries = [];

angular.forEach($scope.staticContent.result, function(doc) {
if (!$scope.listOfStaticQueries.includes(doc['Query Text'])){
$scope.listOfStaticQueries.push(doc['Query Text']);
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/services/settingsSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ angular.module('QuepidApp')
titleField: '',
additionalFields: [],
numberOfRows: 10,
searchEngine: 'static'
searchEngine: 'static',
proxyRequests: true
// no searchUrl or urlFormat because it's code generated!
},
searchapi: {
Expand Down
3 changes: 1 addition & 2 deletions app/assets/templates/views/wizardModal.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ <h2>CSV</h2>
<div class="content import-content">
<pre>{{ staticContent.content }}</pre>
</div>

<button class="btn btn-primary" ng-click="createSnapshot()"> Import</button>
<button class="btn btn-primary" ng-click="createSnapshot()" ng-disabled="listOfStaticQueries.length > 0"> Import</button>
</div>
</div>
</div>
Expand Down
19 changes: 18 additions & 1 deletion app/controllers/api/v1/snapshots/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@ class SearchController < SnapshotsController
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Layout/LineLength
api :GET, '/api/cases/:case_id/snapshots/:snapshot_id/search?q=:q',
'Mimic a Solr query by looking up query/doc data from a specific snapshot, using the q parameter as the query'
param :case_id, :number,
desc: 'The ID of the requested case.', required: true
param :snapshot_id, :number,
desc: 'The ID of the snapshot for the case.', required: true
param :q, String,
desc: 'The query that you are looking up', required: true
def index
@q = params[:q]
@q = search_params[:q]
query = if '*:*' == @q
@snapshot.snapshot_queries.first.query

Expand Down Expand Up @@ -57,9 +66,17 @@ def index
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Layout/LineLength

private

def search_params
# Check if the 'q' parameter exists
raise ActionController::ParameterMissing, "Missing 'q' parameter" unless params.key?(:q)

params
end

def set_snapshot
@snapshot = @case.snapshots
.where(id: params[:snapshot_id])
Expand Down
1 change: 1 addition & 0 deletions config/initializers/apipie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
config.app_name = 'Quepid'
config.api_base_url = '/api'
config.doc_base_url = '/apipie'
config.validate = :explicitly
# where is your API defined?
config.api_controllers_matcher = Rails.root.join('app/controllers/api/**/*.rb').to_s
config.namespaced_resources = true
Expand Down
11 changes: 11 additions & 0 deletions test/controllers/api/v1/snapshots/search_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ class SearchControllerTest < ActionController::TestCase
assert_equal data['responseHeader']['params'], solr_params.stringify_keys.transform_values(&:to_s)
end
end

describe 'handles edge cases' do
let(:acase) { cases(:snapshot_case) }
let(:snapshot) { snapshots(:a_snapshot) }

test 'replies with message when no parameters' do
assert_raises(ActionController::ParameterMissing) do
get :index, params: { case_id: acase.id, snapshot_id: snapshot.id }
end
end
end
end
end
end
Expand Down