Compare commits
No commits in common. "dfa9abc4b93a42a17e3a298a5145fd411d70307a" and "5e32ad713371e7a6b991e8bd9dcb5ca71ebe1a2d" have entirely different histories.
dfa9abc4b9
...
5e32ad7133
3
.gitignore
vendored
3
.gitignore
vendored
@ -6,6 +6,3 @@
|
||||
/backend/API/appsettings.Development.json
|
||||
/backend/API/appsettings.json
|
||||
*bin
|
||||
/backend/API/database.sqlite3
|
||||
/backend/API/database.sqlite3-shm
|
||||
/backend/API/database.sqlite3-wal
|
||||
|
@ -19,7 +19,7 @@ android {
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
buildConfigField("String", "API_BASE_URL", project.property("API_BASE_URL").toString())
|
||||
buildConfigField("String", "API_BASE_URL", gradleLocalProperties(projectDir, providers).getProperty("API_BASE_URL"))
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
@ -1 +0,0 @@
|
||||
API_BASE_URL="https://easyeat.mercantec.tech"
|
@ -1,42 +1,25 @@
|
||||
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)
|
||||
|
||||
ingredientContainer = findViewById(R.id.ingredientContainer)
|
||||
val addButton: Button = findViewById(R.id.addIngredientButton)
|
||||
// Setup the Toolbar as ActionBar
|
||||
val toolbar: Toolbar = findViewById(R.id.toolbar)
|
||||
setSupportActionBar(toolbar)
|
||||
|
||||
// Add the first ingredient row manually at startup
|
||||
addIngredientRow()
|
||||
|
||||
// Set up button to add new rows
|
||||
addButton.setOnClickListener {
|
||||
addIngredientRow()
|
||||
}
|
||||
// Enable the Up button
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(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)
|
||||
// Handle the Up button click
|
||||
override fun onSupportNavigateUp(): Boolean {
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -31,10 +31,7 @@ class RegisterActivity : AppCompatActivity() {
|
||||
try {
|
||||
register(email, username, password)
|
||||
} catch (e: ApiRequestException) {
|
||||
runOnUiThread {
|
||||
Toast.makeText(this, e.message, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
Toast.makeText(this, e.message, Toast.LENGTH_LONG).show()
|
||||
return@thread
|
||||
}
|
||||
|
||||
|
@ -59,8 +59,6 @@ inline fun <reified Req, reified Res> requestJson(method: String, path: String,
|
||||
|
||||
throw ApiRequestException(error.message, null)
|
||||
} catch (e: SerializationException) {
|
||||
if (e.message != null)
|
||||
Log.e("EasyEat", e.message!!)
|
||||
Log.e("EasyEat", response.body)
|
||||
|
||||
throw ApiRequestException("Request failed with HTTP status code ${response.code}", e)
|
||||
@ -70,8 +68,6 @@ inline fun <reified Req, reified Res> requestJson(method: String, path: String,
|
||||
try {
|
||||
return Json.decodeFromString<Res>(response.body)
|
||||
} catch (e: SerializationException) {
|
||||
if (e.message != null)
|
||||
Log.e("EasyEat", e.message!!)
|
||||
Log.e("EasyEat", response.body)
|
||||
|
||||
throw ApiRequestException("Failed to parse response: $response", e)
|
||||
|
@ -7,7 +7,7 @@ import kotlinx.serialization.Serializable
|
||||
data class LoginRequest(val emailUsr: String, val password: String)
|
||||
|
||||
@Serializable
|
||||
data class LoginResponse(val token: String, val userName: String, val id: Int, val refreshToken: String)
|
||||
data class LoginResponse(val token: String, val username: String, val id: Int, val refreshToken: String)
|
||||
|
||||
fun login(email: String, password: String) {
|
||||
val request = LoginRequest(email, password)
|
||||
|
@ -6,6 +6,14 @@
|
||||
android:orientation="vertical"
|
||||
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
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -13,12 +21,8 @@
|
||||
android:textAlignment="center"
|
||||
android:textSize="24sp" />
|
||||
|
||||
<!-- Container for all ingredient rows -->
|
||||
<LinearLayout
|
||||
android:id="@+id/ingredientContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" />
|
||||
<include
|
||||
layout="@layout/activity_create_dish_ingredient_row" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/addIngredientButton"
|
||||
@ -28,4 +32,3 @@
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="16dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -13,7 +13,6 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
@ -1,100 +0,0 @@
|
||||
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" });
|
||||
}
|
||||
}
|
||||
}
|
@ -1,209 +0,0 @@
|
||||
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,23 +1,22 @@
|
||||
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 UserDBAccess _dbAccess;
|
||||
private readonly DbAccess _dbAccess;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public UserLogic(IConfiguration configuration, UserDBAccess dbAccess)
|
||||
public UserLogic(IConfiguration configuration, DbAccess dbAccess)
|
||||
{
|
||||
_dbAccess = dbAccess;
|
||||
_configuration = configuration;
|
||||
@ -61,17 +60,12 @@ namespace API.BusinessLogic
|
||||
string salt = Guid.NewGuid().ToString();
|
||||
string hashedPassword = ComputeHash(userDTO.Password, SHA256.Create(), salt);
|
||||
|
||||
PrefereredRecipes recipes = new PrefereredRecipes();
|
||||
recipes.Recipes = new List<Recipe>();
|
||||
|
||||
User user = new User
|
||||
{
|
||||
UserName = userDTO.UserName,
|
||||
Email = userDTO.Email,
|
||||
Password = hashedPassword,
|
||||
Salt = salt,
|
||||
PrefereredRecipes = recipes,
|
||||
ShoppingList = new List<ShoppingList>(),
|
||||
};
|
||||
|
||||
return await _dbAccess.CreateUser(user);
|
||||
|
@ -1,61 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
|
||||
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,5 +1,4 @@
|
||||
using API.Models.RecipeModels;
|
||||
using API.Models.ShoppingListModels;
|
||||
using API.Models.UserModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@ -13,8 +12,6 @@ namespace API.DBAccess
|
||||
|
||||
public DbSet<Recipe> Recipes { get; set; }
|
||||
|
||||
public DbSet<ShoppingList> ShoppingList { get; set; }
|
||||
|
||||
public DBContext(DbContextOptions<DBContext> options) : base(options) { }
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,11 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.DBAccess
|
||||
{
|
||||
public class UserDBAccess
|
||||
public class DbAccess
|
||||
{
|
||||
private readonly DBContext _context;
|
||||
|
||||
public UserDBAccess(DBContext context)
|
||||
public DbAccess(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,6 +66,7 @@ namespace API.DBAccess
|
||||
if (saved) { return new OkObjectResult(user); }
|
||||
|
||||
return new ConflictObjectResult(new { message = "Could not save to database" });
|
||||
|
||||
}
|
||||
|
||||
public async Task<IActionResult> UpdatePassword(User user)
|
@ -1,79 +0,0 @@
|
||||
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" });
|
||||
}
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
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" });
|
||||
}
|
||||
}
|
||||
}
|
@ -11,34 +11,36 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace API.Migrations
|
||||
{
|
||||
[DbContext(typeof(DBContext))]
|
||||
[Migration("20250429115336_RecipeModelAdded")]
|
||||
[Migration("20250428070005_RecipeModelAdded")]
|
||||
partial class RecipeModelAdded
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.10");
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.10")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("API.Models.RecipeModels.Ingredient", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Amount")
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Element")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int?>("RecipeId")
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Unit")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -51,7 +53,7 @@ namespace API.Migrations
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -62,22 +64,22 @@ namespace API.Migrations
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Directions")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int?>("PrefereredRecipesId")
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -86,65 +88,35 @@ namespace API.Migrations
|
||||
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 =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("PrefereredRecipesId")
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("RefreshToken")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<DateTime>("RefreshTokenExpireAt")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Salt")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("UserName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -167,13 +139,6 @@ 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")
|
||||
@ -194,11 +159,6 @@ namespace API.Migrations
|
||||
{
|
||||
b.Navigation("Ingredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Models.UserModels.User", b =>
|
||||
{
|
||||
b.Navigation("ShoppingList");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
127
backend/API/Migrations/20250428070005_RecipeModelAdded.cs
Normal file
127
backend/API/Migrations/20250428070005_RecipeModelAdded.cs
Normal file
@ -0,0 +1,127 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,274 +0,0 @@
|
||||
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,27 +15,29 @@ namespace API.Migrations
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.10");
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.10")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("API.Models.RecipeModels.Ingredient", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Amount")
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Element")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int?>("RecipeId")
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Unit")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -48,7 +50,7 @@ namespace API.Migrations
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -59,22 +61,22 @@ namespace API.Migrations
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Directions")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int?>("PrefereredRecipesId")
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -83,65 +85,35 @@ namespace API.Migrations
|
||||
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 =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("PrefereredRecipesId")
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("RefreshToken")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<DateTime>("RefreshTokenExpireAt")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Salt")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("UserName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -164,13 +136,6 @@ 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")
|
||||
@ -191,11 +156,6 @@ namespace API.Migrations
|
||||
{
|
||||
b.Navigation("Ingredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Models.UserModels.User", b =>
|
||||
{
|
||||
b.Navigation("ShoppingList");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +0,0 @@
|
||||
namespace API.Models.RecipeModels
|
||||
{
|
||||
public class IngredientDTO
|
||||
{
|
||||
public int Amount { get; set; }
|
||||
|
||||
public string Unit { get; set; }
|
||||
|
||||
public string Element { get; set; }
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
namespace API.Models.RecipeModels
|
||||
{
|
||||
public class PrefereredRecipesDTO
|
||||
{
|
||||
public List<RecipeDTO> Recipes { get; set; }
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
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; }
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
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; }
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
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,5 +1,4 @@
|
||||
using API.Models.RecipeModels;
|
||||
using API.Models.ShoppingListModels;
|
||||
|
||||
namespace API.Models.UserModels
|
||||
{
|
||||
@ -20,7 +19,5 @@ namespace API.Models.UserModels
|
||||
public DateTime RefreshTokenExpireAt { get; set; }
|
||||
|
||||
public PrefereredRecipes PrefereredRecipes { get; set; }
|
||||
|
||||
public List<ShoppingList> ShoppingList { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -25,10 +25,8 @@ namespace API
|
||||
services.AddDbContext<DBContext>(options =>
|
||||
options.UseMySQL(_configuration.GetConnectionString("Database")));
|
||||
|
||||
services.AddScoped<UserDBAccess>();
|
||||
services.AddScoped<DbAccess>();
|
||||
services.AddScoped<UserLogic>();
|
||||
services.AddScoped<RecipeDBAccess>();
|
||||
services.AddScoped<RecipeLogic>();
|
||||
|
||||
services.AddControllers();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user