diff --git a/src/recipeDatabase.cpp b/src/recipeDatabase.cpp index b6a057b..6d50512 100644 --- a/src/recipeDatabase.cpp +++ b/src/recipeDatabase.cpp @@ -1,7 +1,6 @@ #include "recipeDatabase.h" #include #include -#include "timer.h" Recipe RecipeDatabase::getRecipeById(int id) { std::string query = "SELECT * FROM recipes WHERE recipeId = " + std::to_string(id) + ";"; @@ -13,7 +12,7 @@ Recipe RecipeDatabase::getRecipeById(int id) { if (res->next()) { return Recipe(res->getInt("recipeId"), - res->getString("recipeName"), + res->getString("recipeName"), res->getInt("authorId"), res->getInt("cookTime"), res->getInt("prepTime"), @@ -45,9 +44,7 @@ RecipeImage RecipeDatabase::getRecipeImage(int id, int imageNumber) { std::unique_ptr res(stmt->executeQuery(query)); if (res->next()) { - return RecipeImage(res->getInt("recipeId"), - res->getInt("imageNumber"), - res->getString("imageURL")); + return RecipeImage(res->getInt("recipeId"), res->getInt("imageNumber"), res->getString("imageURL")); } } catch (sql::SQLException &e) { std::cout << "# ERR: SQLException in " << __FILE__ << " on line " << __LINE__ << std::endl; @@ -60,9 +57,8 @@ RecipeImage RecipeDatabase::getRecipeImage(int id, int imageNumber) { } std::vector RecipeDatabase::getRecipesBySearch(const std::vector &ingredients) { - std::vector result; - + if (ingredients.empty()) { return result; } @@ -70,21 +66,22 @@ std::vector RecipeDatabase::getRecipesBySearch(const std::vector 0 "; if (i < ingredients.size() - 1) { - notInClause += " AND "; + baseQuery += "OR "; + havingClause += "AND "; } } - baseQuery += notInClause + ")) ORDER BY recipes.datePublished DESC LIMIT 50;"; - + baseQuery += havingClause; + baseQuery += " ORDER BY recipes.datePublished DESC LIMIT 20;"; try { auto con = dbConn.getConnection(); @@ -112,6 +109,7 @@ std::vector RecipeDatabase::getRecipesBySearch(const std::vector RecipeDatabase::getAllReviewsForRecipes(const std::vector RecipeDatabase::getIngredientsByRecipe(int recipeId){ std::vector ingredients; - std::string query = - "SELECT ingredients.name, ingredients.ingredientId " - "FROM recipe_ingredients JOIN ingredients " - "ON recipe_ingredients.ingredientId = ingredients.ingredientId " - "WHERE recipeId = " + std::to_string(recipeId) + ";"; + std::string query = "SELECT * FROM ingredients WHERE recipeId = " + std::to_string(recipeId) + ";"; try { auto con = dbConn.getConnection();