Просмотр исходного кода

Added internal findByName interface.

Thomas Flucke 2 лет назад
Родитель
Сommit
fbb124f2d5
1 измененных файлов с 8 добавлено и 7 удалено
  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) =>