From ccef80f0d9abe9fbb55d90d65182bbfb47b268ca Mon Sep 17 00:00:00 2001 From: jvyden Date: Mon, 8 Nov 2021 00:49:02 -0500 Subject: [PATCH] Implement more counts belonging to users, remove counts from db --- ...54552_RemoveCountsFromDatabase.Designer.cs | 519 ++++++++++++++++++ ...20211108054552_RemoveCountsFromDatabase.cs | 90 +++ .../Migrations/DatabaseModelSnapshot.cs | 21 - ProjectLighthouse/Types/User.cs | 52 +- 4 files changed, 649 insertions(+), 33 deletions(-) create mode 100644 ProjectLighthouse/Migrations/20211108054552_RemoveCountsFromDatabase.Designer.cs create mode 100644 ProjectLighthouse/Migrations/20211108054552_RemoveCountsFromDatabase.cs diff --git a/ProjectLighthouse/Migrations/20211108054552_RemoveCountsFromDatabase.Designer.cs b/ProjectLighthouse/Migrations/20211108054552_RemoveCountsFromDatabase.Designer.cs new file mode 100644 index 00000000..4d2d382f --- /dev/null +++ b/ProjectLighthouse/Migrations/20211108054552_RemoveCountsFromDatabase.Designer.cs @@ -0,0 +1,519 @@ +// +using LBPUnion.ProjectLighthouse; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace ProjectLighthouse.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20211108054552_RemoveCountsFromDatabase")] + partial class RemoveCountsFromDatabase + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 64) + .HasAnnotation("ProductVersion", "5.0.12"); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.HeartedProfile", b => + { + b.Property("HeartedProfileId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("HeartedUserId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("HeartedProfileId"); + + b.HasIndex("HeartedUserId"); + + b.HasIndex("UserId"); + + b.ToTable("HeartedProfiles"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Levels.HeartedLevel", b => + { + b.Property("HeartedLevelId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("SlotId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("HeartedLevelId"); + + b.HasIndex("SlotId"); + + b.HasIndex("UserId"); + + b.ToTable("HeartedLevels"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Levels.QueuedLevel", b => + { + b.Property("QueuedLevelId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("SlotId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("QueuedLevelId"); + + b.HasIndex("SlotId"); + + b.HasIndex("UserId"); + + b.ToTable("QueuedLevels"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Levels.Slot", b => + { + b.Property("SlotId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("AuthorLabels") + .HasColumnType("longtext"); + + b.Property("BackgroundHash") + .HasColumnType("longtext"); + + b.Property("CreatorId") + .HasColumnType("int"); + + b.Property("Description") + .HasColumnType("longtext"); + + b.Property("FirstUploaded") + .HasColumnType("bigint"); + + b.Property("GameVersion") + .HasColumnType("int"); + + b.Property("IconHash") + .HasColumnType("longtext"); + + b.Property("InitiallyLocked") + .HasColumnType("tinyint(1)"); + + b.Property("LastUpdated") + .HasColumnType("bigint"); + + b.Property("Lbp1Only") + .HasColumnType("tinyint(1)"); + + b.Property("LocationId") + .HasColumnType("int"); + + b.Property("MaximumPlayers") + .HasColumnType("int"); + + b.Property("MinimumPlayers") + .HasColumnType("int"); + + b.Property("MoveRequired") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .HasColumnType("longtext"); + + b.Property("Plays") + .HasColumnType("int"); + + b.Property("ResourceCollection") + .HasColumnType("longtext"); + + b.Property("RootLevel") + .HasColumnType("longtext"); + + b.Property("Shareable") + .HasColumnType("int"); + + b.Property("SubLevel") + .HasColumnType("tinyint(1)"); + + b.Property("TeamPick") + .HasColumnType("tinyint(1)"); + + b.HasKey("SlotId"); + + b.HasIndex("CreatorId"); + + b.HasIndex("LocationId"); + + b.ToTable("Slots"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Photo", b => + { + b.Property("PhotoId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("CreatorId") + .HasColumnType("int"); + + b.Property("LargeHash") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("MediumHash") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("PhotoSubjectCollection") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("PlanHash") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("SmallHash") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Timestamp") + .HasColumnType("bigint"); + + b.HasKey("PhotoId"); + + b.HasIndex("CreatorId"); + + b.ToTable("Photos"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.PhotoSubject", b => + { + b.Property("PhotoSubjectId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Bounds") + .HasColumnType("longtext"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("PhotoSubjectId"); + + b.HasIndex("UserId"); + + b.ToTable("PhotoSubjects"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Profiles.Comment", b => + { + b.Property("CommentId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Message") + .HasColumnType("longtext"); + + b.Property("PosterUserId") + .HasColumnType("int"); + + b.Property("TargetUserId") + .HasColumnType("int"); + + b.Property("ThumbsDown") + .HasColumnType("int"); + + b.Property("ThumbsUp") + .HasColumnType("int"); + + b.Property("Timestamp") + .HasColumnType("bigint"); + + b.HasKey("CommentId"); + + b.HasIndex("PosterUserId"); + + b.HasIndex("TargetUserId"); + + b.ToTable("Comments"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Profiles.LastMatch", b => + { + b.Property("UserId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Timestamp") + .HasColumnType("bigint"); + + b.HasKey("UserId"); + + b.ToTable("LastMatches"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Profiles.Location", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("X") + .HasColumnType("int"); + + b.Property("Y") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Locations"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Score", b => + { + b.Property("ScoreId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("PlayerIdCollection") + .HasColumnType("longtext"); + + b.Property("Points") + .HasColumnType("int"); + + b.Property("SlotId") + .HasColumnType("int"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("ScoreId"); + + b.HasIndex("SlotId"); + + b.ToTable("Scores"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Token", b => + { + b.Property("TokenId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("GameVersion") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.Property("UserToken") + .HasColumnType("longtext"); + + b.HasKey("TokenId"); + + b.ToTable("Tokens"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.User", b => + { + b.Property("UserId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Biography") + .HasColumnType("longtext"); + + b.Property("BooHash") + .HasColumnType("longtext"); + + b.Property("Game") + .HasColumnType("int"); + + b.Property("IconHash") + .HasColumnType("longtext"); + + b.Property("LocationId") + .HasColumnType("int"); + + b.Property("Pins") + .HasColumnType("longtext"); + + b.Property("PlanetHash") + .HasColumnType("longtext"); + + b.Property("StaffChallengeBronzeCount") + .HasColumnType("int"); + + b.Property("StaffChallengeGoldCount") + .HasColumnType("int"); + + b.Property("StaffChallengeSilverCount") + .HasColumnType("int"); + + b.Property("Username") + .HasColumnType("longtext"); + + b.Property("YayHash") + .HasColumnType("longtext"); + + b.HasKey("UserId"); + + b.HasIndex("LocationId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.HeartedProfile", b => + { + b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "HeartedUser") + .WithMany() + .HasForeignKey("HeartedUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("HeartedUser"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Levels.HeartedLevel", b => + { + b.HasOne("LBPUnion.ProjectLighthouse.Types.Levels.Slot", "Slot") + .WithMany() + .HasForeignKey("SlotId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Slot"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Levels.QueuedLevel", b => + { + b.HasOne("LBPUnion.ProjectLighthouse.Types.Levels.Slot", "Slot") + .WithMany() + .HasForeignKey("SlotId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Slot"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Levels.Slot", b => + { + b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LBPUnion.ProjectLighthouse.Types.Profiles.Location", "Location") + .WithMany() + .HasForeignKey("LocationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("Location"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Photo", b => + { + b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.PhotoSubject", b => + { + b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Profiles.Comment", b => + { + b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "Poster") + .WithMany() + .HasForeignKey("PosterUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "Target") + .WithMany() + .HasForeignKey("TargetUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Poster"); + + b.Navigation("Target"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Score", b => + { + b.HasOne("LBPUnion.ProjectLighthouse.Types.Levels.Slot", "Slot") + .WithMany() + .HasForeignKey("SlotId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Slot"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.User", b => + { + b.HasOne("LBPUnion.ProjectLighthouse.Types.Profiles.Location", "Location") + .WithMany() + .HasForeignKey("LocationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Location"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ProjectLighthouse/Migrations/20211108054552_RemoveCountsFromDatabase.cs b/ProjectLighthouse/Migrations/20211108054552_RemoveCountsFromDatabase.cs new file mode 100644 index 00000000..829e9ba5 --- /dev/null +++ b/ProjectLighthouse/Migrations/20211108054552_RemoveCountsFromDatabase.cs @@ -0,0 +1,90 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace ProjectLighthouse.Migrations +{ + public partial class RemoveCountsFromDatabase : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "CommentCount", + table: "Users"); + + migrationBuilder.DropColumn( + name: "FavouriteSlotCount", + table: "Users"); + + migrationBuilder.DropColumn( + name: "FavouriteUserCount", + table: "Users"); + + migrationBuilder.DropColumn( + name: "HeartCount", + table: "Users"); + + migrationBuilder.DropColumn( + name: "Lists", + table: "Users"); + + migrationBuilder.DropColumn( + name: "LolCatFtwCount", + table: "Users"); + + migrationBuilder.DropColumn( + name: "ReviewCount", + table: "Users"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "CommentCount", + table: "Users", + type: "int", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "FavouriteSlotCount", + table: "Users", + type: "int", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "FavouriteUserCount", + table: "Users", + type: "int", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "HeartCount", + table: "Users", + type: "int", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "Lists", + table: "Users", + type: "int", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "LolCatFtwCount", + table: "Users", + type: "int", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "ReviewCount", + table: "Users", + type: "int", + nullable: false, + defaultValue: 0); + } + } +} diff --git a/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs b/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs index 40961787..0c145dc5 100644 --- a/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs +++ b/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs @@ -336,42 +336,21 @@ namespace ProjectLighthouse.Migrations b.Property("BooHash") .HasColumnType("longtext"); - b.Property("CommentCount") - .HasColumnType("int"); - - b.Property("FavouriteSlotCount") - .HasColumnType("int"); - - b.Property("FavouriteUserCount") - .HasColumnType("int"); - b.Property("Game") .HasColumnType("int"); - b.Property("HeartCount") - .HasColumnType("int"); - b.Property("IconHash") .HasColumnType("longtext"); - b.Property("Lists") - .HasColumnType("int"); - b.Property("LocationId") .HasColumnType("int"); - b.Property("LolCatFtwCount") - .HasColumnType("int"); - b.Property("Pins") .HasColumnType("longtext"); b.Property("PlanetHash") .HasColumnType("longtext"); - b.Property("ReviewCount") - .HasColumnType("int"); - b.Property("StaffChallengeBronzeCount") .HasColumnType("int"); diff --git a/ProjectLighthouse/Types/User.cs b/ProjectLighthouse/Types/User.cs index dec3dc2c..84713eef 100644 --- a/ProjectLighthouse/Types/User.cs +++ b/ProjectLighthouse/Types/User.cs @@ -8,15 +8,15 @@ namespace LBPUnion.ProjectLighthouse.Types { public class User { - -// [NotMapped] public readonly ClientsConnected ClientsConnected = new(); public int UserId { get; set; } public string Username { get; set; } public string IconHash { get; set; } public int Game { get; set; } + + [NotMapped] public int Lists { get; set; } - public int HeartCount { get; set; } + public string YayHash { get; set; } public string BooHash { get; set; } @@ -25,8 +25,16 @@ namespace LBPUnion.ProjectLighthouse.Types /// public string Biography { get; set; } - public int ReviewCount { get; set; } - public int CommentCount { get; set; } + [NotMapped] + public int ReviewCount => 0; + + [NotMapped] + public int CommentCount { + get { + using Database database = new(); + return database.Comments.Count(c => c.PosterUserId == this.UserId); + } + } [NotMapped] public int PhotosByMeCount { @@ -52,9 +60,30 @@ namespace LBPUnion.ProjectLighthouse.Types [ForeignKey("LocationId")] public Location Location { get; set; } - public int FavouriteSlotCount { get; set; } - public int FavouriteUserCount { get; set; } - public int LolCatFtwCount { get; set; } + [NotMapped] + public int HeartedLevels { + get { + using Database database = new(); + return database.HeartedLevels.Count(p => p.UserId == this.UserId); + } + } + + [NotMapped] + public int HeartedUsers { + get { + using Database database = new(); + return database.HeartedProfiles.Count(p => p.UserId == this.UserId); + } + } + + [NotMapped] + public int QueuedLevelsCount { + get { + using Database database = new(); + return database.QueuedLevels.Count(p => p.UserId == this.UserId); + } + } + public string Pins { get; set; } = ""; public int StaffChallengeGoldCount { get; set; } public int StaffChallengeSilverCount { get; set; } @@ -77,7 +106,6 @@ namespace LBPUnion.ProjectLighthouse.Types this.SerializeSlots() + LbpSerializer.StringElement("lists", this.Lists) + LbpSerializer.StringElement("lists_quota", ServerSettings.ListsQuota) + // technically not a part of the user but LBP expects it - LbpSerializer.StringElement("heartCount", this.HeartCount) + LbpSerializer.StringElement("yay2", this.YayHash) + LbpSerializer.StringElement("boo2", this.BooHash) + LbpSerializer.StringElement("biography", this.Biography) + @@ -87,9 +115,9 @@ namespace LBPUnion.ProjectLighthouse.Types LbpSerializer.StringElement("photosWithMeCount", this.PhotosWithMeCount) + LbpSerializer.StringElement("commentsEnabled", "true") + LbpSerializer.StringElement("location", this.Location.Serialize()) + - LbpSerializer.StringElement("favouriteSlotCount", this.FavouriteSlotCount) + - LbpSerializer.StringElement("favouriteUserCount", this.FavouriteUserCount) + - LbpSerializer.StringElement("lolcatftwCount", this.LolCatFtwCount) + + LbpSerializer.StringElement("favouriteSlotCount", this.HeartedLevels) + + LbpSerializer.StringElement("favouriteUserCount", this.HeartedUsers) + + LbpSerializer.StringElement("lolcatftwCount", this.QueuedLevelsCount) + LbpSerializer.StringElement("pins", this.Pins) + LbpSerializer.StringElement("staffChallengeGoldCount", this.StaffChallengeGoldCount) + LbpSerializer.StringElement("staffChallengeSilverCount", this.StaffChallengeSilverCount) +