Correct models unit and recipe and add a new migration

This commit is contained in:
Francesco D'Amico
2025-03-18 16:14:01 +01:00
parent a91ca743ab
commit c498e23a07
6 changed files with 47 additions and 34 deletions
@@ -1,22 +1,20 @@
namespace Francesco.Recipes.World.Data namespace Francesco.Recipes.World.Data
{ {
<<<<<<< HEAD
using Francesco.Recipes.World.Models.BackendModels; using Francesco.Recipes.World.Models.BackendModels;
using Francesco.Recipes.World.Models.BackendModels.Category; using Francesco.Recipes.World.Models.BackendModels.Category;
using Francesco.Recipes.World.Models.BackendModels.Favorit; using Francesco.Recipes.World.Models.BackendModels.Favorit;
=======
using Francesco.Recipes.World.Models.BackendModels.Category;
>>>>>>> parent of 45702aa (Correct Models Unit and Category)
using Francesco.Recipes.World.Models.BackendModels.Ingredient; using Francesco.Recipes.World.Models.BackendModels.Ingredient;
using Francesco.Recipes.World.Models.BackendModels.IngredientShoppingList;
using Francesco.Recipes.World.Models.BackendModels.Instruction; using Francesco.Recipes.World.Models.BackendModels.Instruction;
using Francesco.Recipes.World.Models.BackendModels.MediaFile;
using Francesco.Recipes.World.Models.BackendModels.Recipe; using Francesco.Recipes.World.Models.BackendModels.Recipe;
using Francesco.Recipes.World.Models.BackendModels.RecipeIngredient; using Francesco.Recipes.World.Models.BackendModels.RecipeIngredient;
using Francesco.Recipes.World.Models.BackendModels.Shoppinglist;
using Francesco.Recipes.World.Models.BackendModels.Unit; using Francesco.Recipes.World.Models.BackendModels.Unit;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
public class FrancescosRecipesWorldDbContext : DbContext public class FrancescosRecipesWorldDbContext : DbContext
{ {
<<<<<<< HEAD
public FrancescosRecipesWorldDbContext(DbContextOptions<FrancescosRecipesWorldDbContext> options) public FrancescosRecipesWorldDbContext(DbContextOptions<FrancescosRecipesWorldDbContext> options)
: base(options) : base(options)
{ {
@@ -105,18 +103,5 @@
new Unit { Id = Guid.Parse("24a91b89-3389-4465-89e4-2f70d2ea6fd7"), Name = "esslöffel", Symbol = "EL" }, new Unit { Id = Guid.Parse("24a91b89-3389-4465-89e4-2f70d2ea6fd7"), Name = "esslöffel", Symbol = "EL" },
]; ];
} }
=======
public FrancescosRecipesWorldDbContext(DbContextOptions<FrancescosRecipesWorldDbContext> options)
: base(options)
{
}
public DbSet<Category> Categories => Set<Category>();
public DbSet<Ingredient> Ingredients => Set<Ingredient>();
public DbSet<Instruction> Instructions => Set<Instruction>();
public DbSet<Recipe> Recipes => Set<Recipe>();
public DbSet<RecipeIngredient> RecipeIngredients => Set<RecipeIngredient>();
public DbSet<Unit> Units => Set<Unit>();
>>>>>>> parent of 45702aa (Correct Models Unit and Category)
} }
} }
@@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Francesco.Recipes.World.Migrations namespace Francesco.Recipes.World.Migrations
{ {
[DbContext(typeof(FrancescosRecipesWorldDbContext))] [DbContext(typeof(FrancescosRecipesWorldDbContext))]
[Migration("20250318105823_InitialMigration")] [Migration("20250318150949_InitialMIgration")]
partial class InitialMigration partial class InitialMIgration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -32,6 +32,7 @@ namespace Francesco.Recipes.World.Migrations
.HasColumnType("uniqueidentifier"); .HasColumnType("uniqueidentifier");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.HasKey("Id"); b.HasKey("Id");
@@ -112,6 +113,7 @@ namespace Francesco.Recipes.World.Migrations
.HasColumnType("uniqueidentifier"); .HasColumnType("uniqueidentifier");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.HasKey("Id"); b.HasKey("Id");
@@ -147,9 +149,11 @@ namespace Francesco.Recipes.World.Migrations
.HasColumnType("uniqueidentifier"); .HasColumnType("uniqueidentifier");
b.Property<string>("Description") b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<string>("Number") b.Property<string>("Number")
.IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<Guid>("RecipeId") b.Property<Guid>("RecipeId")
@@ -219,7 +223,11 @@ namespace Francesco.Recipes.World.Migrations
b.Property<bool>("IsFavorite") b.Property<bool>("IsFavorite")
.HasColumnType("bit"); .HasColumnType("bit");
b.Property<DateTime?>("ModifiedAt")
.HasColumnType("datetime2");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<TimeSpan>("PreparationTime") b.Property<TimeSpan>("PreparationTime")
@@ -275,6 +283,9 @@ namespace Francesco.Recipes.World.Migrations
b.Property<DateTime>("CreatedAt") b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2"); .HasColumnType("datetime2");
b.Property<DateTime?>("ModifiedAt")
.HasColumnType("datetime2");
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("ShoppingLists"); b.ToTable("ShoppingLists");
@@ -287,9 +298,11 @@ namespace Francesco.Recipes.World.Migrations
.HasColumnType("uniqueidentifier"); .HasColumnType("uniqueidentifier");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<string>("Symbol") b.Property<string>("Symbol")
.IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.HasKey("Id"); b.HasKey("Id");
@@ -8,12 +8,12 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace Francesco.Recipes.World.Migrations namespace Francesco.Recipes.World.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class InitialMigration : Migration public partial class InitialMIgration : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
if (migrationBuilder == null) if (migrationBuilder is null)
{ {
throw new ArgumentNullException(nameof(migrationBuilder)); throw new ArgumentNullException(nameof(migrationBuilder));
} }
@@ -22,7 +22,7 @@ namespace Francesco.Recipes.World.Migrations
columns: table => new columns: table => new
{ {
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: true) Name = table.Column<string>(type: "nvarchar(max)", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
@@ -46,7 +46,7 @@ namespace Francesco.Recipes.World.Migrations
columns: table => new columns: table => new
{ {
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: true) Name = table.Column<string>(type: "nvarchar(max)", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
@@ -58,7 +58,8 @@ namespace Francesco.Recipes.World.Migrations
columns: table => new columns: table => new
{ {
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false) CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
ModifiedAt = table.Column<DateTime>(type: "datetime2", nullable: true)
}, },
constraints: table => constraints: table =>
{ {
@@ -70,8 +71,8 @@ namespace Francesco.Recipes.World.Migrations
columns: table => new columns: table => new
{ {
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: true), Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Symbol = table.Column<string>(type: "nvarchar(max)", nullable: true) Symbol = table.Column<string>(type: "nvarchar(max)", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
@@ -83,7 +84,7 @@ namespace Francesco.Recipes.World.Migrations
columns: table => new columns: table => new
{ {
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: true), Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: true), Description = table.Column<string>(type: "nvarchar(max)", nullable: true),
Difficulty = table.Column<int>(type: "int", nullable: false), Difficulty = table.Column<int>(type: "int", nullable: false),
Servings = table.Column<int>(type: "int", nullable: false), Servings = table.Column<int>(type: "int", nullable: false),
@@ -91,6 +92,7 @@ namespace Francesco.Recipes.World.Migrations
CookingTime = table.Column<TimeSpan>(type: "time", nullable: false), CookingTime = table.Column<TimeSpan>(type: "time", nullable: false),
IsFavorite = table.Column<bool>(type: "bit", nullable: false), IsFavorite = table.Column<bool>(type: "bit", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false), CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
ModifiedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
FavoritId = table.Column<Guid>(type: "uniqueidentifier", nullable: false), FavoritId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
CategoryId = table.Column<Guid>(type: "uniqueidentifier", nullable: true) CategoryId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
}, },
@@ -140,8 +142,8 @@ namespace Francesco.Recipes.World.Migrations
columns: table => new columns: table => new
{ {
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: true), Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
Number = table.Column<string>(type: "nvarchar(max)", nullable: true), Number = table.Column<string>(type: "nvarchar(max)", nullable: false),
RecipeId = table.Column<Guid>(type: "uniqueidentifier", nullable: false) RecipeId = table.Column<Guid>(type: "uniqueidentifier", nullable: false)
}, },
constraints: table => constraints: table =>
@@ -304,7 +306,7 @@ namespace Francesco.Recipes.World.Migrations
/// <inheritdoc /> /// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder)
{ {
if (migrationBuilder == null) if (migrationBuilder is null)
{ {
throw new ArgumentNullException(nameof(migrationBuilder)); throw new ArgumentNullException(nameof(migrationBuilder));
} }
@@ -29,6 +29,7 @@ namespace Francesco.Recipes.World.Migrations
.HasColumnType("uniqueidentifier"); .HasColumnType("uniqueidentifier");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.HasKey("Id"); b.HasKey("Id");
@@ -109,6 +110,7 @@ namespace Francesco.Recipes.World.Migrations
.HasColumnType("uniqueidentifier"); .HasColumnType("uniqueidentifier");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.HasKey("Id"); b.HasKey("Id");
@@ -144,9 +146,11 @@ namespace Francesco.Recipes.World.Migrations
.HasColumnType("uniqueidentifier"); .HasColumnType("uniqueidentifier");
b.Property<string>("Description") b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<string>("Number") b.Property<string>("Number")
.IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<Guid>("RecipeId") b.Property<Guid>("RecipeId")
@@ -216,7 +220,11 @@ namespace Francesco.Recipes.World.Migrations
b.Property<bool>("IsFavorite") b.Property<bool>("IsFavorite")
.HasColumnType("bit"); .HasColumnType("bit");
b.Property<DateTime?>("ModifiedAt")
.HasColumnType("datetime2");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<TimeSpan>("PreparationTime") b.Property<TimeSpan>("PreparationTime")
@@ -272,6 +280,9 @@ namespace Francesco.Recipes.World.Migrations
b.Property<DateTime>("CreatedAt") b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2"); .HasColumnType("datetime2");
b.Property<DateTime?>("ModifiedAt")
.HasColumnType("datetime2");
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("ShoppingLists"); b.ToTable("ShoppingLists");
@@ -284,9 +295,11 @@ namespace Francesco.Recipes.World.Migrations
.HasColumnType("uniqueidentifier"); .HasColumnType("uniqueidentifier");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<string>("Symbol") b.Property<string>("Symbol")
.IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.HasKey("Id"); b.HasKey("Id");
@@ -4,7 +4,7 @@
public class Category public class Category
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string? Name { get; set; } public string Name { get; set; }
public virtual ICollection<Recipe> Recipes { get; set; } = new List<Recipe>(); public virtual ICollection<Recipe> Recipes { get; set; } = new List<Recipe>();
} }
} }
@@ -7,8 +7,8 @@ namespace Francesco.Recipes.World.Models.BackendModels.Unit
public class Unit public class Unit
{ {
public Guid Id{ get; set; } public Guid Id{ get; set; }
public string? Name { get; set; } public string Name { get; set; }
public string? Symbol { get; set; } public string Symbol { get; set; }
public virtual ICollection<RecipeIngredient> RecipeIngredient { get; set; } = new List<RecipeIngredient>(); public virtual ICollection<RecipeIngredient> RecipeIngredient { get; set; } = new List<RecipeIngredient>();
} }
} }