diff --git a/appinfo/routes.php b/appinfo/routes.php index ae8f565d3..0458a4441 100755 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -13,8 +13,6 @@ ['name' => 'main#home', 'url' => '/home', 'verb' => 'GET'], ['name' => 'main#keywords', 'url' => '/keywords', 'verb' => 'GET'], ['name' => 'main#categories', 'url' => '/categories', 'verb' => 'GET'], - ['name' => 'main#category', 'url' => '/category/{category}', 'verb' => 'GET'], - ['name' => 'main#search', 'url' => '/search/{query}', 'verb' => 'GET'], ['name' => 'main#error', 'url' => '/error', 'verb' => 'GET'], ['name' => 'main#create', 'url' => '/recipes/create', 'verb' => 'GET'], ['name' => 'main#new', 'url' => '/recipes/create', 'verb' => 'POST'], @@ -26,9 +24,12 @@ ['name' => 'config#reindex', 'url' => '/reindex', 'verb' => 'POST'], ['name' => 'config#list', 'url' => '/config', 'verb' => 'GET'], ['name' => 'config#config', 'url' => '/config', 'verb' => 'POST'], + /* API routes */ + ['name' => 'main#category', 'url' => '/api/category/{category}', 'verb' => 'GET'], + ['name' => 'main#search', 'url' => '/api/search/{query}', 'verb' => 'GET'], ], - - /* API routes */ + + /* API resources */ 'resources' => [ 'recipe' => ['url' => '/api/recipes'] ] diff --git a/lib/Controller/MainController.php b/lib/Controller/MainController.php index b409238ea..4b4f98e80 100755 --- a/lib/Controller/MainController.php +++ b/lib/Controller/MainController.php @@ -143,7 +143,7 @@ public function search($query) $recipes = $this->service->findRecipesInSearchIndex($query); foreach ($recipes as $i => $recipe) { - $recipes[$i]['image_url'] = $this->urlGenerator->linkToRoute( + $recipes[$i]['imageUrl'] = $this->urlGenerator->linkToRoute( 'cookbook.recipe.image', [ 'id' => $recipe['recipe_id'], @@ -153,6 +153,8 @@ public function search($query) ); } + return new DataResponse($recipes, 200, ['Content-Type' => 'application/json']); + // TODO: Remove obsolete code below when this is ready $response = new TemplateResponse($this->appName, 'content/search', ['query' => $query, 'recipes' => $recipes]); $response->renderAs('blank'); @@ -183,7 +185,7 @@ public function category($category) ] ); } - + return new DataResponse($recipes, Http::STATUS_OK, ['Content-Type' => 'application/json']); } catch (\Exception $e) { return new DataResponse($e->getMessage(), 500); @@ -319,7 +321,7 @@ public function update($id) try { $recipe_data = []; - + parse_str(file_get_contents("php://input"), $recipe_data); $recipe_data['id'] = $id; @@ -331,7 +333,7 @@ public function update($id) } catch (\Exception $e) { return new DataResponse($e->getMessage(), 500); - + } } } diff --git a/lib/Db/RecipeDb.php b/lib/Db/RecipeDb.php index d08e2eea3..0b677c227 100755 --- a/lib/Db/RecipeDb.php +++ b/lib/Db/RecipeDb.php @@ -220,7 +220,10 @@ public function findRecipes(array $keywords, string $user_id) { $qb = $this->db->getQueryBuilder(); $qb->select(['r.recipe_id', 'r.name']) - ->from(self::DB_TABLE_KEYWORDS, 'k'); + ->from(self::DB_TABLE_RECIPES, 'r'); + + $qb->leftJoin('r', self::DB_TABLE_KEYWORDS, 'k', 'k.recipe_id = r.recipe_id'); + $qb->leftJoin('r', self::DB_TABLE_CATEGORIES, 'c', 'r.recipe_id = c.recipe_id'); $paramIdx = 1; $params = []; @@ -232,6 +235,7 @@ public function findRecipes(array $keywords, string $user_id) { $qb->orWhere("LOWER(k.name) LIKE :keyword$paramIdx"); $qb->orWhere("LOWER(r.name) LIKE :keyword$paramIdx"); + $qb->orWhere("LOWER(c.name) LIKE :keyword$paramIdx"); $params["keyword$paramIdx"] = "%$lowerKeyword%"; $types["keyword$paramIdx"] = Type::STRING; @@ -239,12 +243,10 @@ public function findRecipes(array $keywords, string $user_id) { } - $qb->andWhere('k.user_id = :user'); + $qb->andWhere('r.user_id = :user'); $qb->setParameters($params, $types); $qb->setParameter('user', $user_id, TYPE::STRING); - - $qb->join('k', self::DB_TABLE_RECIPES, 'r', 'k.recipe_id = r.recipe_id'); $qb->groupBy(['r.name', 'r.recipe_id']); $qb->orderBy('r.name'); diff --git a/src/components/AppControls.vue b/src/components/AppControls.vue index cba9ea4ae..ce657d375 100644 --- a/src/components/AppControls.vue +++ b/src/components/AppControls.vue @@ -5,12 +5,12 @@ - - + {{ t('cookbook', 'Filter') }} + {{ t('cookbook', 'Search') }} - --> @@ -87,17 +87,18 @@