Skip to content

Commit

Permalink
WIP - Remove API Search enpoints duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefanni committed Jul 11, 2018
1 parent d866329 commit 2b32937
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 192 deletions.
187 changes: 77 additions & 110 deletions app/api/srch/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,166 +3,133 @@

module Srch
class Search < Grape::API
def self.create(endpoint)
get endpoint.to_sym do
sresult = DocList.new
unless params[:srchString].nil? || params[:srchString] == 0
sservice = SearchService.new
if endpoint == "all"
sresult = sservice.textSearch_all(params[:srchString])
elsif endpoint=="profiles"
sresult = sservice.textSearch_profiles(params[:srchString])
elsif endpoint=="notes"
sresult = sservice.textSearch_notes(params[:srchString])
elsif endpoint=="questions"
sresult = sservice.textSearch_questions(params[:srchString])
elsif endpoint=="tags"
sresult = sservice.textSearch_tags(params[:srchString])
elsif endpoint=="peoplelocations"
sresult = sservice.recentPeople(params[:srchString])
elsif endpoint == "taglocations" && (params[:srchString].include? ",")
sresult = sservice.tagNearbyNodes(params[:srchString], params[:tagName])
end
end
sparms = SearchRequest.fromRequest(params)
sresult.srchParams = sparms
sresult
end
end

# Endpoint definitions
resource :srch do
# add a default set of params
helpers do
params :common do
requires :srchString, type: String, documentation: { example: 'Spec' }
optional :seq, type: Integer, documentation: { example: 995 }
optional :showCount, type: Integer, documentation: { example: 3 }
optional :pageNum, type: Integer, documentation: { example: 0 }
end
end

# Request URL should be /api/srch/all?srchString=QRY[&seq=KEYCOUNT&showCount=NUM_ROWS&pageNum=PAGE_NUM]
# Basic implementation from classic plots2 SearchController
desc 'Perform a search of all available resources', hidden: false,
is_array: false,
nickname: 'srchGetAll'
params do
requires :srchString, type: String, documentation: { example: 'Spec' }
optional :seq, type: Integer, documentation: { example: 995 }
optional :showCount, type: Integer, documentation: { example: 3 }
optional :pageNum, type: Integer, documentation: { example: 0 }
end
get :all do
sresult = DocList.new
unless params[:srchString].nil? || params[:srchString] == 0
sservice = SearchService.new
sresult = sservice.textSearch_all(params[:srchString])
end
sparms = SearchRequest.fromRequest(params)
sresult.srchParams = sparms
sresult
use :common
end

endpoint = 'all'
create(endpoint)

# Request URL should be /api/srch/profiles?srchString=QRY[&seq=KEYCOUNT&showCount=NUM_ROWS&pageNum=PAGE_NUM]
# Basic implementation from classic plots2 SearchController
desc 'Perform a search of profiles', hidden: false,
is_array: false,
nickname: 'srchGetProfiles'

params do
requires :srchString, type: String, documentation: { example: 'Spec' }
optional :seq, type: Integer, documentation: { example: 995 }
optional :showCount, type: Integer, documentation: { example: 3 }
optional :pageNum, type: Integer, documentation: { example: 0 }
end
get :profiles do
sresult = DocList.new
unless params[:srchString].nil? || params[:srchString] == 0
sservice = SearchService.new
sresult = sservice.textSearch_profiles(params[:srchString])
end
sparms = SearchRequest.fromRequest(params)
sresult.srchParams = sparms
sresult
use :common
end
endpoint = 'profiles'
create(endpoint)

# Request URL should be /api/srch/notes?srchString=QRY[&seq=KEYCOUNT&showCount=NUM_ROWS&pageNum=PAGE_NUM]
# Basic implementation from classic plots2 SearchController
desc 'Perform a search of research notes', hidden: false,
is_array: false,
nickname: 'srchGetNotes'

params do
requires :srchString, type: String, documentation: { example: 'Spec' }
optional :seq, type: Integer, documentation: { example: 995 }
optional :showCount, type: Integer, documentation: { example: 3 }
optional :pageNum, type: Integer, documentation: { example: 0 }
end
get :notes do
sresult = DocList.new
unless params[:srchString].nil? || params[:srchString] == 0
sservice = SearchService.new
sresult = sservice.textSearch_notes(params[:srchString])
end
sparms = SearchRequest.fromRequest(params)
sresult.srchParams = sparms
sresult
use :common
end
endpoint = 'notes'
create(endpoint)

# Request URL should be /api/srch/questions?srchString=QRY[&seq=KEYCOUNT&showCount=NUM_ROWS&pageNum=PAGE_NUM]
# Basic implementation from classic plots2 SearchController
desc 'Perform a search of questions tables', hidden: false,
is_array: false,
nickname: 'srchGetQuestions'

