-
Notifications
You must be signed in to change notification settings - Fork 0
Federation search endpoint #15
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
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,72 @@ | ||||||||||||||
| require 'faraday' | ||||||||||||||
|
|
||||||||||||||
| class FederationController < ApplicationController | ||||||||||||||
|
|
||||||||||||||
| GATEWAY_URL = "https://terminology.services.base4nfdi.de/api-gateway" | ||||||||||||||
| GATEWAY_CONNECTION = Faraday.new(url: GATEWAY_URL) do |conn| | ||||||||||||||
| conn.headers['Accept'] = 'application/json' | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| namespace "/api/federation" do | ||||||||||||||
|
|
||||||||||||||
| get'/search' do | ||||||||||||||
Imene-Amirat marked this conversation as resolved.
Show resolved
Hide resolved
Imene-Amirat marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
| query = params[:query] || params[:q] | ||||||||||||||
|
|
||||||||||||||
| if query.nil? || query.strip.empty? | ||||||||||||||
| error 400, "You must provide a 'query' parameter to execute a search" | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| gateway_params = { query: query, database: "ontoportal" } | ||||||||||||||
|
|
||||||||||||||
| response = GATEWAY_CONNECTION.get("search", gateway_params) | ||||||||||||||
|
|
||||||||||||||
| unless response.success? | ||||||||||||||
| error response.status, "API Gateway error: #{response.body}" | ||||||||||||||
|
||||||||||||||
| error response.status, "API Gateway error: #{response.body}" | |
| Rails.logger.error("API Gateway error: status=#{response.status}, body=#{response.body}") if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger | |
| error response.status, "API Gateway error: upstream service returned an error" |
Imene-Amirat marked this conversation as resolved.
Show resolved
Hide resolved
Imene-Amirat marked this conversation as resolved.
Show resolved
Hide resolved
Imene-Amirat marked this conversation as resolved.
Show resolved
Hide resolved
Imene-Amirat marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Mar 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This endpoint ignores page/pagesize request params and always returns all gateway results. Because page_object assumes the collection is already paginated, this can produce responses where itemsPerPage doesn’t match the number of returned members and pagination links become misleading. Please apply local slicing (using page_params + offset_and_limit) before building the page object.
| reply 200, page_object(docs, total_found) | |
| page, page_size = page_params | |
| offset, limit = offset_and_limit(total_found, page, page_size) | |
| paginated_docs = docs.slice(offset, limit) || [] | |
| reply 200, page_object(paginated_docs, total_found) |
Uh oh!
There was an error while loading. Please reload this page.