diff --git a/busqueda/handler.py b/busqueda/handler.py index 2d0bc15..2f4fe3f 100644 --- a/busqueda/handler.py +++ b/busqueda/handler.py @@ -65,7 +65,7 @@ def handle(req): { p: prefijo del nombre, g: genero del nombre, - a: año de nacimiento + y: año de nacimiento } """ diff --git a/c-busqueda/handler.cr b/c-busqueda/handler.cr index b6cbb00..cd24d4a 100644 --- a/c-busqueda/handler.cr +++ b/c-busqueda/handler.cr @@ -108,6 +108,16 @@ class Handler end def run(request : HTTP::Request) + # Try to find most popular names based on a prefix, year and gender. + # + # Request body is JSON in this form: + # + # { + # p: prefijo del nombre, + # g: genero del nombre, + # y: año de nacimiento + # } + unless (body = request.body).nil? query = Hash(String, String).from_json(body) else @@ -120,7 +130,7 @@ class Handler # Each one either a valid string or nil prefijo = query.fetch("p", "") genero = query.fetch("g", "") - año = query.fetch("a", "") + año = query.fetch("y", "") if !prefijo.empty? prefijo = normalize_name(prefijo) @@ -132,10 +142,7 @@ class Handler genero = nil end - if año.empty? - año = nil - # TODO: check for valid integer - end + año = año.to_i? if prefijo.nil? && año.nil? # Global totals @@ -166,7 +173,7 @@ class Handler LIMIT 50 ) else - # We have all the filters + # We have both sql = %( SELECT contador, nombre FROM nombres