app/controllers/api/v1/swimmers_controller.rb
# Returns a JSON-encoded Array of all the matching rows -- specific version, tailored for
# Badge management, that allows to search among Swimmers that do not have a badge yet.
# Each returned array element is a JSON-encoded hash of a single row.
# The keys of the Hash are the attributes as string.
#
# === Params:
# - 'q': query; select any Swimmer with a matching complete_name for the specified (sub)string
# - 's': season_id; exclude any swimmer that already has a badge for the specified Season ID
#
# === Returns:
# An array of JSON objects having the following individual structre:
#
#  {
#    'swimmer': swimmer_object,
#    'season_id': season_id,
#    'category': category_type_object_for_season_id
#  }
#
# For both the swimmer and the category objects, the field keys are equal to the
# corresponding instance attributes as strings.
#
Returns a JSON-encoded Array of all the matching rows -- specific version, tailored for
Badge management, that allows to search among Swimmers that do not have a badge yet.
Each returned array element is a JSON-encoded hash of a single row.
The keys of the Hash are the attributes as string.

'q': query; select any Swimmer with a matching complete_name for the specified (sub)string
's': season_id; exclude any swimmer that already has a badge for the specified Season ID

An array of JSON objects having the following individual structre.



For both the swimmer and the category objects, the field keys are equal to the
corresponding instance attributes as strings.
Returns a JSON - encoded Array of all the matching rows -- specific version tailored for Badge management that allows to search among Swimmers that do not have a badge yet . Each returned array element is a JSON - encoded hash of a single row . The keys of the Hash are the attributes as string . ' q ' : query ; select any Swimmer with a matching complete_name for the specified ( sub ) string ' s ' : season_id ; exclude any swimmer that already has a badge for the specified Season ID An array of JSON objects having the following individual structre . For both the swimmer and the category objects the field keys are equal to the corresponding instance attributes as strings .
def unbadged
    render(
      status: 400,
      json: { success: false, error: "Invalid or missing required parameters!" }
    ) and return unless params['q'].present? && params['s'].present?
    @swimmers = Swimmer.where.not(id: Badge.where(season_id: params['s']).select(:swimmer_id))
                       .where("(complete_name LIKE ?)", "%#{params['q']}%")
                       .order(:complete_name)
                       .limit(20)
                       .map do |swimmer|
                        {
                          swimmer: swimmer,
                          season_id: params['s'],
                          category: CategoryType.get_category_from(params['s'].to_i, swimmer.year_of_birth)
                        }
                       end
    render json: @swimmers
  end
def unbadged render ( status : 400 , json : { success : false , error : "Invalid or missing required parameters!" } ) and return unless params [ 'q' ] . present? && params [ 's' ] . present? @swimmers = Swimmer . where . not ( id : Badge . where ( season_id : params [ 's' ] ) . select ( :swimmer_id ) ) . where ( "(complete_name LIKE ?)" , "%#{params['q']}%" ) . order ( :complete_name ) . limit ( 20 ) . map do | swimmer | { swimmer : swimmer , season_id : params [ 's' ] , category : CategoryType . get_category_from ( params [ 's' ] . to_i , swimmer . year_of_birth ) } end render json : @swimmers end
Returns a JSON-encoded Array of all the matching rows -- specific version, tailored for
Badge management, that allows to search among Swimmers that do not have a badge yet.
Returns a JSON - encoded Array of all the matching rows -- specific version tailored for Badge management that allows to search among Swimmers that do not have a badge yet .
# DEBUG # logger.debug( "\r\n\r\n!! ------ #{self.class.name}/unbadged -----" ) # logger.debug( "PARAMS => #{params.inspect}\r\n" ) # All swimmers that do not have a badge in the enlisted seasons and have a complete name that matches the search string: # DEBUG # puts "- returning #{ @swimmers.size } result..."