|
|
@@ -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) =>
|