From 108598ef98f2d28d73aba7b987e43f3438dac98a Mon Sep 17 00:00:00 2001 From: Jeas0001 Date: Mon, 28 Apr 2025 09:00:30 +0200 Subject: [PATCH] RecipeModels --- backend/API/DBAccess/DBContext.cs | 7 +- ...0250428070005_RecipeModelAdded.Designer.cs | 165 ++++++++++++++++++ .../20250428070005_RecipeModelAdded.cs | 127 ++++++++++++++ .../API/Migrations/DBContextModelSnapshot.cs | 106 +++++++++++ backend/API/Models/RecipeModels/Ingredient.cs | 13 ++ .../Models/RecipeModels/PrefereredRecipes.cs | 9 + backend/API/Models/RecipeModels/Recipe.cs | 15 ++ backend/API/Models/UserModels/User.cs | 6 +- 8 files changed, 446 insertions(+), 2 deletions(-) create mode 100644 backend/API/Migrations/20250428070005_RecipeModelAdded.Designer.cs create mode 100644 backend/API/Migrations/20250428070005_RecipeModelAdded.cs create mode 100644 backend/API/Models/RecipeModels/Ingredient.cs create mode 100644 backend/API/Models/RecipeModels/PrefereredRecipes.cs create mode 100644 backend/API/Models/RecipeModels/Recipe.cs diff --git a/backend/API/DBAccess/DBContext.cs b/backend/API/DBAccess/DBContext.cs index e7fffff..04c124e 100644 --- a/backend/API/DBAccess/DBContext.cs +++ b/backend/API/DBAccess/DBContext.cs @@ -1,4 +1,5 @@ -using API.Models.UserModels; +using API.Models.RecipeModels; +using API.Models.UserModels; using Microsoft.EntityFrameworkCore; namespace API.DBAccess @@ -7,6 +8,10 @@ namespace API.DBAccess { public DbSet Users { get; set; } + public DbSet PrefereredRecipes { get; set; } + + public DbSet Recipes { get; set; } + public DBContext(DbContextOptions options) : base(options) { } } } diff --git a/backend/API/Migrations/20250428070005_RecipeModelAdded.Designer.cs b/backend/API/Migrations/20250428070005_RecipeModelAdded.Designer.cs new file mode 100644 index 0000000..b851f33 --- /dev/null +++ b/backend/API/Migrations/20250428070005_RecipeModelAdded.Designer.cs @@ -0,0 +1,165 @@ +// +using System; +using API.DBAccess; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace API.Migrations +{ + [DbContext(typeof(DBContext))] + [Migration("20250428070005_RecipeModelAdded")] + partial class RecipeModelAdded + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("API.Models.RecipeModels.Ingredient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Amount") + .HasColumnType("int"); + + b.Property("Element") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("RecipeId") + .HasColumnType("int"); + + b.Property("Unit") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("RecipeId"); + + b.ToTable("Ingredient"); + }); + + modelBuilder.Entity("API.Models.RecipeModels.PrefereredRecipes", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("PrefereredRecipes"); + }); + + modelBuilder.Entity("API.Models.RecipeModels.Recipe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Directions") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("PrefereredRecipesId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PrefereredRecipesId"); + + b.ToTable("Recipes"); + }); + + modelBuilder.Entity("API.Models.UserModels.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Email") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Password") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("PrefereredRecipesId") + .HasColumnType("int"); + + b.Property("RefreshToken") + .HasColumnType("longtext"); + + b.Property("RefreshTokenExpireAt") + .HasColumnType("datetime(6)"); + + b.Property("Salt") + .HasColumnType("longtext"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("PrefereredRecipesId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("API.Models.RecipeModels.Ingredient", b => + { + b.HasOne("API.Models.RecipeModels.Recipe", null) + .WithMany("Ingredients") + .HasForeignKey("RecipeId"); + }); + + modelBuilder.Entity("API.Models.RecipeModels.Recipe", b => + { + b.HasOne("API.Models.RecipeModels.PrefereredRecipes", null) + .WithMany("Recipes") + .HasForeignKey("PrefereredRecipesId"); + }); + + modelBuilder.Entity("API.Models.UserModels.User", b => + { + b.HasOne("API.Models.RecipeModels.PrefereredRecipes", "PrefereredRecipes") + .WithMany() + .HasForeignKey("PrefereredRecipesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PrefereredRecipes"); + }); + + modelBuilder.Entity("API.Models.RecipeModels.PrefereredRecipes", b => + { + b.Navigation("Recipes"); + }); + + modelBuilder.Entity("API.Models.RecipeModels.Recipe", b => + { + b.Navigation("Ingredients"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/backend/API/Migrations/20250428070005_RecipeModelAdded.cs b/backend/API/Migrations/20250428070005_RecipeModelAdded.cs new file mode 100644 index 0000000..afe234c --- /dev/null +++ b/backend/API/Migrations/20250428070005_RecipeModelAdded.cs @@ -0,0 +1,127 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using MySql.EntityFrameworkCore.Metadata; + +#nullable disable + +namespace API.Migrations +{ + /// + public partial class RecipeModelAdded : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "PrefereredRecipesId", + table: "Users", + type: "int", + nullable: false, + defaultValue: 0); + + migrationBuilder.CreateTable( + name: "PrefereredRecipes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn) + }, + constraints: table => + { + table.PrimaryKey("PK_PrefereredRecipes", x => x.Id); + }) + .Annotation("MySQL:Charset", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Recipes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn), + Name = table.Column(type: "longtext", nullable: false), + Description = table.Column(type: "longtext", nullable: false), + Directions = table.Column(type: "longtext", nullable: false), + PrefereredRecipesId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Recipes", x => x.Id); + table.ForeignKey( + name: "FK_Recipes_PrefereredRecipes_PrefereredRecipesId", + column: x => x.PrefereredRecipesId, + principalTable: "PrefereredRecipes", + principalColumn: "Id"); + }) + .Annotation("MySQL:Charset", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Ingredient", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn), + Amount = table.Column(type: "int", nullable: false), + Unit = table.Column(type: "longtext", nullable: false), + Element = table.Column(type: "longtext", nullable: false), + RecipeId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Ingredient", x => x.Id); + table.ForeignKey( + name: "FK_Ingredient_Recipes_RecipeId", + column: x => x.RecipeId, + principalTable: "Recipes", + principalColumn: "Id"); + }) + .Annotation("MySQL:Charset", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_Users_PrefereredRecipesId", + table: "Users", + column: "PrefereredRecipesId"); + + migrationBuilder.CreateIndex( + name: "IX_Ingredient_RecipeId", + table: "Ingredient", + column: "RecipeId"); + + migrationBuilder.CreateIndex( + name: "IX_Recipes_PrefereredRecipesId", + table: "Recipes", + column: "PrefereredRecipesId"); + + migrationBuilder.AddForeignKey( + name: "FK_Users_PrefereredRecipes_PrefereredRecipesId", + table: "Users", + column: "PrefereredRecipesId", + principalTable: "PrefereredRecipes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Users_PrefereredRecipes_PrefereredRecipesId", + table: "Users"); + + migrationBuilder.DropTable( + name: "Ingredient"); + + migrationBuilder.DropTable( + name: "Recipes"); + + migrationBuilder.DropTable( + name: "PrefereredRecipes"); + + migrationBuilder.DropIndex( + name: "IX_Users_PrefereredRecipesId", + table: "Users"); + + migrationBuilder.DropColumn( + name: "PrefereredRecipesId", + table: "Users"); + } + } +} diff --git a/backend/API/Migrations/DBContextModelSnapshot.cs b/backend/API/Migrations/DBContextModelSnapshot.cs index 71ff77e..f11e5a4 100644 --- a/backend/API/Migrations/DBContextModelSnapshot.cs +++ b/backend/API/Migrations/DBContextModelSnapshot.cs @@ -19,6 +19,72 @@ namespace API.Migrations .HasAnnotation("ProductVersion", "8.0.10") .HasAnnotation("Relational:MaxIdentifierLength", 64); + modelBuilder.Entity("API.Models.RecipeModels.Ingredient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Amount") + .HasColumnType("int"); + + b.Property("Element") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("RecipeId") + .HasColumnType("int"); + + b.Property("Unit") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("RecipeId"); + + b.ToTable("Ingredient"); + }); + + modelBuilder.Entity("API.Models.RecipeModels.PrefereredRecipes", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("PrefereredRecipes"); + }); + + modelBuilder.Entity("API.Models.RecipeModels.Recipe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Directions") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("PrefereredRecipesId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PrefereredRecipesId"); + + b.ToTable("Recipes"); + }); + modelBuilder.Entity("API.Models.UserModels.User", b => { b.Property("Id") @@ -33,6 +99,9 @@ namespace API.Migrations .IsRequired() .HasColumnType("longtext"); + b.Property("PrefereredRecipesId") + .HasColumnType("int"); + b.Property("RefreshToken") .HasColumnType("longtext"); @@ -48,8 +117,45 @@ namespace API.Migrations b.HasKey("Id"); + b.HasIndex("PrefereredRecipesId"); + b.ToTable("Users"); }); + + modelBuilder.Entity("API.Models.RecipeModels.Ingredient", b => + { + b.HasOne("API.Models.RecipeModels.Recipe", null) + .WithMany("Ingredients") + .HasForeignKey("RecipeId"); + }); + + modelBuilder.Entity("API.Models.RecipeModels.Recipe", b => + { + b.HasOne("API.Models.RecipeModels.PrefereredRecipes", null) + .WithMany("Recipes") + .HasForeignKey("PrefereredRecipesId"); + }); + + modelBuilder.Entity("API.Models.UserModels.User", b => + { + b.HasOne("API.Models.RecipeModels.PrefereredRecipes", "PrefereredRecipes") + .WithMany() + .HasForeignKey("PrefereredRecipesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PrefereredRecipes"); + }); + + modelBuilder.Entity("API.Models.RecipeModels.PrefereredRecipes", b => + { + b.Navigation("Recipes"); + }); + + modelBuilder.Entity("API.Models.RecipeModels.Recipe", b => + { + b.Navigation("Ingredients"); + }); #pragma warning restore 612, 618 } } diff --git a/backend/API/Models/RecipeModels/Ingredient.cs b/backend/API/Models/RecipeModels/Ingredient.cs new file mode 100644 index 0000000..f2af7ee --- /dev/null +++ b/backend/API/Models/RecipeModels/Ingredient.cs @@ -0,0 +1,13 @@ +namespace API.Models.RecipeModels +{ + public class Ingredient + { + public int Id { get; set; } + + public int Amount { get; set; } + + public string Unit { get; set; } + + public string Element { get; set; } + } +} diff --git a/backend/API/Models/RecipeModels/PrefereredRecipes.cs b/backend/API/Models/RecipeModels/PrefereredRecipes.cs new file mode 100644 index 0000000..5a5872d --- /dev/null +++ b/backend/API/Models/RecipeModels/PrefereredRecipes.cs @@ -0,0 +1,9 @@ +namespace API.Models.RecipeModels +{ + public class PrefereredRecipes + { + public int Id { get; set; } + + public List Recipes { get; set; } + } +} diff --git a/backend/API/Models/RecipeModels/Recipe.cs b/backend/API/Models/RecipeModels/Recipe.cs new file mode 100644 index 0000000..053aa64 --- /dev/null +++ b/backend/API/Models/RecipeModels/Recipe.cs @@ -0,0 +1,15 @@ +namespace API.Models.RecipeModels +{ + public class Recipe + { + public int Id { get; set; } + + public string Name { get; set; } + + public string Description { get; set; } + + public string Directions { get; set; } + + public List Ingredients { get; set; } + } +} diff --git a/backend/API/Models/UserModels/User.cs b/backend/API/Models/UserModels/User.cs index 107646a..e81b231 100644 --- a/backend/API/Models/UserModels/User.cs +++ b/backend/API/Models/UserModels/User.cs @@ -1,4 +1,6 @@ -namespace API.Models.UserModels +using API.Models.RecipeModels; + +namespace API.Models.UserModels { public class User { @@ -15,5 +17,7 @@ public string? RefreshToken { get; set; } public DateTime RefreshTokenExpireAt { get; set; } + + public PrefereredRecipes PrefereredRecipes { get; set; } } }