feat: keep track of user submissions, refs #4
This commit is contained in:
		
							
								
								
									
										164
									
								
								song_of_the_day/Data/Migrations/20250524164159_keep track of users oicked for submission.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										164
									
								
								song_of_the_day/Data/Migrations/20250524164159_keep track of users oicked for submission.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,164 @@ | ||||
| // <auto-generated /> | ||||
| 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 | ||||
|     { | ||||
|         /// <inheritdoc /> | ||||
|         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<int>("SongId") | ||||
|                         .ValueGeneratedOnAdd() | ||||
|                         .HasColumnType("integer"); | ||||
|  | ||||
|                     NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("SongId")); | ||||
|  | ||||
|                     b.Property<string>("Artist") | ||||
|                         .HasColumnType("text"); | ||||
|  | ||||
|                     b.Property<string>("Name") | ||||
|                         .HasColumnType("text"); | ||||
|  | ||||
|                     b.Property<string>("Url") | ||||
|                         .HasColumnType("text"); | ||||
|  | ||||
|                     b.HasKey("SongId"); | ||||
|  | ||||
|                     b.ToTable("Songs"); | ||||
|                 }); | ||||
|  | ||||
|             modelBuilder.Entity("SongSuggestion", b => | ||||
|                 { | ||||
|                     b.Property<int>("Id") | ||||
|                         .ValueGeneratedOnAdd() | ||||
|                         .HasColumnType("integer"); | ||||
|  | ||||
|                     NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); | ||||
|  | ||||
|                     b.Property<DateTime>("Date") | ||||
|                         .HasColumnType("timestamp with time zone"); | ||||
|  | ||||
|                     b.Property<bool>("HasUsedSuggestion") | ||||
|                         .HasColumnType("boolean"); | ||||
|  | ||||
|                     b.Property<int?>("SongId") | ||||
|                         .HasColumnType("integer"); | ||||
|  | ||||
|                     b.Property<int>("SuggestionHelperId") | ||||
|                         .HasColumnType("integer"); | ||||
|  | ||||
|                     b.Property<bool>("UserHasSubmitted") | ||||
|                         .HasColumnType("boolean"); | ||||
|  | ||||
|                     b.Property<int?>("UserId") | ||||
|                         .HasColumnType("integer"); | ||||
|  | ||||
|                     b.HasKey("Id"); | ||||
|  | ||||
|                     b.HasIndex("SongId"); | ||||
|  | ||||
|                     b.HasIndex("SuggestionHelperId"); | ||||
|  | ||||
|                     b.HasIndex("UserId"); | ||||
|  | ||||
|                     b.ToTable("SongSuggestions"); | ||||
|                 }); | ||||
|  | ||||
|             modelBuilder.Entity("SuggestionHelper", b => | ||||
|                 { | ||||
|                     b.Property<int>("Id") | ||||
|                         .ValueGeneratedOnAdd() | ||||
|                         .HasColumnType("integer"); | ||||
|  | ||||
|                     NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); | ||||
|  | ||||
|                     b.Property<string>("Description") | ||||
|                         .HasColumnType("text"); | ||||
|  | ||||
|                     b.Property<string>("Title") | ||||
|                         .HasColumnType("text"); | ||||
|  | ||||
|                     b.HasKey("Id"); | ||||
|  | ||||
|                     b.ToTable("SuggestionHelpers"); | ||||
|                 }); | ||||
|  | ||||
|             modelBuilder.Entity("User", b => | ||||
|                 { | ||||
|                     b.Property<int>("UserId") | ||||
|                         .ValueGeneratedOnAdd() | ||||
|                         .HasColumnType("integer"); | ||||
|  | ||||
|                     NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("UserId")); | ||||
|  | ||||
|                     b.Property<bool>("AssociationInProgress") | ||||
|                         .HasColumnType("boolean"); | ||||
|  | ||||
|                     b.Property<bool>("IsIntroduced") | ||||
|                         .HasColumnType("boolean"); | ||||
|  | ||||
|                     b.Property<string>("LdapUserName") | ||||
|                         .HasColumnType("text"); | ||||
|  | ||||
|                     b.Property<string>("Name") | ||||
|                         .HasColumnType("text"); | ||||
|  | ||||
|                     b.Property<string>("NickName") | ||||
|                         .HasColumnType("text"); | ||||
|  | ||||
|                     b.Property<string>("SignalMemberId") | ||||
|                         .HasColumnType("text"); | ||||
|  | ||||
|                     b.Property<bool>("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 | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,82 @@ | ||||
| using Microsoft.EntityFrameworkCore.Migrations; | ||||
|  | ||||
| #nullable disable | ||||
|  | ||||
| namespace song_of_the_day.DataMigrations | ||||
| { | ||||
|     /// <inheritdoc /> | ||||
|     public partial class keeptrackofusersoickedforsubmission : Migration | ||||
|     { | ||||
|         /// <inheritdoc /> | ||||
|         protected override void Up(MigrationBuilder migrationBuilder) | ||||
|         { | ||||
|             migrationBuilder.RenameColumn( | ||||
|                 name: "Submitted", | ||||
|                 table: "SongSuggestions", | ||||
|                 newName: "UserHasSubmitted"); | ||||
|  | ||||
|             migrationBuilder.AddColumn<bool>( | ||||
|                 name: "WasChosenForSuggestionThisRound", | ||||
|                 table: "Users", | ||||
|                 type: "boolean", | ||||
|                 nullable: false, | ||||
|                 defaultValue: false); | ||||
|  | ||||
|             migrationBuilder.AddColumn<bool>( | ||||
|                 name: "HasUsedSuggestion", | ||||
|                 table: "SongSuggestions", | ||||
|                 type: "boolean", | ||||
|                 nullable: false, | ||||
|                 defaultValue: false); | ||||
|  | ||||
|             migrationBuilder.AddColumn<int>( | ||||
|                 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); | ||||
|         } | ||||
|  | ||||
|         /// <inheritdoc /> | ||||
|         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"); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -54,10 +54,16 @@ namespace song_of_the_day.DataMigrations | ||||
|                     b.Property<DateTime>("Date") | ||||
|                         .HasColumnType("timestamp with time zone"); | ||||
|  | ||||
|                     b.Property<bool>("HasUsedSuggestion") | ||||
|                         .HasColumnType("boolean"); | ||||
|  | ||||
|                     b.Property<int?>("SongId") | ||||
|                         .HasColumnType("integer"); | ||||
|  | ||||
|                     b.Property<bool>("Submitted") | ||||
|                     b.Property<int>("SuggestionHelperId") | ||||
|                         .HasColumnType("integer"); | ||||
|  | ||||
|                     b.Property<bool>("UserHasSubmitted") | ||||
|                         .HasColumnType("boolean"); | ||||
|  | ||||
|                     b.Property<int?>("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<string>("SignalMemberId") | ||||
|                         .HasColumnType("text"); | ||||
|  | ||||
|                     b.Property<bool>("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 | ||||
|   | ||||
| @@ -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; } | ||||
| } | ||||
| @@ -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!"); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user