Merge branch 'master' into api-connection
This commit is contained in:
commit
0f791cc642
3
.gitignore
vendored
3
.gitignore
vendored
@ -6,3 +6,6 @@
|
|||||||
/backend/API/appsettings.Development.json
|
/backend/API/appsettings.Development.json
|
||||||
/backend/API/appsettings.json
|
/backend/API/appsettings.json
|
||||||
*bin
|
*bin
|
||||||
|
/backend/API/database.sqlite3
|
||||||
|
/backend/API/database.sqlite3-shm
|
||||||
|
/backend/API/database.sqlite3-wal
|
||||||
|
@ -1,25 +1,42 @@
|
|||||||
package tech.mercantec.easyeat
|
package tech.mercantec.easyeat
|
||||||
|
|
||||||
import android.os.Bundle
|
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.app.AppCompatActivity
|
||||||
import androidx.appcompat.widget.Toolbar
|
|
||||||
|
|
||||||
class CreateDishActivity : AppCompatActivity() {
|
class CreateDishActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
private lateinit var ingredientContainer: LinearLayout
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_create_dish_form)
|
setContentView(R.layout.activity_create_dish_form)
|
||||||
|
|
||||||
// Setup the Toolbar as ActionBar
|
ingredientContainer = findViewById(R.id.ingredientContainer)
|
||||||
val toolbar: Toolbar = findViewById(R.id.toolbar)
|
val addButton: Button = findViewById(R.id.addIngredientButton)
|
||||||
setSupportActionBar(toolbar)
|
|
||||||
|
|
||||||
// Enable the Up button
|
// Add the first ingredient row manually at startup
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
addIngredientRow()
|
||||||
|
|
||||||
|
// Set up button to add new rows
|
||||||
|
addButton.setOnClickListener {
|
||||||
|
addIngredientRow()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle the Up button click
|
private fun addIngredientRow() {
|
||||||
override fun onSupportNavigateUp(): Boolean {
|
val inflater = LayoutInflater.from(this)
|
||||||
onBackPressedDispatcher.onBackPressed()
|
val ingredientRow = inflater.inflate(R.layout.activity_create_dish_ingredient_row, null)
|
||||||
return true
|
|
||||||
|
// Handle remove button in each row
|
||||||
|
val removeButton: Button = ingredientRow.findViewById(R.id.removeButton)
|
||||||
|
removeButton.setOnClickListener {
|
||||||
|
ingredientContainer.removeView(ingredientRow)
|
||||||
|
}
|
||||||
|
|
||||||
|
ingredientContainer.addView(ingredientRow)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,6 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="16dp">
|
android:padding="16dp">
|
||||||
|
|
||||||
<androidx.appcompat.widget.Toolbar
|
|
||||||
android:id="@+id/toolbar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:title="Create Dish"
|
|
||||||
/>
|
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -21,8 +13,12 @@
|
|||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
android:textSize="24sp" />
|
android:textSize="24sp" />
|
||||||
|
|
||||||
<include
|
<!-- Container for all ingredient rows -->
|
||||||
layout="@layout/activity_create_dish_ingredient_row" />
|
<LinearLayout
|
||||||
|
android:id="@+id/ingredientContainer"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/addIngredientButton"
|
android:id="@+id/addIngredientButton"
|
||||||
@ -32,3 +28,4 @@
|
|||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
android:layout_marginTop="16dp"/>
|
android:layout_marginTop="16dp"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.10" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
100
backend/API/BusinessLogic/RecipeLogic.cs
Normal file
100
backend/API/BusinessLogic/RecipeLogic.cs
Normal file
@ -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<IActionResult> 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<IActionResult> 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<IActionResult> 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<Ingredient>();
|
||||||
|
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<IActionResult> 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<IActionResult> DeleteRecipe(int recipeId)
|
||||||
|
{
|
||||||
|
var recipe = await _dbAccess.ReadRecipe(recipeId);
|
||||||
|
|
||||||
|
if (recipe != null) { return await _dbAccess.DeleteUser(recipe); }
|
||||||
|
|
||||||
|
return new ConflictObjectResult(new { message = "Invalid user" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
209
backend/API/BusinessLogic/ShoppingListLogic.cs
Normal file
209
backend/API/BusinessLogic/ShoppingListLogic.cs
Normal file
@ -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<IActionResult> ReadShoppingList(int userId)
|
||||||
|
{
|
||||||
|
var user = await _dbAccess.ReadShoppingList(userId);
|
||||||
|
|
||||||
|
return new OkObjectResult(user.ShoppingList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> AddItemToShoppingList(ShoppingListItemDTO listItemDTO, int userId)
|
||||||
|
{
|
||||||
|
var user = await _dbAccess.ReadShoppingList(userId);
|
||||||
|
|
||||||
|
List<ShoppingList> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +1,23 @@
|
|||||||
using API.DBAccess;
|
using API.DBAccess;
|
||||||
using API.Models.UserModels;
|
using API.Models.UserModels;
|
||||||
|
using API.Models.RecipeModels;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using Org.BouncyCastle.Asn1.Ocsp;
|
|
||||||
using System.IdentityModel.Tokens.Jwt;
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using API.Models.ShoppingListModels;
|
||||||
|
|
||||||
namespace API.BusinessLogic
|
namespace API.BusinessLogic
|
||||||
{
|
{
|
||||||
public class UserLogic
|
public class UserLogic
|
||||||
{
|
{
|
||||||
private readonly DbAccess _dbAccess;
|
private readonly UserDBAccess _dbAccess;
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
|
|
||||||
public UserLogic(IConfiguration configuration, DbAccess dbAccess)
|
public UserLogic(IConfiguration configuration, UserDBAccess dbAccess)
|
||||||
{
|
{
|
||||||
_dbAccess = dbAccess;
|
_dbAccess = dbAccess;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
@ -60,12 +61,17 @@ namespace API.BusinessLogic
|
|||||||
string salt = Guid.NewGuid().ToString();
|
string salt = Guid.NewGuid().ToString();
|
||||||
string hashedPassword = ComputeHash(userDTO.Password, SHA256.Create(), salt);
|
string hashedPassword = ComputeHash(userDTO.Password, SHA256.Create(), salt);
|
||||||
|
|
||||||
|
PrefereredRecipes recipes = new PrefereredRecipes();
|
||||||
|
recipes.Recipes = new List<Recipe>();
|
||||||
|
|
||||||
User user = new User
|
User user = new User
|
||||||
{
|
{
|
||||||
UserName = userDTO.UserName,
|
UserName = userDTO.UserName,
|
||||||
Email = userDTO.Email,
|
Email = userDTO.Email,
|
||||||
Password = hashedPassword,
|
Password = hashedPassword,
|
||||||
Salt = salt,
|
Salt = salt,
|
||||||
|
PrefereredRecipes = recipes,
|
||||||
|
ShoppingList = new List<ShoppingList>(),
|
||||||
};
|
};
|
||||||
|
|
||||||
return await _dbAccess.CreateUser(user);
|
return await _dbAccess.CreateUser(user);
|
||||||
|
61
backend/API/Controllers/RecipeController.cs
Normal file
61
backend/API/Controllers/RecipeController.cs
Normal file
@ -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<IActionResult> 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<IActionResult> ReadRecipe(int recipeId)
|
||||||
|
{
|
||||||
|
return await _recipeLogic.GetRecipe(recipeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[HttpPost("create/{prefereredRecipesId}")]
|
||||||
|
public async Task<IActionResult> CreateRecipe([FromBody] RecipeDTO recipe, int prefereredRecipesId)
|
||||||
|
{
|
||||||
|
return await _recipeLogic.CreateRecipe(recipe, prefereredRecipesId);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[HttpPut("edit/{recipeId}")]
|
||||||
|
public async Task<IActionResult> 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<IActionResult> DeleteRecipe(int recipeId)
|
||||||
|
{
|
||||||
|
return await _recipeLogic.DeleteRecipe(recipeId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
74
backend/API/Controllers/ShoppingListController.cs
Normal file
74
backend/API/Controllers/ShoppingListController.cs
Normal file
@ -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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using API.Models.RecipeModels;
|
using API.Models.RecipeModels;
|
||||||
|
using API.Models.ShoppingListModels;
|
||||||
using API.Models.UserModels;
|
using API.Models.UserModels;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
@ -12,6 +13,8 @@ namespace API.DBAccess
|
|||||||
|
|
||||||
public DbSet<Recipe> Recipes { get; set; }
|
public DbSet<Recipe> Recipes { get; set; }
|
||||||
|
|
||||||
|
public DbSet<ShoppingList> ShoppingList { get; set; }
|
||||||
|
|
||||||
public DBContext(DbContextOptions<DBContext> options) : base(options) { }
|
public DBContext(DbContextOptions<DBContext> options) : base(options) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
79
backend/API/DBAccess/RecipeDBaccess.cs
Normal file
79
backend/API/DBAccess/RecipeDBaccess.cs
Normal file
@ -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<PrefereredRecipes> 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<PrefereredRecipes> ReadAllRecipe(int prefereredRecipesId)
|
||||||
|
{
|
||||||
|
return await _context.PrefereredRecipes.Include(p => p.Recipes).FirstOrDefaultAsync(r => r.Id == prefereredRecipesId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Recipe> ReadRecipe(int recipeId)
|
||||||
|
{
|
||||||
|
return await _context.Recipes.Include(r => r.Ingredients).FirstOrDefaultAsync(r => r.Id == recipeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<PrefereredRecipes> CreateMissingLists(int userId)
|
||||||
|
{
|
||||||
|
var user = await _context.Users.FirstOrDefaultAsync(u => u.Id == userId);
|
||||||
|
user.PrefereredRecipes = new PrefereredRecipes();
|
||||||
|
user.PrefereredRecipes.Recipes = new List<Recipe>();
|
||||||
|
|
||||||
|
_context.SaveChangesAsync();
|
||||||
|
|
||||||
|
return await ReadPrefereredRecipes(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> 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<IActionResult> 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<IActionResult> 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" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
35
backend/API/DBAccess/ShoppingListDBAccess.cs
Normal file
35
backend/API/DBAccess/ShoppingListDBAccess.cs
Normal file
@ -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<User> ReadShoppingList(int userId)
|
||||||
|
{
|
||||||
|
var user = await _context.Users.Include(u => u.ShoppingList).FirstOrDefaultAsync(u => u.Id == userId);
|
||||||
|
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> 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" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,11 +4,11 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
|
|
||||||
namespace API.DBAccess
|
namespace API.DBAccess
|
||||||
{
|
{
|
||||||
public class DbAccess
|
public class UserDBAccess
|
||||||
{
|
{
|
||||||
private readonly DBContext _context;
|
private readonly DBContext _context;
|
||||||
|
|
||||||
public DbAccess(DBContext context)
|
public UserDBAccess(DBContext context)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ namespace API.DBAccess
|
|||||||
{
|
{
|
||||||
_context.Users.Add(user);
|
_context.Users.Add(user);
|
||||||
|
|
||||||
bool saved = await _context.SaveChangesAsync() == 1;
|
bool saved = await _context.SaveChangesAsync() >= 1;
|
||||||
|
|
||||||
if (saved) { return new OkObjectResult(true); }
|
if (saved) { return new OkObjectResult(true); }
|
||||||
|
|
||||||
@ -66,7 +66,6 @@ namespace API.DBAccess
|
|||||||
if (saved) { return new OkObjectResult(user); }
|
if (saved) { return new OkObjectResult(user); }
|
||||||
|
|
||||||
return new ConflictObjectResult(new { message = "Could not save to database" });
|
return new ConflictObjectResult(new { message = "Could not save to database" });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> UpdatePassword(User user)
|
public async Task<IActionResult> UpdatePassword(User user)
|
@ -1,127 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
using MySql.EntityFrameworkCore.Metadata;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace API.Migrations
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public partial class RecipeModelAdded : Migration
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.AddColumn<int>(
|
|
||||||
name: "PrefereredRecipesId",
|
|
||||||
table: "Users",
|
|
||||||
type: "int",
|
|
||||||
nullable: false,
|
|
||||||
defaultValue: 0);
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "PrefereredRecipes",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(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<int>(type: "int", nullable: false)
|
|
||||||
.Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
|
|
||||||
Name = table.Column<string>(type: "longtext", nullable: false),
|
|
||||||
Description = table.Column<string>(type: "longtext", nullable: false),
|
|
||||||
Directions = table.Column<string>(type: "longtext", nullable: false),
|
|
||||||
PrefereredRecipesId = table.Column<int>(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<int>(type: "int", nullable: false)
|
|
||||||
.Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
|
|
||||||
Amount = table.Column<int>(type: "int", nullable: false),
|
|
||||||
Unit = table.Column<string>(type: "longtext", nullable: false),
|
|
||||||
Element = table.Column<string>(type: "longtext", nullable: false),
|
|
||||||
RecipeId = table.Column<int>(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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,36 +11,34 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
namespace API.Migrations
|
namespace API.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(DBContext))]
|
[DbContext(typeof(DBContext))]
|
||||||
[Migration("20250428070005_RecipeModelAdded")]
|
[Migration("20250429115336_RecipeModelAdded")]
|
||||||
partial class RecipeModelAdded
|
partial class RecipeModelAdded
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder.HasAnnotation("ProductVersion", "8.0.10");
|
||||||
.HasAnnotation("ProductVersion", "8.0.10")
|
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Models.RecipeModels.Ingredient", b =>
|
modelBuilder.Entity("API.Models.RecipeModels.Ingredient", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("int");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<int>("Amount")
|
b.Property<int>("Amount")
|
||||||
.HasColumnType("int");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<string>("Element")
|
b.Property<string>("Element")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<int?>("RecipeId")
|
b.Property<int?>("RecipeId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<string>("Unit")
|
b.Property<string>("Unit")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
@ -53,7 +51,7 @@ namespace API.Migrations
|
|||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("int");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
@ -64,22 +62,22 @@ namespace API.Migrations
|
|||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("int");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<string>("Description")
|
b.Property<string>("Description")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Directions")
|
b.Property<string>("Directions")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<int?>("PrefereredRecipesId")
|
b.Property<int?>("PrefereredRecipesId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
@ -88,35 +86,65 @@ namespace API.Migrations
|
|||||||
b.ToTable("Recipes");
|
b.ToTable("Recipes");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Models.ShoppingListModels.ShoppingList", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<double>("Amount")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<bool>("Checked")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Unit")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int?>("UserId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("ShoppingList");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Models.UserModels.User", b =>
|
modelBuilder.Entity("API.Models.UserModels.User", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("int");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<string>("Email")
|
b.Property<string>("Email")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Password")
|
b.Property<string>("Password")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<int>("PrefereredRecipesId")
|
b.Property<int>("PrefereredRecipesId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<string>("RefreshToken")
|
b.Property<string>("RefreshToken")
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<DateTime>("RefreshTokenExpireAt")
|
b.Property<DateTime>("RefreshTokenExpireAt")
|
||||||
.HasColumnType("datetime(6)");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Salt")
|
b.Property<string>("Salt")
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("UserName")
|
b.Property<string>("UserName")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
@ -139,6 +167,13 @@ namespace API.Migrations
|
|||||||
.HasForeignKey("PrefereredRecipesId");
|
.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 =>
|
modelBuilder.Entity("API.Models.UserModels.User", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("API.Models.RecipeModels.PrefereredRecipes", "PrefereredRecipes")
|
b.HasOne("API.Models.RecipeModels.PrefereredRecipes", "PrefereredRecipes")
|
||||||
@ -159,6 +194,11 @@ namespace API.Migrations
|
|||||||
{
|
{
|
||||||
b.Navigation("Ingredients");
|
b.Navigation("Ingredients");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Models.UserModels.User", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("ShoppingList");
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
274
backend/API/Migrations/20250429115336_RecipeModelAdded.cs
Normal file
274
backend/API/Migrations/20250429115336_RecipeModelAdded.cs
Normal file
@ -0,0 +1,274 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace API.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class RecipeModelAdded : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "UserName",
|
||||||
|
table: "Users",
|
||||||
|
type: "TEXT",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "longtext");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Salt",
|
||||||
|
table: "Users",
|
||||||
|
type: "TEXT",
|
||||||
|
nullable: true,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "longtext",
|
||||||
|
oldNullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<DateTime>(
|
||||||
|
name: "RefreshTokenExpireAt",
|
||||||
|
table: "Users",
|
||||||
|
type: "TEXT",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(DateTime),
|
||||||
|
oldType: "datetime(6)");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "RefreshToken",
|
||||||
|
table: "Users",
|
||||||
|
type: "TEXT",
|
||||||
|
nullable: true,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "longtext",
|
||||||
|
oldNullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Password",
|
||||||
|
table: "Users",
|
||||||
|
type: "TEXT",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "longtext");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Email",
|
||||||
|
table: "Users",
|
||||||
|
type: "TEXT",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "longtext");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<int>(
|
||||||
|
name: "Id",
|
||||||
|
table: "Users",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(int),
|
||||||
|
oldType: "int")
|
||||||
|
.Annotation("Sqlite:Autoincrement", true)
|
||||||
|
.OldAnnotation("Sqlite:Autoincrement", true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "PrefereredRecipesId",
|
||||||
|
table: "Users",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0);
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "PrefereredRecipes",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(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<int>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
Amount = table.Column<double>(type: "REAL", nullable: false),
|
||||||
|
Unit = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Name = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Checked = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||||
|
UserId = table.Column<int>(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<int>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
Name = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Description = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Directions = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
PrefereredRecipesId = table.Column<int>(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<int>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
Amount = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
Unit = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Element = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
RecipeId = table.Column<int>(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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
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<string>(
|
||||||
|
name: "UserName",
|
||||||
|
table: "Users",
|
||||||
|
type: "longtext",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "TEXT");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Salt",
|
||||||
|
table: "Users",
|
||||||
|
type: "longtext",
|
||||||
|
nullable: true,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "TEXT",
|
||||||
|
oldNullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<DateTime>(
|
||||||
|
name: "RefreshTokenExpireAt",
|
||||||
|
table: "Users",
|
||||||
|
type: "datetime(6)",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(DateTime),
|
||||||
|
oldType: "TEXT");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "RefreshToken",
|
||||||
|
table: "Users",
|
||||||
|
type: "longtext",
|
||||||
|
nullable: true,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "TEXT",
|
||||||
|
oldNullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Password",
|
||||||
|
table: "Users",
|
||||||
|
type: "longtext",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "TEXT");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Email",
|
||||||
|
table: "Users",
|
||||||
|
type: "longtext",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "TEXT");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<int>(
|
||||||
|
name: "Id",
|
||||||
|
table: "Users",
|
||||||
|
type: "int",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(int),
|
||||||
|
oldType: "INTEGER")
|
||||||
|
.Annotation("Sqlite:Autoincrement", true)
|
||||||
|
.OldAnnotation("Sqlite:Autoincrement", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,29 +15,27 @@ namespace API.Migrations
|
|||||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder.HasAnnotation("ProductVersion", "8.0.10");
|
||||||
.HasAnnotation("ProductVersion", "8.0.10")
|
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Models.RecipeModels.Ingredient", b =>
|
modelBuilder.Entity("API.Models.RecipeModels.Ingredient", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("int");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<int>("Amount")
|
b.Property<int>("Amount")
|
||||||
.HasColumnType("int");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<string>("Element")
|
b.Property<string>("Element")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<int?>("RecipeId")
|
b.Property<int?>("RecipeId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<string>("Unit")
|
b.Property<string>("Unit")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
@ -50,7 +48,7 @@ namespace API.Migrations
|
|||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("int");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
@ -61,22 +59,22 @@ namespace API.Migrations
|
|||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("int");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<string>("Description")
|
b.Property<string>("Description")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Directions")
|
b.Property<string>("Directions")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<int?>("PrefereredRecipesId")
|
b.Property<int?>("PrefereredRecipesId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
@ -85,35 +83,65 @@ namespace API.Migrations
|
|||||||
b.ToTable("Recipes");
|
b.ToTable("Recipes");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Models.ShoppingListModels.ShoppingList", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<double>("Amount")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<bool>("Checked")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Unit")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int?>("UserId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("ShoppingList");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Models.UserModels.User", b =>
|
modelBuilder.Entity("API.Models.UserModels.User", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("int");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<string>("Email")
|
b.Property<string>("Email")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Password")
|
b.Property<string>("Password")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<int>("PrefereredRecipesId")
|
b.Property<int>("PrefereredRecipesId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<string>("RefreshToken")
|
b.Property<string>("RefreshToken")
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<DateTime>("RefreshTokenExpireAt")
|
b.Property<DateTime>("RefreshTokenExpireAt")
|
||||||
.HasColumnType("datetime(6)");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Salt")
|
b.Property<string>("Salt")
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("UserName")
|
b.Property<string>("UserName")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
@ -136,6 +164,13 @@ namespace API.Migrations
|
|||||||
.HasForeignKey("PrefereredRecipesId");
|
.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 =>
|
modelBuilder.Entity("API.Models.UserModels.User", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("API.Models.RecipeModels.PrefereredRecipes", "PrefereredRecipes")
|
b.HasOne("API.Models.RecipeModels.PrefereredRecipes", "PrefereredRecipes")
|
||||||
@ -156,6 +191,11 @@ namespace API.Migrations
|
|||||||
{
|
{
|
||||||
b.Navigation("Ingredients");
|
b.Navigation("Ingredients");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Models.UserModels.User", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("ShoppingList");
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
11
backend/API/Models/RecipeModels/IngredientDTO.cs
Normal file
11
backend/API/Models/RecipeModels/IngredientDTO.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
7
backend/API/Models/RecipeModels/PrefereredRecipesDTO.cs
Normal file
7
backend/API/Models/RecipeModels/PrefereredRecipesDTO.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace API.Models.RecipeModels
|
||||||
|
{
|
||||||
|
public class PrefereredRecipesDTO
|
||||||
|
{
|
||||||
|
public List<RecipeDTO> Recipes { get; set; }
|
||||||
|
}
|
||||||
|
}
|
13
backend/API/Models/RecipeModels/RecipeDTO.cs
Normal file
13
backend/API/Models/RecipeModels/RecipeDTO.cs
Normal file
@ -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<IngredientDTO> Ingredients { get; set; }
|
||||||
|
}
|
||||||
|
}
|
15
backend/API/Models/ShoppingListModels/ShoppingList.cs
Normal file
15
backend/API/Models/ShoppingListModels/ShoppingList.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
14
backend/API/Models/ShoppingListModels/ShoppingListItemDTO.cs
Normal file
14
backend/API/Models/ShoppingListModels/ShoppingListItemDTO.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using API.Models.RecipeModels;
|
using API.Models.RecipeModels;
|
||||||
|
using API.Models.ShoppingListModels;
|
||||||
|
|
||||||
namespace API.Models.UserModels
|
namespace API.Models.UserModels
|
||||||
{
|
{
|
||||||
@ -19,5 +20,7 @@ namespace API.Models.UserModels
|
|||||||
public DateTime RefreshTokenExpireAt { get; set; }
|
public DateTime RefreshTokenExpireAt { get; set; }
|
||||||
|
|
||||||
public PrefereredRecipes PrefereredRecipes { get; set; }
|
public PrefereredRecipes PrefereredRecipes { get; set; }
|
||||||
|
|
||||||
|
public List<ShoppingList> ShoppingList { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,10 @@ namespace API
|
|||||||
services.AddDbContext<DBContext>(options =>
|
services.AddDbContext<DBContext>(options =>
|
||||||
options.UseMySQL(_configuration.GetConnectionString("Database")));
|
options.UseMySQL(_configuration.GetConnectionString("Database")));
|
||||||
|
|
||||||
services.AddScoped<DbAccess>();
|
services.AddScoped<UserDBAccess>();
|
||||||
services.AddScoped<UserLogic>();
|
services.AddScoped<UserLogic>();
|
||||||
|
services.AddScoped<RecipeDBAccess>();
|
||||||
|
services.AddScoped<RecipeLogic>();
|
||||||
|
|
||||||
services.AddControllers();
|
services.AddControllers();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user