Parcourir la source

Added internal findByName interface.

Thomas Flucke il y a 2 ans
Parent
commit
fbb124f2d5
1 fichiers modifiés avec 8 ajouts et 7 suppressions
  1. 8 7
      server/app/com/weEat/controllers/FoodController.scala

+ 8 - 7
server/app/com/weEat/controllers/FoodController.scala

@@ -55,15 +55,16 @@ class FoodController @Inject()(
 
   def query(q: String) = Action.async
   { implicit request: Request[AnyContent] =>
+    findByName(q).transform({
+      case Success(x) => Success(Ok(Json.toJson(x)))
+      case Failure(x) => throw x
+    })
+  }
+
+  def findByName(q: String): Future[Seq[FoodNodeId]] =
     withCollection(FoodNodeView) { (collection) =>
-      collection.find(regex("name", q, "i"))
-        .toFuture()
-        .transform({
-          case Success(x) => Success(Ok(Json.toJson(x)))
-          case Failure(x) => throw x
-        })
+      collection.find(regex("name", q, "i")).toFuture()
     }.flatten
-  }
 
   def getByFdcId(fdcId: Long): Future[Option[USDANodeId]] =
     withCollection(FoodNodeView) { (collection) =>