2018-03-01 16:19:13 +00:00
|
|
|
#ifndef RECIPEDATABASE_H
|
|
|
|
#define RECIPEDATABASE_H
|
|
|
|
|
2018-03-30 12:33:48 +00:00
|
|
|
#include <map>
|
2018-03-01 16:19:13 +00:00
|
|
|
|
|
|
|
#include "database.h"
|
2018-03-01 16:28:18 +00:00
|
|
|
#include "model/recipe/recipe.h"
|
2018-03-02 13:14:56 +00:00
|
|
|
#include "utils/fileutils.h"
|
2018-03-01 16:19:13 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The RecipeDatabase class represents the precise database used for the recipe storage, and is specialized.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class RecipeDatabase : public Database
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RecipeDatabase(string filename);
|
2018-03-01 16:28:18 +00:00
|
|
|
|
|
|
|
//Stores a full recipe in the database.
|
2018-03-02 13:14:56 +00:00
|
|
|
bool storeRecipe(Recipe recipe);
|
2018-03-02 08:32:40 +00:00
|
|
|
|
|
|
|
//SQL Helper methods.
|
2018-03-10 07:51:17 +00:00
|
|
|
//Storage.
|
2018-05-22 21:06:11 +00:00
|
|
|
bool storeRecipeIngredient(Ingredient i, int recipeId);
|
2018-03-03 07:38:32 +00:00
|
|
|
|
2018-03-10 07:51:17 +00:00
|
|
|
//Retrieval.
|
2018-03-03 07:48:55 +00:00
|
|
|
Recipe retrieveRecipe(string name);
|
2018-03-29 14:09:58 +00:00
|
|
|
Recipe retrieveRandomRecipe();
|
2018-03-11 11:53:30 +00:00
|
|
|
vector<Recipe> retrieveAllRecipes();
|
2018-03-30 20:50:02 +00:00
|
|
|
vector<Recipe> retrieveRecipesWithTags(vector<RecipeTag> tags);
|
|
|
|
vector<Recipe> retrieveRecipesWithSubstring(string s);
|
2018-03-10 07:51:17 +00:00
|
|
|
vector<Ingredient> retrieveAllIngredients();
|
2018-03-10 11:36:14 +00:00
|
|
|
vector<RecipeTag> retrieveAllTags();
|
2018-03-10 13:56:43 +00:00
|
|
|
|
|
|
|
//Deletion.
|
2018-03-29 07:58:25 +00:00
|
|
|
bool deleteRecipe(string name);
|
2018-03-29 09:21:00 +00:00
|
|
|
bool deleteRecipe(int recipeId);
|
|
|
|
bool deleteIngredient(string name);
|
|
|
|
bool deleteUnitOfMeasure(string name);
|
|
|
|
bool deleteTag(RecipeTag tag);
|
2018-03-30 21:25:28 +00:00
|
|
|
|
|
|
|
//Updating.
|
2018-03-31 10:53:31 +00:00
|
|
|
bool updateRecipe(Recipe recipe, string originalName);
|
2018-03-31 13:02:35 +00:00
|
|
|
|
2018-03-01 16:19:13 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
//Utility methods.
|
|
|
|
void ensureTablesExist();
|
2018-03-29 14:09:58 +00:00
|
|
|
//Read a recipe from a row of a result table.
|
|
|
|
Recipe readFromResultTable(ResultTable t, int row=0);
|
2018-03-30 18:57:14 +00:00
|
|
|
vector<Recipe> readRecipesFromTable(ResultTable t);
|
2018-03-31 10:53:31 +00:00
|
|
|
|
|
|
|
//Storage
|
|
|
|
bool storeInstruction(Instruction instruction, int recipeId);
|
|
|
|
bool storeImage(QImage image, int recipeId);
|
|
|
|
bool storeTags(vector<RecipeTag> tags, int recipeId);
|
|
|
|
|
|
|
|
//Retrieval
|
|
|
|
vector<RecipeTag> retrieveTags(int recipeId);
|
2018-05-22 21:06:11 +00:00
|
|
|
vector<Ingredient> retrieveRecipeIngredients(int recipeId);
|
2018-03-31 10:53:31 +00:00
|
|
|
|
|
|
|
//Deletion
|
|
|
|
bool deleteRecipeTags(int recipeId);
|
|
|
|
bool deleteRecipeIngredients(int recipeId);
|
2018-03-01 16:19:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // RECIPEDATABASE_H
|