params do
requires :srchString, type: String, documentation: { example: 'Spec' }
optional :seq, type: Integer, documentation: { example: 995 }
optional :showCount, type: Integer, documentation: { example: 3 }
optional :pageNum, type: Integer, documentation: { example: 0 }
end
get :questions do
sresult = DocList.new
unless params[:srchString].nil? || params[:srchString] == 0
sservice = SearchService.new
sresult = sservice.textSearch_questions(params[:srchString])
end
sparms = SearchRequest.fromRequest(params)
sresult.srchParams = sparms
sresult
use :common
end
endpoint = 'questions'
create(endpoint)

# Request URL should be /api/srch/tags?srchString=QRY[&seq=KEYCOUNT&showCount=NUM_ROWS&pageNum=PAGE_NUM]
# Basic implementation from classic plots2 SearchController
desc 'Perform a search of documents associated with tags within the system', hidden: false,
is_array: false,
nickname: 'srchGetByTags'

params do
requires :srchString, type: String, documentation: { example: 'Spec' }
optional :seq, type: Integer, documentation: { example: 995 }
optional :showCount, type: Integer, documentation: { example: 3 }
optional :pageNum, type: Integer, documentation: { example: 0 }
end
get :tags do
sresult = DocList.new
unless params[:srchString].nil? || params[:srchString] == 0
sservice = SearchService.new
sresult = sservice.textSearch_tags(params[:srchString])
end
sparms = SearchRequest.fromRequest(params)
sresult.srchParams = sparms
sresult
use :common
end
endpoint = 'tags'
create(endpoint)

# Request URL should be /api/srch/taglocations?srchString=QRY[&tagName=awesome&seq=KEYCOUNT&showCount=NUM_ROWS&pageNum=PAGE_NUM]
# Request URL should be /api/srch/locations?srchString=QRY[&seq=KEYCOUNT&showCount=NUM_ROWS&pageNum=PAGE_NUM]
# Note: Query(QRY as above) must have latitude and longitude as srchString=lat,lon
desc 'Perform a search of documents having nearby latitude, longitude and tag values',
hidden: false,
is_array: false,
nickname: 'srchGetTagLocations'
desc 'Perform a search of documents having nearby latitude and longitude tag values', hidden: false,
is_array: false,
nickname: 'srchGetLocations'


params do
requires :srchString, type: String, documentation: { example: 'Spec' }
use :common
optional :tagName, type: String, documentation: { example: 'awesome' }
optional :seq, type: Integer, documentation: { example: 995 }
optional :showCount, type: Integer, documentation: { example: 3 }
optional :pageNum, type: Integer, documentation: { example: 0 }
end
get :taglocations do
sresult = DocList.new
unless params[:srchString].nil? || params[:srchString] == 0 || !(params[:srchString].include? ",")
sservice = SearchService.new
sresult = sservice.tagNearbyNodes(params[:srchString], params[:tagName])
end
sparms = SearchRequest.fromRequest(params)
sresult.srchParams = sparms
sresult
end
endpoint = 'taglocations'
create(endpoint)

#API TO FETCH QRY RECENT CONTRIBUTORS
# Request URL should be /api/srch/peoplelocations?srchString=QRY[&seq=KEYCOUNT&showCount=NUM_ROWS&pageNum=PAGE_NUM]
#QRY should be a number
desc 'Perform a search to show x Recent People', hidden: false,
is_array: false,
nickname: 'srchGetPeople'

# API TO FETCH QRY RECENT CONTRIBUTORS
# Request URL should be /api/srch/peoplelocations?srchString=QRY[&tagName=group:partsandcrafts&seq=KEYCOUNT&showCount=NUM_ROWS&pageNum=PAGE_NUM]
# QRY should be a number
desc 'Perform a search to show x Recent People',
hidden: false,
is_array: false,
nickname: 'srchGetPeople'
params do
requires :srchString, type: String, documentation: { example: 'Spec' }
use :common
optional :tagName, type: String, documentation: { example: 'group:partsandcrafts' }
optional :seq, type: Integer, documentation: { example: 995 }
optional :showCount, type: Integer, documentation: { example: 3 }
optional :pageNum, type: Integer, documentation: { example: 0 }
end
get :peoplelocations do
sresult = DocList.new
unless params[:srchString].nil? || params[:srchString] == 0
sservice = SearchService.new
sresult = sservice.recentPeople(params[:srchString], params[:tagName])
end
sparms = SearchRequest.fromRequest(params)
sresult.srchParams = sparms
sresult
end

endpoint = 'peoplelocations'
create(endpoint)
# end endpoint definitions
end
end
Expand Down
Loading

0 comments on commit 2b32937

Please sign in to comment.