From c96d34fc6aff8513d9008fb076d34b8fe9484cd2 Mon Sep 17 00:00:00 2001 From: Sarah Faey Date: Mon, 5 Dec 2022 14:28:04 +0100 Subject: [PATCH] removed RaidLogs --- Lieb/Data/LiebContext.cs | 2 - Lieb/Data/RaidService.cs | 29 - Lieb/Data/RaidTemplateService.cs | 21 +- Lieb/Data/UserService.cs | 7 - .../20221205132556_RemovedRaidLog.Designer.cs | 633 ++++++++++++++++++ .../20221205132556_RemovedRaidLog.cs | 67 ++ Lieb/Migrations/LiebContextModelSnapshot.cs | 61 -- Lieb/Models/GuildWars2/Raid/Raid.cs | 2 - Lieb/Models/GuildWars2/Raid/RaidLog.cs | 75 --- Lieb/Models/GuildWars2/Raid/RaidTemplate.cs | 2 - 10 files changed, 701 insertions(+), 198 deletions(-) create mode 100644 Lieb/Migrations/20221205132556_RemovedRaidLog.Designer.cs create mode 100644 Lieb/Migrations/20221205132556_RemovedRaidLog.cs delete mode 100644 Lieb/Models/GuildWars2/Raid/RaidLog.cs diff --git a/Lieb/Data/LiebContext.cs b/Lieb/Data/LiebContext.cs index 2416627..1d0a1ce 100644 --- a/Lieb/Data/LiebContext.cs +++ b/Lieb/Data/LiebContext.cs @@ -24,7 +24,6 @@ namespace Lieb.Data public DbSet RaidTemplates { get; set; } public DbSet RaidReminders { get; set; } public DbSet RaidSignUps { get; set; } - public DbSet RaidLogs { get; set; } public DbSet DiscordRaidMessages { get; set; } public DbSet DiscordSettings { get; set; } @@ -42,7 +41,6 @@ namespace Lieb.Data modelBuilder.Entity().ToTable("RaidTemplate"); modelBuilder.Entity().ToTable("RaidReminder"); modelBuilder.Entity().ToTable("RaidSignUp"); - modelBuilder.Entity().ToTable("RaidLog"); modelBuilder.Entity().ToTable("DiscordRaidMessage"); modelBuilder.Entity().ToTable("DiscordSettings"); } diff --git a/Lieb/Data/RaidService.cs b/Lieb/Data/RaidService.cs index 9753ce9..f53ff89 100644 --- a/Lieb/Data/RaidService.cs +++ b/Lieb/Data/RaidService.cs @@ -77,9 +77,6 @@ namespace Lieb.Data } } await context.SaveChangesAsync(); - RaidLog log = RaidLog.CreateRaidLog(changedBy, raid); - await context.RaidLogs.AddAsync(log); - await context.SaveChangesAsync(); await _discordService.PostRaidMessage(raid.RaidId); } } @@ -96,35 +93,16 @@ namespace Lieb.Data context.RaidSignUps.RemoveRange(raid.SignUps); context.RaidRoles.RemoveRange(raid.Roles); - context.RaidLogs.RemoveRange(raid.RaidLogs); context.RaidReminders.RemoveRange(raid.Reminders); context.DiscordRaidMessages.RemoveRange(raid.DiscordRaidMessages); await context.SaveChangesAsync(); raid.SignUps.Clear(); raid.Roles.Clear(); - raid.RaidLogs.Clear(); raid.Reminders.Clear(); raid.DiscordRaidMessages.Clear(); context.Raids.Remove(raid); await context.SaveChangesAsync(); - - if(userId != null) - { - LiebUser user = context.LiebUsers.FirstOrDefault(u => u.Id == userId); - if(user != null) - { - RaidLog logEntry = new RaidLog() - { - LogEntry = $"The Raid \"{raid.Title}\" was deleted by {user.Name}", - Time = DateTimeOffset.UtcNow, - Type = RaidLog.LogType.Raid, - UserId = userId - }; - context.RaidLogs.Add(logEntry); - await context.SaveChangesAsync(); - } - } } public async Task SignUp(int raidId, ulong liebUserId, int guildWars2AccountId, int plannedRoleId, SignUpType signUpType, ulong signedUpByUserId = 0) @@ -474,13 +452,6 @@ namespace Lieb.Data private async Task LogSignUp(RaidSignUp signUp, string userName, ulong signedUpBy = 0) { - ulong userId = signedUpBy > 0 ? signedUpBy : signUp.LiebUserId.Value; - RaidLog log = RaidLog.CreateSignUpLog(userId, signUp, userName); - - using var context = _contextFactory.CreateDbContext(); - await context.RaidLogs.AddAsync(log); - await context.SaveChangesAsync(); - _ = SendDiscordSignUpLogMessage(signUp, userName, signedUpBy); } diff --git a/Lieb/Data/RaidTemplateService.cs b/Lieb/Data/RaidTemplateService.cs index 8e66b1b..78ec043 100644 --- a/Lieb/Data/RaidTemplateService.cs +++ b/Lieb/Data/RaidTemplateService.cs @@ -52,9 +52,6 @@ namespace Lieb.Data context.DiscordRaidMessages.RemoveRange(messagesToDelete); } await context.SaveChangesAsync(); - RaidLog log = RaidLog.CreateRaidTemplateLog(changedBy, template); - await context.RaidLogs.AddAsync(log); - await context.SaveChangesAsync(); } } @@ -65,28 +62,12 @@ namespace Lieb.Data context.RaidRoles.RemoveRange(template.Roles); context.RaidReminders.RemoveRange(template.Reminders); context.DiscordRaidMessages.RemoveRange(template.DiscordRaidMessages); - context.RaidLogs.RemoveRange(template.TemplateLogs); await context.SaveChangesAsync(); template.Roles.Clear(); template.Reminders.Clear(); template.DiscordRaidMessages.Clear(); - template.TemplateLogs.Clear(); context.RaidTemplates.Remove(template); - await context.SaveChangesAsync(); - - LiebUser user = context.LiebUsers.FirstOrDefault(u => u.Id == userId); - if(user != null) - { - RaidLog logEntry = new RaidLog() - { - LogEntry = $"The Template \"{template.Title}\" was deleted by {user.Name}", - Time = DateTimeOffset.UtcNow, - Type = RaidLog.LogType.RaidTemplate, - UserId = userId - }; - context.RaidLogs.Add(logEntry); - await context.SaveChangesAsync(); - } + await context.SaveChangesAsync(); } public async Task CreateRaidFromTemplate(int raidTempalteId) diff --git a/Lieb/Data/UserService.cs b/Lieb/Data/UserService.cs index 9f6e393..abbe901 100644 --- a/Lieb/Data/UserService.cs +++ b/Lieb/Data/UserService.cs @@ -129,13 +129,6 @@ namespace Lieb.Data await _discordService.PostRaidMessage(raidId); } - IEnumerable logs = context.RaidLogs.Where(r => r.UserId == userId); - foreach(RaidLog log in logs) - { - log.UserId = null; - } - await context.SaveChangesAsync(); - LiebUser user = GetLiebUser(userId); foreach(GuildWars2Account account in user.GuildWars2Accounts) { diff --git a/Lieb/Migrations/20221205132556_RemovedRaidLog.Designer.cs b/Lieb/Migrations/20221205132556_RemovedRaidLog.Designer.cs new file mode 100644 index 0000000..6ed8ba8 --- /dev/null +++ b/Lieb/Migrations/20221205132556_RemovedRaidLog.Designer.cs @@ -0,0 +1,633 @@ +// +using System; +using Lieb.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Lieb.Migrations +{ + [DbContext(typeof(LiebContext))] + [Migration("20221205132556_RemovedRaidLog")] + partial class RemovedRaidLog + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "6.0.10"); + + modelBuilder.Entity("Lieb.Models.DiscordSettings", b => + { + b.Property("DiscordSettingsId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ChangeUserNames") + .HasColumnType("INTEGER"); + + b.Property("DiscordLogChannel") + .HasColumnType("INTEGER"); + + b.HasKey("DiscordSettingsId"); + + b.ToTable("DiscordSettings", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Equipped", b => + { + b.Property("EquippedId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CanTank") + .HasColumnType("INTEGER"); + + b.Property("GuildWars2AccountId") + .HasColumnType("INTEGER"); + + b.Property("GuildWars2BuildId") + .HasColumnType("INTEGER"); + + b.HasKey("EquippedId"); + + b.HasIndex("GuildWars2AccountId"); + + b.HasIndex("GuildWars2BuildId"); + + b.ToTable("Equipped", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.GuildWars2Account", b => + { + b.Property("GuildWars2AccountId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("AccountName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ApiKey") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("LiebUserId") + .HasColumnType("INTEGER"); + + b.HasKey("GuildWars2AccountId"); + + b.HasIndex("LiebUserId"); + + b.ToTable("GuildWars2Account", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.GuildWars2Build", b => + { + b.Property("GuildWars2BuildId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Alacrity") + .HasColumnType("INTEGER"); + + b.Property("BuildName") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("TEXT"); + + b.Property("Class") + .HasColumnType("INTEGER"); + + b.Property("EliteSpecialization") + .HasColumnType("INTEGER"); + + b.Property("Heal") + .HasColumnType("INTEGER"); + + b.Property("Might") + .HasColumnType("INTEGER"); + + b.Property("Quickness") + .HasColumnType("INTEGER"); + + b.HasKey("GuildWars2BuildId"); + + b.ToTable("GuildWars2Build", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.DiscordRaidMessage", b => + { + b.Property("DiscordRaidMessageId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DiscordChannelId") + .HasColumnType("INTEGER"); + + b.Property("DiscordGuildId") + .HasColumnType("INTEGER"); + + b.Property("DiscordMessageId") + .HasColumnType("INTEGER"); + + b.Property("RaidId") + .HasColumnType("INTEGER"); + + b.Property("RaidTemplateId") + .HasColumnType("INTEGER"); + + b.HasKey("DiscordRaidMessageId"); + + b.HasIndex("RaidId"); + + b.HasIndex("RaidTemplateId"); + + b.ToTable("DiscordRaidMessage", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.Raid", b => + { + b.Property("RaidId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("TEXT"); + + b.Property("EndTimeUTC") + .HasColumnType("TEXT"); + + b.Property("EventType") + .HasColumnType("INTEGER"); + + b.Property("FreeForAllTimeUTC") + .HasColumnType("TEXT"); + + b.Property("Guild") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("MoveFlexUsers") + .HasColumnType("INTEGER"); + + b.Property("Organizer") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("RaidOwnerId") + .HasColumnType("INTEGER"); + + b.Property("RaidType") + .HasColumnType("INTEGER"); + + b.Property("RequiredRole") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("StartTimeUTC") + .HasColumnType("TEXT"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("VoiceChat") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("RaidId"); + + b.ToTable("Raid", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidReminder", b => + { + b.Property("RaidReminderId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DiscordChannelId") + .HasColumnType("INTEGER"); + + b.Property("DiscordServerId") + .HasColumnType("INTEGER"); + + b.Property("Message") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("TEXT"); + + b.Property("RaidId") + .HasColumnType("INTEGER"); + + b.Property("RaidTemplateId") + .HasColumnType("INTEGER"); + + b.Property("ReminderTimeUTC") + .HasColumnType("TEXT"); + + b.Property("Sent") + .HasColumnType("INTEGER"); + + b.Property("TimeType") + .HasColumnType("INTEGER"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("RaidReminderId"); + + b.HasIndex("RaidId"); + + b.HasIndex("RaidTemplateId"); + + b.ToTable("RaidReminder", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidRole", b => + { + b.Property("RaidRoleId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("IsRandomSignUpRole") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT"); + + b.Property("RaidId") + .HasColumnType("INTEGER"); + + b.Property("RaidTemplateId") + .HasColumnType("INTEGER"); + + b.Property("Spots") + .HasColumnType("INTEGER"); + + b.HasKey("RaidRoleId"); + + b.HasIndex("RaidId"); + + b.HasIndex("RaidTemplateId"); + + b.ToTable("RaidRole", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidSignUp", b => + { + b.Property("RaidSignUpId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ExternalUserName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("GuildWars2AccountId") + .HasColumnType("INTEGER"); + + b.Property("LiebUserId") + .HasColumnType("INTEGER"); + + b.Property("RaidId") + .HasColumnType("INTEGER"); + + b.Property("RaidRoleId") + .HasColumnType("INTEGER"); + + b.Property("SignUpType") + .HasColumnType("INTEGER"); + + b.HasKey("RaidSignUpId"); + + b.HasIndex("GuildWars2AccountId"); + + b.HasIndex("LiebUserId"); + + b.HasIndex("RaidId"); + + b.HasIndex("RaidRoleId"); + + b.ToTable("RaidSignUp", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidTemplate", b => + { + b.Property("RaidTemplateId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreateDaysBefore") + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("TEXT"); + + b.Property("EndTime") + .HasColumnType("TEXT"); + + b.Property("EventType") + .HasColumnType("INTEGER"); + + b.Property("FreeForAllTime") + .HasColumnType("TEXT"); + + b.Property("Guild") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Interval") + .HasColumnType("INTEGER"); + + b.Property("MoveFlexUsers") + .HasColumnType("INTEGER"); + + b.Property("Organizer") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("RaidOwnerId") + .HasColumnType("INTEGER"); + + b.Property("RaidType") + .HasColumnType("INTEGER"); + + b.Property("RequiredRole") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("StartTime") + .HasColumnType("TEXT"); + + b.Property("TimeZone") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("VoiceChat") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("RaidTemplateId"); + + b.ToTable("RaidTemplate", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.LiebRole", b => + { + b.Property("LiebRoleId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Level") + .HasColumnType("INTEGER"); + + b.Property("LevelToAssign") + .HasColumnType("INTEGER"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("LiebRoleId"); + + b.ToTable("LiebRole", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.LiebUser", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("AlwaysSignUpWithMainAccount") + .HasColumnType("INTEGER"); + + b.Property("BannedUntil") + .HasColumnType("TEXT"); + + b.Property("Birthday") + .HasColumnType("TEXT"); + + b.Property("MainGW2Account") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT"); + + b.Property("Pronouns") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("LiebUser", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.RoleAssignment", b => + { + b.Property("RoleAssignmentId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("LiebRoleId") + .HasColumnType("INTEGER"); + + b.Property("LiebUserId") + .HasColumnType("INTEGER"); + + b.HasKey("RoleAssignmentId"); + + b.HasIndex("LiebRoleId"); + + b.HasIndex("LiebUserId"); + + b.ToTable("RoleAssignment", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Equipped", b => + { + b.HasOne("Lieb.Models.GuildWars2.GuildWars2Account", "GuildWars2Account") + .WithMany("EquippedBuilds") + .HasForeignKey("GuildWars2AccountId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lieb.Models.GuildWars2.GuildWars2Build", "GuildWars2Build") + .WithMany("EquippedRoles") + .HasForeignKey("GuildWars2BuildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("GuildWars2Account"); + + b.Navigation("GuildWars2Build"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.GuildWars2Account", b => + { + b.HasOne("Lieb.Models.LiebUser", null) + .WithMany("GuildWars2Accounts") + .HasForeignKey("LiebUserId"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.DiscordRaidMessage", b => + { + b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", null) + .WithMany("DiscordRaidMessages") + .HasForeignKey("RaidId"); + + b.HasOne("Lieb.Models.GuildWars2.Raid.RaidTemplate", null) + .WithMany("DiscordRaidMessages") + .HasForeignKey("RaidTemplateId"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidReminder", b => + { + b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", null) + .WithMany("Reminders") + .HasForeignKey("RaidId"); + + b.HasOne("Lieb.Models.GuildWars2.Raid.RaidTemplate", null) + .WithMany("Reminders") + .HasForeignKey("RaidTemplateId"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidRole", b => + { + b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", null) + .WithMany("Roles") + .HasForeignKey("RaidId"); + + b.HasOne("Lieb.Models.GuildWars2.Raid.RaidTemplate", null) + .WithMany("Roles") + .HasForeignKey("RaidTemplateId"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidSignUp", b => + { + b.HasOne("Lieb.Models.GuildWars2.GuildWars2Account", "GuildWars2Account") + .WithMany() + .HasForeignKey("GuildWars2AccountId"); + + b.HasOne("Lieb.Models.LiebUser", "LiebUser") + .WithMany() + .HasForeignKey("LiebUserId"); + + b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", "Raid") + .WithMany("SignUps") + .HasForeignKey("RaidId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lieb.Models.GuildWars2.Raid.RaidRole", "RaidRole") + .WithMany() + .HasForeignKey("RaidRoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("GuildWars2Account"); + + b.Navigation("LiebUser"); + + b.Navigation("Raid"); + + b.Navigation("RaidRole"); + }); + + modelBuilder.Entity("Lieb.Models.RoleAssignment", b => + { + b.HasOne("Lieb.Models.LiebRole", "LiebRole") + .WithMany("RoleAssignments") + .HasForeignKey("LiebRoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lieb.Models.LiebUser", "LiebUser") + .WithMany("RoleAssignments") + .HasForeignKey("LiebUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("LiebRole"); + + b.Navigation("LiebUser"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.GuildWars2Account", b => + { + b.Navigation("EquippedBuilds"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.GuildWars2Build", b => + { + b.Navigation("EquippedRoles"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.Raid", b => + { + b.Navigation("DiscordRaidMessages"); + + b.Navigation("Reminders"); + + b.Navigation("Roles"); + + b.Navigation("SignUps"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidTemplate", b => + { + b.Navigation("DiscordRaidMessages"); + + b.Navigation("Reminders"); + + b.Navigation("Roles"); + }); + + modelBuilder.Entity("Lieb.Models.LiebRole", b => + { + b.Navigation("RoleAssignments"); + }); + + modelBuilder.Entity("Lieb.Models.LiebUser", b => + { + b.Navigation("GuildWars2Accounts"); + + b.Navigation("RoleAssignments"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Lieb/Migrations/20221205132556_RemovedRaidLog.cs b/Lieb/Migrations/20221205132556_RemovedRaidLog.cs new file mode 100644 index 0000000..d9c4e10 --- /dev/null +++ b/Lieb/Migrations/20221205132556_RemovedRaidLog.cs @@ -0,0 +1,67 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Lieb.Migrations +{ + public partial class RemovedRaidLog : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "RaidLog"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "RaidLog", + columns: table => new + { + RaidLogId = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + RaidId = table.Column(type: "INTEGER", nullable: true), + RaidTemplateId = table.Column(type: "INTEGER", nullable: true), + UserId = table.Column(type: "INTEGER", nullable: true), + LogEntry = table.Column(type: "TEXT", nullable: false), + Time = table.Column(type: "TEXT", nullable: false), + Type = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RaidLog", x => x.RaidLogId); + table.ForeignKey( + name: "FK_RaidLog_LiebUser_UserId", + column: x => x.UserId, + principalTable: "LiebUser", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_RaidLog_Raid_RaidId", + column: x => x.RaidId, + principalTable: "Raid", + principalColumn: "RaidId"); + table.ForeignKey( + name: "FK_RaidLog_RaidTemplate_RaidTemplateId", + column: x => x.RaidTemplateId, + principalTable: "RaidTemplate", + principalColumn: "RaidTemplateId"); + }); + + migrationBuilder.CreateIndex( + name: "IX_RaidLog_RaidId", + table: "RaidLog", + column: "RaidId"); + + migrationBuilder.CreateIndex( + name: "IX_RaidLog_RaidTemplateId", + table: "RaidLog", + column: "RaidTemplateId"); + + migrationBuilder.CreateIndex( + name: "IX_RaidLog_UserId", + table: "RaidLog", + column: "UserId"); + } + } +} diff --git a/Lieb/Migrations/LiebContextModelSnapshot.cs b/Lieb/Migrations/LiebContextModelSnapshot.cs index 84c184d..f6813cb 100644 --- a/Lieb/Migrations/LiebContextModelSnapshot.cs +++ b/Lieb/Migrations/LiebContextModelSnapshot.cs @@ -207,42 +207,6 @@ namespace Lieb.Migrations b.ToTable("Raid", (string)null); }); - modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidLog", b => - { - b.Property("RaidLogId") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("LogEntry") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("RaidId") - .HasColumnType("INTEGER"); - - b.Property("RaidTemplateId") - .HasColumnType("INTEGER"); - - b.Property("Time") - .HasColumnType("TEXT"); - - b.Property("Type") - .HasColumnType("INTEGER"); - - b.Property("UserId") - .HasColumnType("INTEGER"); - - b.HasKey("RaidLogId"); - - b.HasIndex("RaidId"); - - b.HasIndex("RaidTemplateId"); - - b.HasIndex("UserId"); - - b.ToTable("RaidLog", (string)null); - }); - modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidReminder", b => { b.Property("RaidReminderId") @@ -548,27 +512,6 @@ namespace Lieb.Migrations .HasForeignKey("RaidTemplateId"); }); - modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidLog", b => - { - b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", "Raid") - .WithMany("RaidLogs") - .HasForeignKey("RaidId"); - - b.HasOne("Lieb.Models.GuildWars2.Raid.RaidTemplate", "RaidTemplate") - .WithMany("TemplateLogs") - .HasForeignKey("RaidTemplateId"); - - b.HasOne("Lieb.Models.LiebUser", "User") - .WithMany() - .HasForeignKey("UserId"); - - b.Navigation("Raid"); - - b.Navigation("RaidTemplate"); - - b.Navigation("User"); - }); - modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidReminder", b => { b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", null) @@ -655,8 +598,6 @@ namespace Lieb.Migrations { b.Navigation("DiscordRaidMessages"); - b.Navigation("RaidLogs"); - b.Navigation("Reminders"); b.Navigation("Roles"); @@ -671,8 +612,6 @@ namespace Lieb.Migrations b.Navigation("Reminders"); b.Navigation("Roles"); - - b.Navigation("TemplateLogs"); }); modelBuilder.Entity("Lieb.Models.LiebRole", b => diff --git a/Lieb/Models/GuildWars2/Raid/Raid.cs b/Lieb/Models/GuildWars2/Raid/Raid.cs index ee445ce..5f0225d 100644 --- a/Lieb/Models/GuildWars2/Raid/Raid.cs +++ b/Lieb/Models/GuildWars2/Raid/Raid.cs @@ -16,8 +16,6 @@ namespace Lieb.Models.GuildWars2.Raid public ICollection SignUps { get; set; } = new HashSet(); - public ICollection RaidLogs { get; set; } = new HashSet(); - public Raid() { } public Raid(RaidTemplate template) : base(template) diff --git a/Lieb/Models/GuildWars2/Raid/RaidLog.cs b/Lieb/Models/GuildWars2/Raid/RaidLog.cs deleted file mode 100644 index 15fd9da..0000000 --- a/Lieb/Models/GuildWars2/Raid/RaidLog.cs +++ /dev/null @@ -1,75 +0,0 @@ - -using System.Text.Json; -using System.Text.Json.Serialization; - -namespace Lieb.Models.GuildWars2.Raid -{ - public class RaidLog - { - public enum LogType - { - Raid = 1, - RaidTemplate = 2, - RaidSignUp = 3 - } - - public int RaidLogId { get; set; } - - public LogType Type {get; set;} - - public ulong? UserId {get; set;} - - public int? RaidId { get; set; } - - public int? RaidTemplateId { get; set; } - - public string LogEntry {get; set;} = string.Empty; - - public DateTimeOffset Time { get; set; } = DateTimeOffset.UtcNow; - - public LiebUser? User {get; set;} - - [JsonIgnore(Condition = JsonIgnoreCondition.Always)] - public Raid? Raid { get; set; } - - [JsonIgnore(Condition = JsonIgnoreCondition.Always)] - public RaidTemplate? RaidTemplate { get; set; } - - public static RaidLog CreateRaidLog(ulong? userId, Raid raid) - { - return new RaidLog() - { - Type = LogType.Raid, - UserId = userId, - RaidId = raid.RaidId, - LogEntry = JsonSerializer.Serialize(raid), - Time = DateTimeOffset.UtcNow - }; - } - - public static RaidLog CreateSignUpLog(ulong userId, RaidSignUp signUp, string signedUpUserName) - { - string message = $"changed Status of {signedUpUserName} to: {signUp.SignUpType.ToString()}"; - return new RaidLog() - { - Type = LogType.RaidSignUp, - UserId = userId, - RaidId = signUp.RaidId, - LogEntry = message, - Time = DateTimeOffset.UtcNow - }; - } - - public static RaidLog CreateRaidTemplateLog(ulong userId, RaidTemplate template) - { - return new RaidLog() - { - Type = LogType.RaidTemplate, - UserId = userId, - RaidTemplateId = template.RaidTemplateId, - LogEntry = JsonSerializer.Serialize(template), - Time = DateTimeOffset.UtcNow - }; - } - } -} diff --git a/Lieb/Models/GuildWars2/Raid/RaidTemplate.cs b/Lieb/Models/GuildWars2/Raid/RaidTemplate.cs index e41bb7b..bbf8456 100644 --- a/Lieb/Models/GuildWars2/Raid/RaidTemplate.cs +++ b/Lieb/Models/GuildWars2/Raid/RaidTemplate.cs @@ -19,7 +19,5 @@ namespace Lieb.Models.GuildWars2.Raid public int Interval { get; set; } public int CreateDaysBefore { get; set; } - - public ICollection TemplateLogs { get; set; } = new HashSet(); } }