summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/Elements.Data/ApplicationDbContext.cs5
-rw-r--r--backend/Elements.Data/Migrations/20231022191811_Initial.Designer.cs (renamed from backend/Elements.Data/Migrations/20231022135245_Initial.Designer.cs)68
-rw-r--r--backend/Elements.Data/Migrations/20231022191811_Initial.cs (renamed from backend/Elements.Data/Migrations/20231022135245_Initial.cs)60
-rw-r--r--backend/Elements.Data/Migrations/ApplicationDbContextModelSnapshot.cs66
-rw-r--r--backend/Elements.Data/Models/Suggestion.cs9
-rw-r--r--backend/Elements.Data/Models/User.cs6
-rw-r--r--backend/Elements.Data/Models/Vote.cs8
7 files changed, 176 insertions, 46 deletions
diff --git a/backend/Elements.Data/ApplicationDbContext.cs b/backend/Elements.Data/ApplicationDbContext.cs
index 2187feb..d971b4e 100644
--- a/backend/Elements.Data/ApplicationDbContext.cs
+++ b/backend/Elements.Data/ApplicationDbContext.cs
@@ -10,6 +10,7 @@ public class ApplicationDbContext : DbContext
public DbSet<User> Users { get; set; }
public DbSet<Suggestion> Suggestions { get; set; }
public DbSet<Recipe> Recipes { get; set; }
+ public DbSet<Vote> Votes { get; set; }
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
@@ -23,9 +24,7 @@ public class ApplicationDbContext : DbContext
{
Id = 1,
Name = "Elements",
- GoogleId = String.Empty,
- Elements = new List<Element>(),
- Suggestions = new List<Suggestion>()
+ GoogleId = String.Empty
});
byte[] fireData = Convert.FromBase64String("//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQ///cEP//3BD//9wQw==");
diff --git a/backend/Elements.Data/Migrations/20231022135245_Initial.Designer.cs b/backend/Elements.Data/Migrations/20231022191811_Initial.Designer.cs
index cb525bd..72f90f1 100644
--- a/backend/Elements.Data/Migrations/20231022135245_Initial.Designer.cs
+++ b/backend/Elements.Data/Migrations/20231022191811_Initial.Designer.cs
@@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Elements.Data.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
- [Migration("20231022135245_Initial")]
+ [Migration("20231022191811_Initial")]
partial class Initial
{
/// <inheritdoc />
@@ -113,7 +113,7 @@ namespace Elements.Data.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
- b.Property<int>("FirstIngredientId")
+ b.Property<int>("FirstElementId")
.HasColumnType("INTEGER");
b.Property<byte[]>("Icon")
@@ -124,23 +124,20 @@ namespace Elements.Data.Migrations
.IsRequired()
.HasColumnType("TEXT");
- b.Property<int>("SecondIngredientId")
+ b.Property<int>("SecondElementId")
.HasColumnType("INTEGER");
b.Property<int>("UserId")
.HasColumnType("INTEGER");
- b.Property<int>("Votes")
- .HasColumnType("INTEGER");
-
b.Property<DateTime>("VotingEnd")
.HasColumnType("TEXT");
b.HasKey("Id");
- b.HasIndex("FirstIngredientId");
+ b.HasIndex("FirstElementId");
- b.HasIndex("SecondIngredientId");
+ b.HasIndex("SecondElementId");
b.HasIndex("UserId");
@@ -174,6 +171,27 @@ namespace Elements.Data.Migrations
});
});
+ modelBuilder.Entity("Elements.Data.Models.Vote", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property<int>("SuggestionId")
+ .HasColumnType("INTEGER");
+
+ b.Property<int>("UserId")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Id");
+
+ b.HasIndex("SuggestionId");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("Votes");
+ });
+
modelBuilder.Entity("Elements.Data.Models.Element", b =>
{
b.HasOne("Elements.Data.Models.User", "User")
@@ -214,15 +232,15 @@ namespace Elements.Data.Migrations
modelBuilder.Entity("Elements.Data.Models.Suggestion", b =>
{
- b.HasOne("Elements.Data.Models.Element", "FirstIngredient")
+ b.HasOne("Elements.Data.Models.Element", "FirstElement")
.WithMany()
- .HasForeignKey("FirstIngredientId")
+ .HasForeignKey("FirstElementId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
- b.HasOne("Elements.Data.Models.Element", "SecondIngredient")
+ b.HasOne("Elements.Data.Models.Element", "SecondElement")
.WithMany()
- .HasForeignKey("SecondIngredientId")
+ .HasForeignKey("SecondElementId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -232,9 +250,29 @@ namespace Elements.Data.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
- b.Navigation("FirstIngredient");
+ b.Navigation("FirstElement");
- b.Navigation("SecondIngredient");
+ b.Navigation("SecondElement");
+ });
+
+ modelBuilder.Entity("Elements.Data.Models.Vote", b =>
+ {
+ b.HasOne("Elements.Data.Models.Suggestion", null)
+ .WithMany("Votes")
+ .HasForeignKey("SuggestionId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("Elements.Data.Models.User", null)
+ .WithMany("Votes")
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+ });
+
+ modelBuilder.Entity("Elements.Data.Models.Suggestion", b =>
+ {
+ b.Navigation("Votes");
});
modelBuilder.Entity("Elements.Data.Models.User", b =>
@@ -242,6 +280,8 @@ namespace Elements.Data.Migrations
b.Navigation("Elements");
b.Navigation("Suggestions");
+
+ b.Navigation("Votes");
});
#pragma warning restore 612, 618
}
diff --git a/backend/Elements.Data/Migrations/20231022135245_Initial.cs b/backend/Elements.Data/Migrations/20231022191811_Initial.cs
index 1b203db..5885c27 100644
--- a/backend/Elements.Data/Migrations/20231022135245_Initial.cs
+++ b/backend/Elements.Data/Migrations/20231022191811_Initial.cs
@@ -90,24 +90,23 @@ namespace Elements.Data.Migrations
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
Icon = table.Column<byte[]>(type: "BLOB", nullable: false),
- FirstIngredientId = table.Column<int>(type: "INTEGER", nullable: false),
- SecondIngredientId = table.Column<int>(type: "INTEGER", nullable: false),
+ FirstElementId = table.Column<int>(type: "INTEGER", nullable: false),
+ SecondElementId = table.Column<int>(type: "INTEGER", nullable: false),
VotingEnd = table.Column<DateTime>(type: "TEXT", nullable: false),
- Votes = table.Column<int>(type: "INTEGER", nullable: false),
UserId = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Suggestions", x => x.Id);
table.ForeignKey(
- name: "FK_Suggestions_Elements_FirstIngredientId",
- column: x => x.FirstIngredientId,
+ name: "FK_Suggestions_Elements_FirstElementId",
+ column: x => x.FirstElementId,
principalTable: "Elements",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
- name: "FK_Suggestions_Elements_SecondIngredientId",
- column: x => x.SecondIngredientId,
+ name: "FK_Suggestions_Elements_SecondElementId",
+ column: x => x.SecondElementId,
principalTable: "Elements",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
@@ -119,6 +118,32 @@ namespace Elements.Data.Migrations
onDelete: ReferentialAction.Cascade);
});
+ migrationBuilder.CreateTable(
+ name: "Votes",
+ columns: table => new
+ {
+ Id = table.Column<int>(type: "INTEGER", nullable: false)
+ .Annotation("Sqlite:Autoincrement", true),
+ UserId = table.Column<int>(type: "INTEGER", nullable: false),
+ SuggestionId = table.Column<int>(type: "INTEGER", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Votes", x => x.Id);
+ table.ForeignKey(
+ name: "FK_Votes_Suggestions_SuggestionId",
+ column: x => x.SuggestionId,
+ principalTable: "Suggestions",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_Votes_Users_UserId",
+ column: x => x.UserId,
+ principalTable: "Users",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
migrationBuilder.InsertData(
table: "Users",
columns: new[] { "Id", "GoogleId", "Name" },
@@ -156,19 +181,29 @@ namespace Elements.Data.Migrations
column: "SecondIngredientId");
migrationBuilder.CreateIndex(
- name: "IX_Suggestions_FirstIngredientId",
+ name: "IX_Suggestions_FirstElementId",
table: "Suggestions",
- column: "FirstIngredientId");
+ column: "FirstElementId");
migrationBuilder.CreateIndex(
- name: "IX_Suggestions_SecondIngredientId",
+ name: "IX_Suggestions_SecondElementId",
table: "Suggestions",
- column: "SecondIngredientId");
+ column: "SecondElementId");
migrationBuilder.CreateIndex(
name: "IX_Suggestions_UserId",
table: "Suggestions",
column: "UserId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Votes_SuggestionId",
+ table: "Votes",
+ column: "SuggestionId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Votes_UserId",
+ table: "Votes",
+ column: "UserId");
}
/// <inheritdoc />
@@ -178,6 +213,9 @@ namespace Elements.Data.Migrations
name: "Recipes");
migrationBuilder.DropTable(
+ name: "Votes");
+
+ migrationBuilder.DropTable(
name: "Suggestions");
migrationBuilder.DropTable(
diff --git a/backend/Elements.Data/Migrations/ApplicationDbContextModelSnapshot.cs b/backend/Elements.Data/Migrations/ApplicationDbContextModelSnapshot.cs
index 095839f..5964a6c 100644
--- a/backend/Elements.Data/Migrations/ApplicationDbContextModelSnapshot.cs
+++ b/backend/Elements.Data/Migrations/ApplicationDbContextModelSnapshot.cs
@@ -110,7 +110,7 @@ namespace Elements.Data.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
- b.Property<int>("FirstIngredientId")
+ b.Property<int>("FirstElementId")
.HasColumnType("INTEGER");
b.Property<byte[]>("Icon")
@@ -121,23 +121,20 @@ namespace Elements.Data.Migrations
.IsRequired()
.HasColumnType("TEXT");
- b.Property<int>("SecondIngredientId")
+ b.Property<int>("SecondElementId")
.HasColumnType("INTEGER");
b.Property<int>("UserId")
.HasColumnType("INTEGER");
- b.Property<int>("Votes")
- .HasColumnType("INTEGER");
-
b.Property<DateTime>("VotingEnd")
.HasColumnType("TEXT");
b.HasKey("Id");
- b.HasIndex("FirstIngredientId");
+ b.HasIndex("FirstElementId");
- b.HasIndex("SecondIngredientId");
+ b.HasIndex("SecondElementId");
b.HasIndex("UserId");
@@ -171,6 +168,27 @@ namespace Elements.Data.Migrations
});
});
+ modelBuilder.Entity("Elements.Data.Models.Vote", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property<int>("SuggestionId")
+ .HasColumnType("INTEGER");
+
+ b.Property<int>("UserId")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Id");
+
+ b.HasIndex("SuggestionId");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("Votes");
+ });
+
modelBuilder.Entity("Elements.Data.Models.Element", b =>
{
b.HasOne("Elements.Data.Models.User", "User")
@@ -211,15 +229,15 @@ namespace Elements.Data.Migrations
modelBuilder.Entity("Elements.Data.Models.Suggestion", b =>
{
- b.HasOne("Elements.Data.Models.Element", "FirstIngredient")
+ b.HasOne("Elements.Data.Models.Element", "FirstElement")
.WithMany()
- .HasForeignKey("FirstIngredientId")
+ .HasForeignKey("FirstElementId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
- b.HasOne("Elements.Data.Models.Element", "SecondIngredient")
+ b.HasOne("Elements.Data.Models.Element", "SecondElement")
.WithMany()
- .HasForeignKey("SecondIngredientId")
+ .HasForeignKey("SecondElementId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -229,9 +247,29 @@ namespace Elements.Data.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
- b.Navigation("FirstIngredient");
+ b.Navigation("FirstElement");
- b.Navigation("SecondIngredient");
+ b.Navigation("SecondElement");
+ });
+
+ modelBuilder.Entity("Elements.Data.Models.Vote", b =>
+ {
+ b.HasOne("Elements.Data.Models.Suggestion", null)
+ .WithMany("Votes")
+ .HasForeignKey("SuggestionId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("Elements.Data.Models.User", null)
+ .WithMany("Votes")
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+ });
+
+ modelBuilder.Entity("Elements.Data.Models.Suggestion", b =>
+ {
+ b.Navigation("Votes");
});
modelBuilder.Entity("Elements.Data.Models.User", b =>
@@ -239,6 +277,8 @@ namespace Elements.Data.Migrations
b.Navigation("Elements");
b.Navigation("Suggestions");
+
+ b.Navigation("Votes");
});
#pragma warning restore 612, 618
}
diff --git a/backend/Elements.Data/Models/Suggestion.cs b/backend/Elements.Data/Models/Suggestion.cs
index 3d626fc..bd936a4 100644
--- a/backend/Elements.Data/Models/Suggestion.cs
+++ b/backend/Elements.Data/Models/Suggestion.cs
@@ -5,9 +5,12 @@ public class Suggestion
public int Id { get; set; }
public required string Name { get; init; }
public required byte[] Icon { get; init; }
- public required Element FirstIngredient { get; init; }
- public required Element SecondIngredient { get; init; }
+ public required int FirstElementId { get; init; }
+ public required int SecondElementId { get; init; }
public required DateTime VotingEnd { get; init; }
- public required int Votes { get; set; } = 1;
public required int UserId { get; init; }
+
+ public Element FirstElement { get; set; } = null!;
+ public Element SecondElement { get; set; } = null!;
+ public ICollection<Vote> Votes { get; } = new List<Vote>();
} \ No newline at end of file
diff --git a/backend/Elements.Data/Models/User.cs b/backend/Elements.Data/Models/User.cs
index 63be88a..bf3231b 100644
--- a/backend/Elements.Data/Models/User.cs
+++ b/backend/Elements.Data/Models/User.cs
@@ -5,6 +5,8 @@ public class User
public int Id { get; set; }
public required string GoogleId { get; init; }
public required string Name { get; set; }
- public required ICollection<Element> Elements { get; set; }
- public required ICollection<Suggestion> Suggestions { get; set; }
+
+ public ICollection<Element> Elements { get; } = new List<Element>();
+ public ICollection<Suggestion> Suggestions { get; } = new List<Suggestion>();
+ public ICollection<Vote> Votes { get; } = new List<Vote>();
} \ No newline at end of file
diff --git a/backend/Elements.Data/Models/Vote.cs b/backend/Elements.Data/Models/Vote.cs
new file mode 100644
index 0000000..2979692
--- /dev/null
+++ b/backend/Elements.Data/Models/Vote.cs
@@ -0,0 +1,8 @@
+namespace Elements.Data.Models;
+
+public class Vote
+{
+ public int Id { get; set; }
+ public required int UserId { get; init; }
+ public required int SuggestionId { get; set; }
+} \ No newline at end of file