app/controllers/api/v1/swimming_pools_controller.rb
# Returns a JSON-encoded Array of all the rows.
# Each 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.
#
# === Additional params:
# - 'q':    a matching (sub)string for either the SwimmingPool.nickname or SwimmingPool.name
#
Returns a JSON-encoded Array of all the rows.
Each 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.

Additional params:
'q':    a matching (sub)string for either the SwimmingPool.nickname or SwimmingPool.name
Returns a JSON - encoded Array of all the rows . Each 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 . Additional params : ' q ' : a matching ( sub ) string for either the SwimmingPool . nickname or SwimmingPool . name
def index
    if params['q']
      filter = "%#{params['q']}%"
      @swimming_pools = SwimmingPool.where( ["(name LIKE ?) OR (nick_name LIKE ?)", filter, filter] )
          .order( :nick_name )
    else
      @swimming_pools = SwimmingPool.order( :nick_name ).limit(20)
    end
    render status: 200, json: @swimming_pools
  end
def index if params [ 'q' ] filter = "%#{params['q']}%" @swimming_pools = SwimmingPool . where ( [ "(name LIKE ?) OR (nick_name LIKE ?)" , filter , filter ] ) . order ( :nick_name ) else @swimming_pools = SwimmingPool . order ( :nick_name ) . limit ( 20 ) end render status : 200 , json : @swimming_pools end
Returns a JSON-encoded Array of all the rows.
Returns a JSON - encoded Array of all the rows .
# DEBUG #    puts "\r\n**** Api::V1::SwimmingPoolsController #index ****" #    puts "- PARAMS: " << params.inspect # DEBUG #    puts "- returning #{ @swimming_pools.size } result..."