diff --git a/.gitignore b/.gitignore
index da7a856..36ae88b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,6 @@
/backend/API/appsettings.Development.json
/backend/API/appsettings.json
*bin
+/backend/API/database.sqlite3
+/backend/API/database.sqlite3-shm
+/backend/API/database.sqlite3-wal
diff --git a/app/app/src/main/java/tech/mercantec/easyeat/CreateDishActivity.kt b/app/app/src/main/java/tech/mercantec/easyeat/CreateDishActivity.kt
index 21e10ac..7485b2b 100644
--- a/app/app/src/main/java/tech/mercantec/easyeat/CreateDishActivity.kt
+++ b/app/app/src/main/java/tech/mercantec/easyeat/CreateDishActivity.kt
@@ -1,25 +1,42 @@
package tech.mercantec.easyeat
import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.widget.Button
+import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
-import androidx.appcompat.widget.Toolbar
class CreateDishActivity : AppCompatActivity() {
+
+ private lateinit var ingredientContainer: LinearLayout
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_create_dish_form)
- // Setup the Toolbar as ActionBar
- val toolbar: Toolbar = findViewById(R.id.toolbar)
- setSupportActionBar(toolbar)
+ ingredientContainer = findViewById(R.id.ingredientContainer)
+ val addButton: Button = findViewById(R.id.addIngredientButton)
- // Enable the Up button
- supportActionBar?.setDisplayHomeAsUpEnabled(true)
+ // Add the first ingredient row manually at startup
+ addIngredientRow()
+
+ // Set up button to add new rows
+ addButton.setOnClickListener {
+ addIngredientRow()
+ }
}
- // Handle the Up button click
- override fun onSupportNavigateUp(): Boolean {
- onBackPressedDispatcher.onBackPressed()
- return true
+ private fun addIngredientRow() {
+ val inflater = LayoutInflater.from(this)
+ val ingredientRow = inflater.inflate(R.layout.activity_create_dish_ingredient_row, null)
+
+ // Handle remove button in each row
+ val removeButton: Button = ingredientRow.findViewById(R.id.removeButton)
+ removeButton.setOnClickListener {
+ ingredientContainer.removeView(ingredientRow)
+ }
+
+ ingredientContainer.addView(ingredientRow)
}
}
diff --git a/app/app/src/main/res/layout/activity_create_dish_form.xml b/app/app/src/main/res/layout/activity_create_dish_form.xml
index b64643f..62e333a 100644
--- a/app/app/src/main/res/layout/activity_create_dish_form.xml
+++ b/app/app/src/main/res/layout/activity_create_dish_form.xml
@@ -6,14 +6,6 @@
android:orientation="vertical"
android:padding="16dp">
-
-
-
-
+
+
+
diff --git a/backend/API/API.csproj b/backend/API/API.csproj
index 1e9549b..e1ff1ea 100644
--- a/backend/API/API.csproj
+++ b/backend/API/API.csproj
@@ -13,6 +13,7 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/backend/API/BusinessLogic/RecipeLogic.cs b/backend/API/BusinessLogic/RecipeLogic.cs
new file mode 100644
index 0000000..fb101f0
--- /dev/null
+++ b/backend/API/BusinessLogic/RecipeLogic.cs
@@ -0,0 +1,100 @@
+using API.DBAccess;
+using API.Models.RecipeModels;
+using Microsoft.AspNetCore.Mvc;
+
+namespace API.BusinessLogic
+{
+ public class RecipeLogic
+ {
+ private readonly RecipeDBAccess _dbAccess;
+
+ public RecipeLogic(RecipeDBAccess dbAccess)
+ {
+ _dbAccess = dbAccess;
+ }
+
+ public async Task GetPrefereredRecipes(int userId)
+ {
+ PrefereredRecipes recipes = await _dbAccess.ReadPrefereredRecipes(userId);
+ if (recipes == null) { recipes = await _dbAccess.CreateMissingLists(userId); }
+ if (recipes == null || recipes.Id == 0) { return new ConflictObjectResult(new { message = "Could not find any recipes" }); }
+
+ return new OkObjectResult(recipes);
+ }
+
+ public async Task GetRecipe(int recipeId)
+ {
+ var recipe = await _dbAccess.ReadRecipe(recipeId);
+
+ if (recipe == null || recipe.Id == 0) { return new ConflictObjectResult(new { message = "Could not find any recipe" }); }
+
+ return new OkObjectResult(recipe);
+ }
+
+ public async Task CreateRecipe(RecipeDTO recipe, int prefereredRecipesId)
+ {
+ var prefereredRecipes = await _dbAccess.ReadAllRecipe(prefereredRecipesId);
+
+ foreach (var item in prefereredRecipes.Recipes)
+ {
+ if (item.Name == recipe.Name)
+ {
+ return new ConflictObjectResult(new { message = "Recipe name is already in use." });
+ }
+ }
+
+ Recipe recipe1 = new Recipe();
+ recipe1.Name = recipe.Name;
+ recipe1.Directions = recipe.Directions;
+ recipe1.Description = recipe.Description;
+ recipe1.Ingredients = new List();
+ foreach (var item in recipe.Ingredients)
+ {
+ Ingredient ingredient = new Ingredient();
+ ingredient.Unit = item.Unit;
+ ingredient.Element = item.Element;
+ ingredient.Amount = item.Amount;
+ recipe1.Ingredients.Add(ingredient);
+ }
+
+ return await _dbAccess.CreateRecipe(recipe1, prefereredRecipesId);
+ }
+
+ public async Task EditRecipe(RecipeDTO recipe, int recipeId, int userId)
+ {
+ var prefereredRecipes = await _dbAccess.ReadPrefereredRecipes(userId);
+ var dish = await _dbAccess.ReadRecipe(recipeId);
+
+ foreach (var item in prefereredRecipes.Recipes)
+ {
+ if (item.Name == recipe.Name)
+ {
+ return new ConflictObjectResult(new { message = "Recipe name is already in use." });
+ }
+ }
+
+ dish.Name = recipe.Name;
+ dish.Description = recipe.Description;
+ dish.Directions = recipe.Directions;
+ foreach (var item in recipe.Ingredients)
+ {
+ Ingredient ingredient = new Ingredient();
+ ingredient.Unit = item.Unit;
+ ingredient.Element = item.Element;
+ ingredient.Amount = item.Amount;
+ dish.Ingredients.Add(ingredient);
+ }
+
+ return await _dbAccess.UpdateRecipe(dish);
+ }
+
+ public async Task DeleteRecipe(int recipeId)
+ {
+ var recipe = await _dbAccess.ReadRecipe(recipeId);
+
+ if (recipe != null) { return await _dbAccess.DeleteUser(recipe); }
+
+ return new ConflictObjectResult(new { message = "Invalid user" });
+ }
+ }
+}
diff --git a/backend/API/BusinessLogic/ShoppingListLogic.cs b/backend/API/BusinessLogic/ShoppingListLogic.cs
new file mode 100644
index 0000000..87c4165
--- /dev/null
+++ b/backend/API/BusinessLogic/ShoppingListLogic.cs
@@ -0,0 +1,209 @@
+using API.DBAccess;
+using API.Models.ShoppingListModels;
+using Microsoft.AspNetCore.Mvc;
+
+namespace API.BusinessLogic
+{
+ public class ShoppingListLogic
+ {
+ private readonly ShoppingListDBAccess _dbAccess;
+ private readonly RecipeDBAccess _recipeDBAccess;
+
+ public ShoppingListLogic(ShoppingListDBAccess dbAccess, RecipeDBAccess recipeDBAccess)
+ {
+ _dbAccess = dbAccess;
+ _recipeDBAccess = recipeDBAccess;
+ }
+
+ public async Task ReadShoppingList(int userId)
+ {
+ var user = await _dbAccess.ReadShoppingList(userId);
+
+ return new OkObjectResult(user.ShoppingList);
+ }
+
+ public async Task AddItemToShoppingList(ShoppingListItemDTO listItemDTO, int userId)
+ {
+ var user = await _dbAccess.ReadShoppingList(userId);
+
+ List shoppingList = user.ShoppingList;
+
+ if (shoppingList.Any(s => s.Name == listItemDTO.Name))
+ {
+ ShoppingList item = shoppingList.Where(s => s.Name == listItemDTO.Name).FirstOrDefault();
+ shoppingList.Remove(item);
+
+ if (item.Unit == listItemDTO.Unit)
+ {
+ item.Amount += listItemDTO.Amount;
+ }
+ else if (item.Unit == "g" && listItemDTO.Unit == "kg")
+ {
+ item.Amount = (item.Amount / 1000) + listItemDTO.Amount;
+ item.Unit = "kg";
+ }
+ else if (item.Unit == "ml" && item.Unit == "l")
+ {
+ item.Amount = (item.Amount / 1000) + listItemDTO.Amount;
+ item.Unit = "l";
+ }
+ else if (item.Unit == "dl" && item.Unit == "l")
+ {
+ item.Amount = (item.Amount / 10) + listItemDTO.Amount;
+ item.Unit = "l";
+ }
+
+ item.Checked = false;
+
+ if (item.Unit == "g" && item.Amount >= 1000)
+ {
+ item.Unit = "kg";
+ item.Amount = item.Amount / 1000;
+ }
+ else if (item.Unit == "ml" && item.Amount >= 1000)
+ {
+ item.Unit = "l";
+ item.Amount = item.Amount / 1000;
+ }
+ else if (item.Unit == "dl" && item.Amount >= 10)
+ {
+ item.Unit = "l";
+ item.Amount = item.Amount / 10;
+ }
+ user.ShoppingList.Add(item);
+ }
+ else
+ {
+ ShoppingList newItem = new ShoppingList();
+ newItem.Name = listItemDTO.Name;
+ newItem.Amount = listItemDTO.Amount;
+ newItem.Unit = listItemDTO.Unit;
+ newItem.Checked = false;
+
+ user.ShoppingList.Add(newItem);
+ }
+ return await _dbAccess.UpdateShoppingList(user);
+ }
+
+ public async Task CheckItemInShoppingList(int userId, int itemId)
+ {
+ var user = await _dbAccess.ReadShoppingList(userId);
+
+ int itemIndex = user.ShoppingList.FindIndex(x => x.Id == itemId);
+
+ user.ShoppingList[itemIndex].Checked = !user.ShoppingList[itemIndex].Checked;
+
+ return await _dbAccess.UpdateShoppingList(user);
+ }
+
+ public async Task UpdateItemInShoppingList(int userId, int itemId, ShoppingListItemDTO listItemDTO)
+ {
+ var user = await _dbAccess.ReadShoppingList(userId);
+
+ int itemIndex = user.ShoppingList.FindIndex(x => x.Id == itemId);
+
+ user.ShoppingList[itemIndex].Unit = listItemDTO.Unit;
+ user.ShoppingList[itemIndex].Name = listItemDTO.Name;
+ user.ShoppingList[itemIndex].Amount = listItemDTO.Amount;
+
+ if (user.ShoppingList[itemIndex].Unit == "g" && user.ShoppingList[itemIndex].Amount >= 1000)
+ {
+ user.ShoppingList[itemIndex].Unit = "kg";
+ user.ShoppingList[itemIndex].Amount = user.ShoppingList[itemIndex].Amount / 1000;
+ }
+ else if (user.ShoppingList[itemIndex].Unit == "ml" && user.ShoppingList[itemIndex].Amount >= 1000)
+ {
+ user.ShoppingList[itemIndex].Unit = "l";
+ user.ShoppingList[itemIndex].Amount = user.ShoppingList[itemIndex].Amount / 1000;
+ }
+ else if (user.ShoppingList[itemIndex].Unit == "dl" && user.ShoppingList[itemIndex].Amount >= 10)
+ {
+ user.ShoppingList[itemIndex].Unit = "l";
+ user.ShoppingList[itemIndex].Amount = user.ShoppingList[itemIndex].Amount / 10;
+ }
+
+ return await _dbAccess.UpdateShoppingList(user);
+ }
+
+ public async Task DeleteItemInShoppingList(int userId, int itemId)
+ {
+ var user = await _dbAccess.ReadShoppingList(userId);
+
+ int itemIndex = user.ShoppingList.FindIndex(x => x.Id == itemId);
+
+ user.ShoppingList.RemoveAt(itemIndex);
+
+ return await _dbAccess.UpdateShoppingList(user);
+ }
+
+ public async Task AddRecipeToShoppingList(int userId, int recipeId)
+ {
+ var user = await _dbAccess.ReadShoppingList(userId);
+ var recipe = await _recipeDBAccess.ReadRecipe(recipeId);
+ var ingredients = recipe.Ingredients;
+
+ foreach (var ingredient in ingredients)
+ {
+ List shoppingList = user.ShoppingList;
+
+ if (shoppingList.Any(s => s.Name == ingredient.Element))
+ {
+ ShoppingList item = shoppingList.Where(s => s.Name == ingredient.Element).FirstOrDefault();
+ shoppingList.Remove(item);
+
+ if (item.Unit == ingredient.Unit)
+ {
+ item.Amount += ingredient.Amount;
+ }
+ else if (item.Unit == "g" && ingredient.Unit == "kg")
+ {
+ item.Amount = (item.Amount / 1000) + ingredient.Amount;
+ item.Unit = "kg";
+ }
+ else if (item.Unit == "ml" && item.Unit == "l")
+ {
+ item.Amount = (item.Amount / 1000) + ingredient.Amount;
+ item.Unit = "l";
+ }
+ else if (item.Unit == "dl" && item.Unit == "l")
+ {
+ item.Amount = (item.Amount / 10) + ingredient.Amount;
+ item.Unit = "l";
+ }
+
+ item.Checked = false;
+
+ if (item.Unit == "g" && item.Amount >= 1000)
+ {
+ item.Unit = "kg";
+ item.Amount = item.Amount / 1000;
+ }
+ else if (item.Unit == "ml" && item.Amount >= 1000)
+ {
+ item.Unit = "l";
+ item.Amount = item.Amount / 1000;
+ }
+ else if (item.Unit == "dl" && item.Amount >= 10)
+ {
+ item.Unit = "l";
+ item.Amount = item.Amount / 10;
+ }
+
+ user.ShoppingList.Add(item);
+ }
+ else
+ {
+ ShoppingList newItem = new ShoppingList();
+ newItem.Name = ingredient.Element;
+ newItem.Amount = ingredient.Amount;
+ newItem.Unit = ingredient.Unit;
+ newItem.Checked = false;
+
+ user.ShoppingList.Add(newItem);
+ }
+ }
+
+ return await _dbAccess.UpdateShoppingList(user);
+ }
+ }
+}
diff --git a/backend/API/BusinessLogic/UserLogic.cs b/backend/API/BusinessLogic/UserLogic.cs
index 07fb887..c257631 100644
--- a/backend/API/BusinessLogic/UserLogic.cs
+++ b/backend/API/BusinessLogic/UserLogic.cs
@@ -1,22 +1,23 @@
using API.DBAccess;
using API.Models.UserModels;
+using API.Models.RecipeModels;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
-using Org.BouncyCastle.Asn1.Ocsp;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
+using API.Models.ShoppingListModels;
namespace API.BusinessLogic
{
public class UserLogic
{
- private readonly DbAccess _dbAccess;
+ private readonly UserDBAccess _dbAccess;
private readonly IConfiguration _configuration;
- public UserLogic(IConfiguration configuration, DbAccess dbAccess)
+ public UserLogic(IConfiguration configuration, UserDBAccess dbAccess)
{
_dbAccess = dbAccess;
_configuration = configuration;
@@ -60,12 +61,17 @@ namespace API.BusinessLogic
string salt = Guid.NewGuid().ToString();
string hashedPassword = ComputeHash(userDTO.Password, SHA256.Create(), salt);
+ PrefereredRecipes recipes = new PrefereredRecipes();
+ recipes.Recipes = new List();
+
User user = new User
{
UserName = userDTO.UserName,
Email = userDTO.Email,
Password = hashedPassword,
Salt = salt,
+ PrefereredRecipes = recipes,
+ ShoppingList = new List(),
};
return await _dbAccess.CreateUser(user);
diff --git a/backend/API/Controllers/RecipeController.cs b/backend/API/Controllers/RecipeController.cs
new file mode 100644
index 0000000..bb9c1eb
--- /dev/null
+++ b/backend/API/Controllers/RecipeController.cs
@@ -0,0 +1,61 @@
+using API.BusinessLogic;
+using API.Models.RecipeModels;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using System.Security.Claims;
+
+namespace API.Controllers
+{
+ [ApiController]
+ [Route("api/[controller]")]
+ public class RecipeController :Controller
+ {
+ private readonly RecipeLogic _recipeLogic;
+
+ public RecipeController(RecipeLogic recipeLogic)
+ {
+ _recipeLogic = recipeLogic;
+ }
+
+ [Authorize]
+ [HttpGet("getall")]
+ public async Task ReadPrefereredRecipes()
+ {
+ var claims = HttpContext.User.Claims;
+ string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
+ int userId = Convert.ToInt32(userIdString);
+ return await _recipeLogic.GetPrefereredRecipes(userId);
+ }
+
+ [Authorize]
+ [HttpGet("get/{recipeId}")]
+ public async Task ReadRecipe(int recipeId)
+ {
+ return await _recipeLogic.GetRecipe(recipeId);
+ }
+
+ [Authorize]
+ [HttpPost("create/{prefereredRecipesId}")]
+ public async Task CreateRecipe([FromBody] RecipeDTO recipe, int prefereredRecipesId)
+ {
+ return await _recipeLogic.CreateRecipe(recipe, prefereredRecipesId);
+ }
+
+ [Authorize]
+ [HttpPut("edit/{recipeId}")]
+ public async Task EditRecipe([FromBody] RecipeDTO recipe, int recipeId)
+ {
+ var claims = HttpContext.User.Claims;
+ string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
+ int userId = Convert.ToInt32(userIdString);
+ return await _recipeLogic.EditRecipe(recipe, recipeId, userId);
+ }
+
+ [Authorize]
+ [HttpDelete("delete/{recipeId}")]
+ public async Task DeleteRecipe(int recipeId)
+ {
+ return await _recipeLogic.DeleteRecipe(recipeId);
+ }
+ }
+}
diff --git a/backend/API/Controllers/ShoppingListController.cs b/backend/API/Controllers/ShoppingListController.cs
new file mode 100644
index 0000000..7db1bd4
--- /dev/null
+++ b/backend/API/Controllers/ShoppingListController.cs
@@ -0,0 +1,74 @@
+
+using API.BusinessLogic;
+using API.Models.ShoppingListModels;
+using Microsoft.AspNetCore.Mvc;
+using System.Security.Claims;
+
+namespace API.Controllers
+{
+ [ApiController]
+ [Route("api/[controller]")]
+ public class ShoppingListController : Controller
+ {
+ private readonly ShoppingListLogic _shoppingListLogic;
+
+ public ShoppingListController(ShoppingListLogic shoppingListLogic)
+ {
+ _shoppingListLogic = shoppingListLogic;
+ }
+
+ [HttpGet("get")]
+ public async Task ReadShoppingList()
+ {
+ var claims = HttpContext.User.Claims;
+ string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
+ int userId = Convert.ToInt32(userIdString);
+ return await _shoppingListLogic.ReadShoppingList(userId);
+ }
+
+ [HttpPost("add")]
+ public async Task AddItem([FromBody] ShoppingListItemDTO listItemDTO)
+ {
+ var claims = HttpContext.User.Claims;
+ string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
+ int userId = Convert.ToInt32(userIdString);
+ return await _shoppingListLogic.AddItemToShoppingList(listItemDTO, userId);
+ }
+
+ [HttpPut("check")]
+ public async Task CheckItem(int itemId)
+ {
+ var claims = HttpContext.User.Claims;
+ string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
+ int userId = Convert.ToInt32(userIdString);
+ return await _shoppingListLogic.CheckItemInShoppingList(userId, itemId);
+ }
+
+ [HttpPut("update")]
+ public async Task UpdateItem([FromBody] ShoppingListItemDTO listItemDTO, int itemId)
+ {
+ var claims = HttpContext.User.Claims;
+ string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
+ int userId = Convert.ToInt32(userIdString);
+ return await _shoppingListLogic.UpdateItemInShoppingList(userId, itemId, listItemDTO);
+ }
+
+ [HttpDelete("delete")]
+ public async Task DeleteItem(int itemId)
+ {
+ var claims = HttpContext.User.Claims;
+ string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
+ int userId = Convert.ToInt32(userIdString);
+ return await _shoppingListLogic.DeleteItemInShoppingList(userId, itemId);
+ }
+
+ [HttpPost("recipeadd")]
+ public async Task AddARecipesItems(int recipeId)
+ {
+ var claims = HttpContext.User.Claims;
+ string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
+ int userId = Convert.ToInt32(userIdString);
+ return await _shoppingListLogic.AddRecipeToShoppingList(userId, recipeId);
+ }
+ }
+}
diff --git a/backend/API/DBAccess/DBContext.cs b/backend/API/DBAccess/DBContext.cs
index 04c124e..f335651 100644
--- a/backend/API/DBAccess/DBContext.cs
+++ b/backend/API/DBAccess/DBContext.cs
@@ -1,4 +1,5 @@
using API.Models.RecipeModels;
+using API.Models.ShoppingListModels;
using API.Models.UserModels;
using Microsoft.EntityFrameworkCore;
@@ -12,6 +13,8 @@ namespace API.DBAccess
public DbSet Recipes { get; set; }
+ public DbSet ShoppingList { get; set; }
+
public DBContext(DbContextOptions options) : base(options) { }
}
}
diff --git a/backend/API/DBAccess/RecipeDBaccess.cs b/backend/API/DBAccess/RecipeDBaccess.cs
new file mode 100644
index 0000000..7c276a3
--- /dev/null
+++ b/backend/API/DBAccess/RecipeDBaccess.cs
@@ -0,0 +1,79 @@
+using API.Models.RecipeModels;
+using API.Models.UserModels;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+
+namespace API.DBAccess
+{
+ public class RecipeDBAccess
+ {
+ private readonly DBContext _context;
+
+ public RecipeDBAccess(DBContext context)
+ {
+ _context = context;
+ }
+
+ public async Task ReadPrefereredRecipes(int userId)
+ {
+ var recipes = await _context.Users.Include(u => u.PrefereredRecipes).ThenInclude(p => p.Recipes).FirstOrDefaultAsync(u => u.Id == userId);
+
+ return recipes.PrefereredRecipes;
+ }
+
+ public async Task ReadAllRecipe(int prefereredRecipesId)
+ {
+ return await _context.PrefereredRecipes.Include(p => p.Recipes).FirstOrDefaultAsync(r => r.Id == prefereredRecipesId);
+ }
+
+ public async Task ReadRecipe(int recipeId)
+ {
+ return await _context.Recipes.Include(r => r.Ingredients).FirstOrDefaultAsync(r => r.Id == recipeId);
+ }
+
+ public async Task CreateMissingLists(int userId)
+ {
+ var user = await _context.Users.FirstOrDefaultAsync(u => u.Id == userId);
+ user.PrefereredRecipes = new PrefereredRecipes();
+ user.PrefereredRecipes.Recipes = new List();
+
+ _context.SaveChangesAsync();
+
+ return await ReadPrefereredRecipes(userId);
+ }
+
+ public async Task CreateRecipe(Recipe recipe, int prefereredRecipeId)
+ {
+ var recipes = await _context.PrefereredRecipes.Include(p => p.Recipes).FirstOrDefaultAsync(p => p.Id == prefereredRecipeId);
+
+ recipes.Recipes.Add(recipe);
+
+ bool saved = await _context.SaveChangesAsync() > 1;
+
+ if (saved) { return new OkObjectResult(saved); }
+
+ return new ConflictObjectResult(new { message = "Could not save to database" });
+ }
+
+ public async Task UpdateRecipe(Recipe recipe)
+ {
+ _context.Entry(recipe).State = EntityState.Modified;
+
+ bool saved = await _context.SaveChangesAsync() >= 1;
+
+ if (saved) { return new OkObjectResult(recipe); }
+
+ return new ConflictObjectResult(new { message = "Could not save to database" });
+ }
+
+ public async Task DeleteUser(Recipe recipe)
+ {
+ _context.Recipes.Remove(recipe);
+ bool saved = await _context.SaveChangesAsync() >= 0;
+
+ if (saved) { return new OkObjectResult(saved); }
+
+ return new ConflictObjectResult(new { message = "Could not save to database" });
+ }
+ }
+}
diff --git a/backend/API/DBAccess/ShoppingListDBAccess.cs b/backend/API/DBAccess/ShoppingListDBAccess.cs
new file mode 100644
index 0000000..f77069d
--- /dev/null
+++ b/backend/API/DBAccess/ShoppingListDBAccess.cs
@@ -0,0 +1,35 @@
+using API.Models.RecipeModels;
+using API.Models.ShoppingListModels;
+using API.Models.UserModels;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+
+namespace API.DBAccess
+{
+ public class ShoppingListDBAccess
+ {
+ private readonly DBContext _context;
+
+ public ShoppingListDBAccess(DBContext context)
+ {
+ _context = context;
+ }
+ public async Task ReadShoppingList(int userId)
+ {
+ var user = await _context.Users.Include(u => u.ShoppingList).FirstOrDefaultAsync(u => u.Id == userId);
+
+ return user;
+ }
+
+ public async Task UpdateShoppingList(User user)
+ {
+ _context.Entry(user).State = EntityState.Modified;
+
+ bool saved = await _context.SaveChangesAsync() >= 1;
+
+ if (saved) { return new OkObjectResult(user); }
+
+ return new ConflictObjectResult(new { message = "Could not save to database" });
+ }
+ }
+}
diff --git a/backend/API/DBAccess/DbAccess.cs b/backend/API/DBAccess/UserDBAccess.cs
similarity index 94%
rename from backend/API/DBAccess/DbAccess.cs
rename to backend/API/DBAccess/UserDBAccess.cs
index f994c5a..dfbc59e 100644
--- a/backend/API/DBAccess/DbAccess.cs
+++ b/backend/API/DBAccess/UserDBAccess.cs
@@ -4,11 +4,11 @@ using Microsoft.EntityFrameworkCore;
namespace API.DBAccess
{
- public class DbAccess
+ public class UserDBAccess
{
private readonly DBContext _context;
- public DbAccess(DBContext context)
+ public UserDBAccess(DBContext context)
{
_context = context;
}
@@ -49,7 +49,7 @@ namespace API.DBAccess
{
_context.Users.Add(user);
- bool saved = await _context.SaveChangesAsync() == 1;
+ bool saved = await _context.SaveChangesAsync() >= 1;
if (saved) { return new OkObjectResult(true); }
@@ -66,7 +66,6 @@ namespace API.DBAccess
if (saved) { return new OkObjectResult(user); }
return new ConflictObjectResult(new { message = "Could not save to database" });
-
}
public async Task UpdatePassword(User user)
diff --git a/backend/API/Migrations/20250428070005_RecipeModelAdded.cs b/backend/API/Migrations/20250428070005_RecipeModelAdded.cs
deleted file mode 100644
index afe234c..0000000
--- a/backend/API/Migrations/20250428070005_RecipeModelAdded.cs
+++ /dev/null
@@ -1,127 +0,0 @@
-using Microsoft.EntityFrameworkCore.Migrations;
-using MySql.EntityFrameworkCore.Metadata;
-
-#nullable disable
-
-namespace API.Migrations
-{
- ///
- public partial class RecipeModelAdded : Migration
- {
- ///
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.AddColumn(
- name: "PrefereredRecipesId",
- table: "Users",
- type: "int",
- nullable: false,
- defaultValue: 0);
-
- migrationBuilder.CreateTable(
- name: "PrefereredRecipes",
- columns: table => new
- {
- Id = table.Column(type: "int", nullable: false)
- .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_PrefereredRecipes", x => x.Id);
- })
- .Annotation("MySQL:Charset", "utf8mb4");
-
- migrationBuilder.CreateTable(
- name: "Recipes",
- columns: table => new
- {
- Id = table.Column(type: "int", nullable: false)
- .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
- Name = table.Column(type: "longtext", nullable: false),
- Description = table.Column(type: "longtext", nullable: false),
- Directions = table.Column(type: "longtext", nullable: false),
- PrefereredRecipesId = table.Column(type: "int", nullable: true)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Recipes", x => x.Id);
- table.ForeignKey(
- name: "FK_Recipes_PrefereredRecipes_PrefereredRecipesId",
- column: x => x.PrefereredRecipesId,
- principalTable: "PrefereredRecipes",
- principalColumn: "Id");
- })
- .Annotation("MySQL:Charset", "utf8mb4");
-
- migrationBuilder.CreateTable(
- name: "Ingredient",
- columns: table => new
- {
- Id = table.Column(type: "int", nullable: false)
- .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
- Amount = table.Column(type: "int", nullable: false),
- Unit = table.Column(type: "longtext", nullable: false),
- Element = table.Column(type: "longtext", nullable: false),
- RecipeId = table.Column(type: "int", nullable: true)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Ingredient", x => x.Id);
- table.ForeignKey(
- name: "FK_Ingredient_Recipes_RecipeId",
- column: x => x.RecipeId,
- principalTable: "Recipes",
- principalColumn: "Id");
- })
- .Annotation("MySQL:Charset", "utf8mb4");
-
- migrationBuilder.CreateIndex(
- name: "IX_Users_PrefereredRecipesId",
- table: "Users",
- column: "PrefereredRecipesId");
-
- migrationBuilder.CreateIndex(
- name: "IX_Ingredient_RecipeId",
- table: "Ingredient",
- column: "RecipeId");
-
- migrationBuilder.CreateIndex(
- name: "IX_Recipes_PrefereredRecipesId",
- table: "Recipes",
- column: "PrefereredRecipesId");
-
- migrationBuilder.AddForeignKey(
- name: "FK_Users_PrefereredRecipes_PrefereredRecipesId",
- table: "Users",
- column: "PrefereredRecipesId",
- principalTable: "PrefereredRecipes",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
- }
-
- ///
- protected override void Down(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.DropForeignKey(
- name: "FK_Users_PrefereredRecipes_PrefereredRecipesId",
- table: "Users");
-
- migrationBuilder.DropTable(
- name: "Ingredient");
-
- migrationBuilder.DropTable(
- name: "Recipes");
-
- migrationBuilder.DropTable(
- name: "PrefereredRecipes");
-
- migrationBuilder.DropIndex(
- name: "IX_Users_PrefereredRecipesId",
- table: "Users");
-
- migrationBuilder.DropColumn(
- name: "PrefereredRecipesId",
- table: "Users");
- }
- }
-}
diff --git a/backend/API/Migrations/20250428070005_RecipeModelAdded.Designer.cs b/backend/API/Migrations/20250429115336_RecipeModelAdded.Designer.cs
similarity index 63%
rename from backend/API/Migrations/20250428070005_RecipeModelAdded.Designer.cs
rename to backend/API/Migrations/20250429115336_RecipeModelAdded.Designer.cs
index b851f33..48ed828 100644
--- a/backend/API/Migrations/20250428070005_RecipeModelAdded.Designer.cs
+++ b/backend/API/Migrations/20250429115336_RecipeModelAdded.Designer.cs
@@ -11,36 +11,34 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace API.Migrations
{
[DbContext(typeof(DBContext))]
- [Migration("20250428070005_RecipeModelAdded")]
+ [Migration("20250429115336_RecipeModelAdded")]
partial class RecipeModelAdded
{
///
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
- modelBuilder
- .HasAnnotation("ProductVersion", "8.0.10")
- .HasAnnotation("Relational:MaxIdentifierLength", 64);
+ modelBuilder.HasAnnotation("ProductVersion", "8.0.10");
modelBuilder.Entity("API.Models.RecipeModels.Ingredient", b =>
{
b.Property("Id")
.ValueGeneratedOnAdd()
- .HasColumnType("int");
+ .HasColumnType("INTEGER");
b.Property("Amount")
- .HasColumnType("int");
+ .HasColumnType("INTEGER");
b.Property("Element")
.IsRequired()
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.Property("RecipeId")
- .HasColumnType("int");
+ .HasColumnType("INTEGER");
b.Property("Unit")
.IsRequired()
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.HasKey("Id");
@@ -53,7 +51,7 @@ namespace API.Migrations
{
b.Property("Id")
.ValueGeneratedOnAdd()
- .HasColumnType("int");
+ .HasColumnType("INTEGER");
b.HasKey("Id");
@@ -64,22 +62,22 @@ namespace API.Migrations
{
b.Property("Id")
.ValueGeneratedOnAdd()
- .HasColumnType("int");
+ .HasColumnType("INTEGER");
b.Property("Description")
.IsRequired()
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.Property("Directions")
.IsRequired()
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.Property("Name")
.IsRequired()
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.Property("PrefereredRecipesId")
- .HasColumnType("int");
+ .HasColumnType("INTEGER");
b.HasKey("Id");
@@ -88,35 +86,65 @@ namespace API.Migrations
b.ToTable("Recipes");
});
+ modelBuilder.Entity("API.Models.ShoppingListModels.ShoppingList", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("Amount")
+ .HasColumnType("REAL");
+
+ b.Property("Checked")
+ .HasColumnType("INTEGER");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Unit")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("UserId")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("ShoppingList");
+ });
+
modelBuilder.Entity("API.Models.UserModels.User", b =>
{
b.Property("Id")
.ValueGeneratedOnAdd()
- .HasColumnType("int");
+ .HasColumnType("INTEGER");
b.Property("Email")
.IsRequired()
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.Property("Password")
.IsRequired()
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.Property("PrefereredRecipesId")
- .HasColumnType("int");
+ .HasColumnType("INTEGER");
b.Property("RefreshToken")
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.Property("RefreshTokenExpireAt")
- .HasColumnType("datetime(6)");
+ .HasColumnType("TEXT");
b.Property("Salt")
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.Property("UserName")
.IsRequired()
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.HasKey("Id");
@@ -139,6 +167,13 @@ namespace API.Migrations
.HasForeignKey("PrefereredRecipesId");
});
+ modelBuilder.Entity("API.Models.ShoppingListModels.ShoppingList", b =>
+ {
+ b.HasOne("API.Models.UserModels.User", null)
+ .WithMany("ShoppingList")
+ .HasForeignKey("UserId");
+ });
+
modelBuilder.Entity("API.Models.UserModels.User", b =>
{
b.HasOne("API.Models.RecipeModels.PrefereredRecipes", "PrefereredRecipes")
@@ -159,6 +194,11 @@ namespace API.Migrations
{
b.Navigation("Ingredients");
});
+
+ modelBuilder.Entity("API.Models.UserModels.User", b =>
+ {
+ b.Navigation("ShoppingList");
+ });
#pragma warning restore 612, 618
}
}
diff --git a/backend/API/Migrations/20250429115336_RecipeModelAdded.cs b/backend/API/Migrations/20250429115336_RecipeModelAdded.cs
new file mode 100644
index 0000000..907b867
--- /dev/null
+++ b/backend/API/Migrations/20250429115336_RecipeModelAdded.cs
@@ -0,0 +1,274 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace API.Migrations
+{
+ ///
+ public partial class RecipeModelAdded : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AlterColumn(
+ name: "UserName",
+ table: "Users",
+ type: "TEXT",
+ nullable: false,
+ oldClrType: typeof(string),
+ oldType: "longtext");
+
+ migrationBuilder.AlterColumn(
+ name: "Salt",
+ table: "Users",
+ type: "TEXT",
+ nullable: true,
+ oldClrType: typeof(string),
+ oldType: "longtext",
+ oldNullable: true);
+
+ migrationBuilder.AlterColumn(
+ name: "RefreshTokenExpireAt",
+ table: "Users",
+ type: "TEXT",
+ nullable: false,
+ oldClrType: typeof(DateTime),
+ oldType: "datetime(6)");
+
+ migrationBuilder.AlterColumn(
+ name: "RefreshToken",
+ table: "Users",
+ type: "TEXT",
+ nullable: true,
+ oldClrType: typeof(string),
+ oldType: "longtext",
+ oldNullable: true);
+
+ migrationBuilder.AlterColumn(
+ name: "Password",
+ table: "Users",
+ type: "TEXT",
+ nullable: false,
+ oldClrType: typeof(string),
+ oldType: "longtext");
+
+ migrationBuilder.AlterColumn(
+ name: "Email",
+ table: "Users",
+ type: "TEXT",
+ nullable: false,
+ oldClrType: typeof(string),
+ oldType: "longtext");
+
+ migrationBuilder.AlterColumn(
+ name: "Id",
+ table: "Users",
+ type: "INTEGER",
+ nullable: false,
+ oldClrType: typeof(int),
+ oldType: "int")
+ .Annotation("Sqlite:Autoincrement", true)
+ .OldAnnotation("Sqlite:Autoincrement", true);
+
+ migrationBuilder.AddColumn(
+ name: "PrefereredRecipesId",
+ table: "Users",
+ type: "INTEGER",
+ nullable: false,
+ defaultValue: 0);
+
+ migrationBuilder.CreateTable(
+ name: "PrefereredRecipes",
+ columns: table => new
+ {
+ Id = table.Column(type: "INTEGER", nullable: false)
+ .Annotation("Sqlite:Autoincrement", true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_PrefereredRecipes", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "ShoppingList",
+ columns: table => new
+ {
+ Id = table.Column(type: "INTEGER", nullable: false)
+ .Annotation("Sqlite:Autoincrement", true),
+ Amount = table.Column(type: "REAL", nullable: false),
+ Unit = table.Column(type: "TEXT", nullable: false),
+ Name = table.Column(type: "TEXT", nullable: false),
+ Checked = table.Column(type: "INTEGER", nullable: false),
+ UserId = table.Column(type: "INTEGER", nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_ShoppingList", x => x.Id);
+ table.ForeignKey(
+ name: "FK_ShoppingList_Users_UserId",
+ column: x => x.UserId,
+ principalTable: "Users",
+ principalColumn: "Id");
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Recipes",
+ columns: table => new
+ {
+ Id = table.Column(type: "INTEGER", nullable: false)
+ .Annotation("Sqlite:Autoincrement", true),
+ Name = table.Column(type: "TEXT", nullable: false),
+ Description = table.Column(type: "TEXT", nullable: false),
+ Directions = table.Column(type: "TEXT", nullable: false),
+ PrefereredRecipesId = table.Column(type: "INTEGER", nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Recipes", x => x.Id);
+ table.ForeignKey(
+ name: "FK_Recipes_PrefereredRecipes_PrefereredRecipesId",
+ column: x => x.PrefereredRecipesId,
+ principalTable: "PrefereredRecipes",
+ principalColumn: "Id");
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Ingredient",
+ columns: table => new
+ {
+ Id = table.Column(type: "INTEGER", nullable: false)
+ .Annotation("Sqlite:Autoincrement", true),
+ Amount = table.Column(type: "INTEGER", nullable: false),
+ Unit = table.Column(type: "TEXT", nullable: false),
+ Element = table.Column(type: "TEXT", nullable: false),
+ RecipeId = table.Column(type: "INTEGER", nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Ingredient", x => x.Id);
+ table.ForeignKey(
+ name: "FK_Ingredient_Recipes_RecipeId",
+ column: x => x.RecipeId,
+ principalTable: "Recipes",
+ principalColumn: "Id");
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Users_PrefereredRecipesId",
+ table: "Users",
+ column: "PrefereredRecipesId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Ingredient_RecipeId",
+ table: "Ingredient",
+ column: "RecipeId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Recipes_PrefereredRecipesId",
+ table: "Recipes",
+ column: "PrefereredRecipesId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_ShoppingList_UserId",
+ table: "ShoppingList",
+ column: "UserId");
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_Users_PrefereredRecipes_PrefereredRecipesId",
+ table: "Users",
+ column: "PrefereredRecipesId",
+ principalTable: "PrefereredRecipes",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_Users_PrefereredRecipes_PrefereredRecipesId",
+ table: "Users");
+
+ migrationBuilder.DropTable(
+ name: "Ingredient");
+
+ migrationBuilder.DropTable(
+ name: "ShoppingList");
+
+ migrationBuilder.DropTable(
+ name: "Recipes");
+
+ migrationBuilder.DropTable(
+ name: "PrefereredRecipes");
+
+ migrationBuilder.DropIndex(
+ name: "IX_Users_PrefereredRecipesId",
+ table: "Users");
+
+ migrationBuilder.DropColumn(
+ name: "PrefereredRecipesId",
+ table: "Users");
+
+ migrationBuilder.AlterColumn(
+ name: "UserName",
+ table: "Users",
+ type: "longtext",
+ nullable: false,
+ oldClrType: typeof(string),
+ oldType: "TEXT");
+
+ migrationBuilder.AlterColumn(
+ name: "Salt",
+ table: "Users",
+ type: "longtext",
+ nullable: true,
+ oldClrType: typeof(string),
+ oldType: "TEXT",
+ oldNullable: true);
+
+ migrationBuilder.AlterColumn(
+ name: "RefreshTokenExpireAt",
+ table: "Users",
+ type: "datetime(6)",
+ nullable: false,
+ oldClrType: typeof(DateTime),
+ oldType: "TEXT");
+
+ migrationBuilder.AlterColumn(
+ name: "RefreshToken",
+ table: "Users",
+ type: "longtext",
+ nullable: true,
+ oldClrType: typeof(string),
+ oldType: "TEXT",
+ oldNullable: true);
+
+ migrationBuilder.AlterColumn(
+ name: "Password",
+ table: "Users",
+ type: "longtext",
+ nullable: false,
+ oldClrType: typeof(string),
+ oldType: "TEXT");
+
+ migrationBuilder.AlterColumn(
+ name: "Email",
+ table: "Users",
+ type: "longtext",
+ nullable: false,
+ oldClrType: typeof(string),
+ oldType: "TEXT");
+
+ migrationBuilder.AlterColumn(
+ name: "Id",
+ table: "Users",
+ type: "int",
+ nullable: false,
+ oldClrType: typeof(int),
+ oldType: "INTEGER")
+ .Annotation("Sqlite:Autoincrement", true)
+ .OldAnnotation("Sqlite:Autoincrement", true);
+ }
+ }
+}
diff --git a/backend/API/Migrations/DBContextModelSnapshot.cs b/backend/API/Migrations/DBContextModelSnapshot.cs
index f11e5a4..1366ca7 100644
--- a/backend/API/Migrations/DBContextModelSnapshot.cs
+++ b/backend/API/Migrations/DBContextModelSnapshot.cs
@@ -15,29 +15,27 @@ namespace API.Migrations
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
- modelBuilder
- .HasAnnotation("ProductVersion", "8.0.10")
- .HasAnnotation("Relational:MaxIdentifierLength", 64);
+ modelBuilder.HasAnnotation("ProductVersion", "8.0.10");
modelBuilder.Entity("API.Models.RecipeModels.Ingredient", b =>
{
b.Property("Id")
.ValueGeneratedOnAdd()
- .HasColumnType("int");
+ .HasColumnType("INTEGER");
b.Property("Amount")
- .HasColumnType("int");
+ .HasColumnType("INTEGER");
b.Property("Element")
.IsRequired()
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.Property("RecipeId")
- .HasColumnType("int");
+ .HasColumnType("INTEGER");
b.Property("Unit")
.IsRequired()
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.HasKey("Id");
@@ -50,7 +48,7 @@ namespace API.Migrations
{
b.Property("Id")
.ValueGeneratedOnAdd()
- .HasColumnType("int");
+ .HasColumnType("INTEGER");
b.HasKey("Id");
@@ -61,22 +59,22 @@ namespace API.Migrations
{
b.Property("Id")
.ValueGeneratedOnAdd()
- .HasColumnType("int");
+ .HasColumnType("INTEGER");
b.Property("Description")
.IsRequired()
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.Property("Directions")
.IsRequired()
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.Property("Name")
.IsRequired()
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.Property("PrefereredRecipesId")
- .HasColumnType("int");
+ .HasColumnType("INTEGER");
b.HasKey("Id");
@@ -85,35 +83,65 @@ namespace API.Migrations
b.ToTable("Recipes");
});
+ modelBuilder.Entity("API.Models.ShoppingListModels.ShoppingList", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("Amount")
+ .HasColumnType("REAL");
+
+ b.Property("Checked")
+ .HasColumnType("INTEGER");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Unit")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("UserId")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("ShoppingList");
+ });
+
modelBuilder.Entity("API.Models.UserModels.User", b =>
{
b.Property("Id")
.ValueGeneratedOnAdd()
- .HasColumnType("int");
+ .HasColumnType("INTEGER");
b.Property("Email")
.IsRequired()
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.Property("Password")
.IsRequired()
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.Property("PrefereredRecipesId")
- .HasColumnType("int");
+ .HasColumnType("INTEGER");
b.Property("RefreshToken")
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.Property("RefreshTokenExpireAt")
- .HasColumnType("datetime(6)");
+ .HasColumnType("TEXT");
b.Property("Salt")
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.Property("UserName")
.IsRequired()
- .HasColumnType("longtext");
+ .HasColumnType("TEXT");
b.HasKey("Id");
@@ -136,6 +164,13 @@ namespace API.Migrations
.HasForeignKey("PrefereredRecipesId");
});
+ modelBuilder.Entity("API.Models.ShoppingListModels.ShoppingList", b =>
+ {
+ b.HasOne("API.Models.UserModels.User", null)
+ .WithMany("ShoppingList")
+ .HasForeignKey("UserId");
+ });
+
modelBuilder.Entity("API.Models.UserModels.User", b =>
{
b.HasOne("API.Models.RecipeModels.PrefereredRecipes", "PrefereredRecipes")
@@ -156,6 +191,11 @@ namespace API.Migrations
{
b.Navigation("Ingredients");
});
+
+ modelBuilder.Entity("API.Models.UserModels.User", b =>
+ {
+ b.Navigation("ShoppingList");
+ });
#pragma warning restore 612, 618
}
}
diff --git a/backend/API/Models/RecipeModels/IngredientDTO.cs b/backend/API/Models/RecipeModels/IngredientDTO.cs
new file mode 100644
index 0000000..b85d789
--- /dev/null
+++ b/backend/API/Models/RecipeModels/IngredientDTO.cs
@@ -0,0 +1,11 @@
+namespace API.Models.RecipeModels
+{
+ public class IngredientDTO
+ {
+ public int Amount { get; set; }
+
+ public string Unit { get; set; }
+
+ public string Element { get; set; }
+ }
+}
diff --git a/backend/API/Models/RecipeModels/PrefereredRecipesDTO.cs b/backend/API/Models/RecipeModels/PrefereredRecipesDTO.cs
new file mode 100644
index 0000000..16ea538
--- /dev/null
+++ b/backend/API/Models/RecipeModels/PrefereredRecipesDTO.cs
@@ -0,0 +1,7 @@
+namespace API.Models.RecipeModels
+{
+ public class PrefereredRecipesDTO
+ {
+ public List Recipes { get; set; }
+ }
+}
diff --git a/backend/API/Models/RecipeModels/RecipeDTO.cs b/backend/API/Models/RecipeModels/RecipeDTO.cs
new file mode 100644
index 0000000..0f27cdb
--- /dev/null
+++ b/backend/API/Models/RecipeModels/RecipeDTO.cs
@@ -0,0 +1,13 @@
+namespace API.Models.RecipeModels
+{
+ public class RecipeDTO
+ {
+ public string Name { get; set; }
+
+ public string Description { get; set; }
+
+ public string Directions { get; set; }
+
+ public List Ingredients { get; set; }
+ }
+}
diff --git a/backend/API/Models/ShoppingListModels/ShoppingList.cs b/backend/API/Models/ShoppingListModels/ShoppingList.cs
new file mode 100644
index 0000000..a2c206a
--- /dev/null
+++ b/backend/API/Models/ShoppingListModels/ShoppingList.cs
@@ -0,0 +1,15 @@
+namespace API.Models.ShoppingListModels
+{
+ public class ShoppingList
+ {
+ public int Id { get; set; }
+
+ public double Amount { get; set; }
+
+ public string Unit { get; set; }
+
+ public string Name { get; set; }
+
+ public bool Checked { get; set; }
+ }
+}
diff --git a/backend/API/Models/ShoppingListModels/ShoppingListItemDTO.cs b/backend/API/Models/ShoppingListModels/ShoppingListItemDTO.cs
new file mode 100644
index 0000000..4b1959e
--- /dev/null
+++ b/backend/API/Models/ShoppingListModels/ShoppingListItemDTO.cs
@@ -0,0 +1,14 @@
+namespace API.Models.ShoppingListModels
+{
+ public class ShoppingListItemDTO
+ {
+
+ public string Name { get; set; }
+
+ public double Amount { get; set; }
+
+ public string Unit { get; set; }
+
+ public bool Checked { get; set; }
+ }
+}
diff --git a/backend/API/Models/UserModels/User.cs b/backend/API/Models/UserModels/User.cs
index e81b231..abca1fa 100644
--- a/backend/API/Models/UserModels/User.cs
+++ b/backend/API/Models/UserModels/User.cs
@@ -1,4 +1,5 @@
using API.Models.RecipeModels;
+using API.Models.ShoppingListModels;
namespace API.Models.UserModels
{
@@ -19,5 +20,7 @@ namespace API.Models.UserModels
public DateTime RefreshTokenExpireAt { get; set; }
public PrefereredRecipes PrefereredRecipes { get; set; }
+
+ public List ShoppingList { get; set; }
}
}
diff --git a/backend/API/Startup.cs b/backend/API/Startup.cs
index c0d4f97..7b0dd60 100644
--- a/backend/API/Startup.cs
+++ b/backend/API/Startup.cs
@@ -25,8 +25,10 @@ namespace API
services.AddDbContext(options =>
options.UseMySQL(_configuration.GetConnectionString("Database")));
- services.AddScoped();
+ services.AddScoped();
services.AddScoped();
+ services.AddScoped();
+ services.AddScoped();
services.AddControllers();