app/controllers/api/v1/swimmers_controller.rb
# Returns a JSON-encoded Array of all the matching rows.
# Each returned array element is a JSON-encoded hash of a single row.
# The keys of the Hash are the attributes as string.
# The returned set when no querying/filtering parameter is provided  is
# capped to return 20 rows max.
#
# XXX [Steve, 2016107] Note that we cannot cap the limit of the query
# when seeking a specified value, since the actual search result may well lay
# beyond the limit set.
#
# === Params:
# - 'q': filter by matching (sub)string for the Swimmer.complete_name
# - 't': (additional) filter by a team_id array
# - 's': (additional) filter by a SINGLE season_id array
#
Returns a JSON-encoded Array of all the matching rows.
Each returned array element is a JSON-encoded hash of a single row.
The keys of the Hash are the attributes as string.
The returned set when no querying/filtering parameter is provided  is
capped to return 20 rows max.

XXX [Steve, 2016107] Note that we cannot cap the limit of the query
when seeking a specified value, since the actual search result may well lay
beyond the limit set.


Returns a JSON - encoded Array of all the matching rows . Each returned array element is a JSON - encoded hash of a single row . The keys of the Hash are the attributes as string . The returned set when no querying / filtering parameter is provided is capped to return 20 rows max . XXX [ Steve 2016107 ] Note that we cannot cap the limit of the query when seeking a specified value since the actual search result may well lay beyond the limit set .
def index
    where_clause = []
    where_params = []
    if params['q'].present?
      where_clause << "(complete_name LIKE ?)"
      where_params << "%#{params['q']}%"
    end
    if params['t'].present?
      where_clause << "(badges.team_id IN (?))"
      where_params << params['t']
    end
    if params['s'].present?
      where_clause << "(badges.season_id = ?)"
      where_params << params['s']
    end
    if where_clause.size > 0
      @swimmers = Swimmer.includes(:badges).joins(:badges)
        .where( [ where_clause.join(' AND ') ] + where_params )
        .order( :complete_name )
    else
      @swimmers = Swimmer.order( :complete_name ).limit(20)
    end
    render status: 200, json: @swimmers
  end
def index where_clause = [ ] where_params = [ ] if params [ 'q' ] . present? where_clause << "(complete_name LIKE ?)" where_params << "%#{params['q']}%" end if params [ 't' ] . present? where_clause << "(badges.team_id IN (?))" where_params << params [ 't' ] end if params [ 's' ] . present? where_clause << "(badges.season_id = ?)" where_params << params [ 's' ] end if where_clause . size > 0 @swimmers = Swimmer . includes ( :badges ) . joins ( :badges ) . where ( [ where_clause . join ( ' AND ' ) ] + where_params ) . order ( :complete_name ) else @swimmers = Swimmer . order ( :complete_name ) . limit ( 20 ) end render status : 200 , json : @swimmers end
Returns a JSON-encoded Array of all the matching rows.
Returns a JSON - encoded Array of all the matching rows .
# DEBUG #    logger.debug( "\r\n\r\n!! ------ #{self.class.name} - index -----" ) #    logger.debug( "PARAMS => #{params.inspect}\r\n" ) # Filter by query: # Filter by team IDs: # Filter by season ID: # Apply filters: # No filters (just a limit): # DEBUG #    puts "- returning #{ @swimmers.size } result..."