diff --git a/song_of_the_day/Data/Migrations/20250524164159_keep track of users oicked for submission.Designer.cs b/song_of_the_day/Data/Migrations/20250524164159_keep track of users oicked for submission.Designer.cs
new file mode 100644
index 0000000..a73706d
--- /dev/null
+++ b/song_of_the_day/Data/Migrations/20250524164159_keep track of users oicked for submission.Designer.cs
@@ -0,0 +1,164 @@
+//
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace song_of_the_day.DataMigrations
+{
+ [DbContext(typeof(DataContext))]
+ [Migration("20250524164159_keep track of users oicked for submission")]
+ partial class keeptrackofusersoickedforsubmission
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "9.0.3")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("Song", b =>
+ {
+ b.Property("SongId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("SongId"));
+
+ b.Property("Artist")
+ .HasColumnType("text");
+
+ b.Property("Name")
+ .HasColumnType("text");
+
+ b.Property("Url")
+ .HasColumnType("text");
+
+ b.HasKey("SongId");
+
+ b.ToTable("Songs");
+ });
+
+ modelBuilder.Entity("SongSuggestion", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Date")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("HasUsedSuggestion")
+ .HasColumnType("boolean");
+
+ b.Property("SongId")
+ .HasColumnType("integer");
+
+ b.Property("SuggestionHelperId")
+ .HasColumnType("integer");
+
+ b.Property("UserHasSubmitted")
+ .HasColumnType("boolean");
+
+ b.Property("UserId")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.HasIndex("SongId");
+
+ b.HasIndex("SuggestionHelperId");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("SongSuggestions");
+ });
+
+ modelBuilder.Entity("SuggestionHelper", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Description")
+ .HasColumnType("text");
+
+ b.Property("Title")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("SuggestionHelpers");
+ });
+
+ modelBuilder.Entity("User", b =>
+ {
+ b.Property("UserId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("UserId"));
+
+ b.Property("AssociationInProgress")
+ .HasColumnType("boolean");
+
+ b.Property("IsIntroduced")
+ .HasColumnType("boolean");
+
+ b.Property("LdapUserName")
+ .HasColumnType("text");
+
+ b.Property("Name")
+ .HasColumnType("text");
+
+ b.Property("NickName")
+ .HasColumnType("text");
+
+ b.Property("SignalMemberId")
+ .HasColumnType("text");
+
+ b.Property("WasChosenForSuggestionThisRound")
+ .HasColumnType("boolean");
+
+ b.HasKey("UserId");
+
+ b.ToTable("Users");
+ });
+
+ modelBuilder.Entity("SongSuggestion", b =>
+ {
+ b.HasOne("Song", "Song")
+ .WithMany()
+ .HasForeignKey("SongId");
+
+ b.HasOne("SuggestionHelper", "SuggestionHelper")
+ .WithMany()
+ .HasForeignKey("SuggestionHelperId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("User", "User")
+ .WithMany()
+ .HasForeignKey("UserId");
+
+ b.Navigation("Song");
+
+ b.Navigation("SuggestionHelper");
+
+ b.Navigation("User");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/song_of_the_day/Data/Migrations/20250524164159_keep track of users oicked for submission.cs b/song_of_the_day/Data/Migrations/20250524164159_keep track of users oicked for submission.cs
new file mode 100644
index 0000000..8d9441a
--- /dev/null
+++ b/song_of_the_day/Data/Migrations/20250524164159_keep track of users oicked for submission.cs
@@ -0,0 +1,82 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace song_of_the_day.DataMigrations
+{
+ ///
+ public partial class keeptrackofusersoickedforsubmission : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.RenameColumn(
+ name: "Submitted",
+ table: "SongSuggestions",
+ newName: "UserHasSubmitted");
+
+ migrationBuilder.AddColumn(
+ name: "WasChosenForSuggestionThisRound",
+ table: "Users",
+ type: "boolean",
+ nullable: false,
+ defaultValue: false);
+
+ migrationBuilder.AddColumn(
+ name: "HasUsedSuggestion",
+ table: "SongSuggestions",
+ type: "boolean",
+ nullable: false,
+ defaultValue: false);
+
+ migrationBuilder.AddColumn(
+ name: "SuggestionHelperId",
+ table: "SongSuggestions",
+ type: "integer",
+ nullable: false,
+ defaultValue: 0);
+
+ migrationBuilder.CreateIndex(
+ name: "IX_SongSuggestions_SuggestionHelperId",
+ table: "SongSuggestions",
+ column: "SuggestionHelperId");
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_SongSuggestions_SuggestionHelpers_SuggestionHelperId",
+ table: "SongSuggestions",
+ column: "SuggestionHelperId",
+ principalTable: "SuggestionHelpers",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_SongSuggestions_SuggestionHelpers_SuggestionHelperId",
+ table: "SongSuggestions");
+
+ migrationBuilder.DropIndex(
+ name: "IX_SongSuggestions_SuggestionHelperId",
+ table: "SongSuggestions");
+
+ migrationBuilder.DropColumn(
+ name: "WasChosenForSuggestionThisRound",
+ table: "Users");
+
+ migrationBuilder.DropColumn(
+ name: "HasUsedSuggestion",
+ table: "SongSuggestions");
+
+ migrationBuilder.DropColumn(
+ name: "SuggestionHelperId",
+ table: "SongSuggestions");
+
+ migrationBuilder.RenameColumn(
+ name: "UserHasSubmitted",
+ table: "SongSuggestions",
+ newName: "Submitted");
+ }
+ }
+}
diff --git a/song_of_the_day/Data/Migrations/DataContextModelSnapshot.cs b/song_of_the_day/Data/Migrations/DataContextModelSnapshot.cs
index 59cf79b..0c486bf 100644
--- a/song_of_the_day/Data/Migrations/DataContextModelSnapshot.cs
+++ b/song_of_the_day/Data/Migrations/DataContextModelSnapshot.cs
@@ -54,10 +54,16 @@ namespace song_of_the_day.DataMigrations
b.Property("Date")
.HasColumnType("timestamp with time zone");
+ b.Property("HasUsedSuggestion")
+ .HasColumnType("boolean");
+
b.Property("SongId")
.HasColumnType("integer");
- b.Property("Submitted")
+ b.Property("SuggestionHelperId")
+ .HasColumnType("integer");
+
+ b.Property("UserHasSubmitted")
.HasColumnType("boolean");
b.Property("UserId")
@@ -67,6 +73,8 @@ namespace song_of_the_day.DataMigrations
b.HasIndex("SongId");
+ b.HasIndex("SuggestionHelperId");
+
b.HasIndex("UserId");
b.ToTable("SongSuggestions");
@@ -117,6 +125,9 @@ namespace song_of_the_day.DataMigrations
b.Property("SignalMemberId")
.HasColumnType("text");
+ b.Property("WasChosenForSuggestionThisRound")
+ .HasColumnType("boolean");
+
b.HasKey("UserId");
b.ToTable("Users");
@@ -128,12 +139,20 @@ namespace song_of_the_day.DataMigrations
.WithMany()
.HasForeignKey("SongId");
+ b.HasOne("SuggestionHelper", "SuggestionHelper")
+ .WithMany()
+ .HasForeignKey("SuggestionHelperId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
b.HasOne("User", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("Song");
+ b.Navigation("SuggestionHelper");
+
b.Navigation("User");
});
#pragma warning restore 612, 618
diff --git a/song_of_the_day/Data/User.cs b/song_of_the_day/Data/User.cs
index ff37817..67f9e67 100644
--- a/song_of_the_day/Data/User.cs
+++ b/song_of_the_day/Data/User.cs
@@ -9,4 +9,5 @@ public class User
public bool IsIntroduced { get; set; }
public bool AssociationInProgress { get; set; }
public string? LdapUserName { get; set; }
+ public bool WasChosenForSuggestionThisRound { get; set; }
}
\ No newline at end of file
diff --git a/song_of_the_day/Program.cs b/song_of_the_day/Program.cs
index a2df2ff..b2573fa 100644
--- a/song_of_the_day/Program.cs
+++ b/song_of_the_day/Program.cs
@@ -46,6 +46,7 @@ userCheckTimer.OnOccurence += async (s, ea) =>
IsIntroduced = false,
LdapUserName = string.Empty,
AssociationInProgress = false,
+ WasChosenForSuggestionThisRound = false,
};
dci.Users?.Add(newUser);
needsSaving = true;
@@ -110,7 +111,16 @@ pickOfTheDayTimer.OnOccurence += async (s, ea) =>
await dci.DisposeAsync();
return;
}
- var luckyUser = await dci.Users.ElementAtAsync((new Random()).Next(await dci.Users.CountAsync()));
+ var potentialUsers = dci.Users.Where(u => !u.WasChosenForSuggestionThisRound);
+ if (!potentialUsers.Any())
+ {
+ Console.WriteLine("Resetting suggestion count on users before resuming");
+ await dci.Users.ForEachAsync(u => u.WasChosenForSuggestionThisRound = false);
+ await dci.SaveChangesAsync();
+ potentialUsers = dci.Users.Where(u => !u.WasChosenForSuggestionThisRound);
+ }
+ Console.WriteLine("Today's pool of pickable users is: " + string.Join(", ", potentialUsers.Select(u => u.Name)));
+ var luckyUser = potentialUsers.ElementAt((new Random()).Next(potentialUsers.Count()));
if (luckyUser == null)
{
Console.WriteLine("Unable to determine today's lucky user!");