nitweb/src: APISearch super APIList
authorAlexandre Terrasa <alexandre@moz-code.org>
Thu, 2 Jun 2016 23:18:31 +0000 (19:18 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Thu, 2 Jun 2016 23:18:52 +0000 (19:18 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/web/model_api.nit

index df84816..9bbe5ad 100644 (file)
@@ -77,26 +77,6 @@ class APIRouter
        end
 end
 
-# Search mentities from a query string.
-#
-# Example: `GET /search?q=Arr`
-class APISearch
-       super APIHandler
-
-       redef fun get(req, res) do
-               var q = req.string_arg("q")
-               if q == null then
-                       res.error 400
-                       return
-               end
-               var arr = new JsonArray
-               for mentity in view.mentities do
-                       if mentity.name.has_prefix(q) then arr.add mentity
-               end
-               res.json arr
-       end
-end
-
 # List all mentities.
 #
 # MEntities can be filtered on their kind using the `k` parameter.
@@ -148,6 +128,23 @@ class APIList
        end
 end
 
+# Search mentities from a query string.
+#
+# Example: `GET /search?q=Arr`
+class APISearch
+       super APIList
+
+       redef fun list_mentities(req) do
+               var q = req.string_arg("q")
+               var mentities = new Array[MEntity]
+               if q == null then return mentities
+               for mentity in view.mentities do
+                       if mentity.name.has_prefix(q) then mentities.add mentity
+               end
+               return mentities
+       end
+end
+
 # Return a random list of MEntities.
 #
 # Example: `GET /random?n=10&k=module`