reworked Logging changes
This commit is contained in:
parent
b8feed971c
commit
a504925752
7 changed files with 93 additions and 58 deletions
|
@ -38,7 +38,7 @@ namespace DiscordBot.CommandHandlers
|
|||
ulong.TryParse(ids[3],out userId);
|
||||
}
|
||||
await ManageSignUp(ids[2], parsedRaidId, component, userId);
|
||||
await component.RespondAsync("successfully signed up");
|
||||
await component.RespondAsync("successfully signed up", ephemeral: true);
|
||||
break;
|
||||
case Constants.ComponentIds.SIGN_UP_EXTERNAL_DROP_DOWN:
|
||||
await component.RespondWithModalAsync(CreateUserNameModal(parsedRaidId, int.Parse(component.Data.Values.First())));
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace Lieb.Data
|
|||
public DbSet<RaidTemplate> RaidTemplates { get; set; }
|
||||
public DbSet<RaidReminder> RaidReminders { get; set; }
|
||||
public DbSet<RaidSignUp> RaidSignUps { get; set; }
|
||||
public DbSet<RaidSignUpHistory> RaidSignUpHistories { get; set; }
|
||||
public DbSet<RaidLog> RaidLogs { get; set; }
|
||||
public DbSet<DiscordRaidMessage> DiscordRaidMessages { get; set; }
|
||||
|
||||
|
||||
|
@ -41,7 +41,7 @@ namespace Lieb.Data
|
|||
modelBuilder.Entity<RaidTemplate>().ToTable("RaidTemplate");
|
||||
modelBuilder.Entity<RaidReminder>().ToTable("RaidReminder");
|
||||
modelBuilder.Entity<RaidSignUp>().ToTable("RaidSignUp");
|
||||
modelBuilder.Entity<RaidSignUpHistory>().ToTable("RaidSignUpHistory");
|
||||
modelBuilder.Entity<RaidLog>().ToTable("RaidLog");
|
||||
modelBuilder.Entity<DiscordRaidMessage>().ToTable("DiscordRaidMessage");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace Lieb.Data
|
|||
using var context = _contextFactory.CreateDbContext();
|
||||
Raid? raid = context.Raids
|
||||
.Include(r => r.Roles)
|
||||
.Include(r => r.SignUpHistory)
|
||||
.Include(r => r.RaidLogs)
|
||||
.Include(r => r.Reminders)
|
||||
.Include(r => r.SignUps)
|
||||
.ThenInclude(s => s.LiebUser)
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace Lieb.Data
|
|||
using var context = _contextFactory.CreateDbContext();
|
||||
return context.Raids
|
||||
.Include(r => r.Roles)
|
||||
.Include(r => r.SignUpHistory)
|
||||
.Include(r => r.RaidLogs)
|
||||
.Include(r => r.Reminders)
|
||||
.Include(r => r.SignUps)
|
||||
.ThenInclude(s => s.LiebUser)
|
||||
|
@ -37,7 +37,7 @@ namespace Lieb.Data
|
|||
using var context = _contextFactory.CreateDbContext();
|
||||
return context.Raids
|
||||
.Include(r => r.Roles)
|
||||
.Include(r => r.SignUpHistory)
|
||||
.Include(r => r.RaidLogs)
|
||||
.Include(r => r.Reminders)
|
||||
.Include(r => r.SignUps)
|
||||
.ThenInclude(s => s.LiebUser)
|
||||
|
@ -90,7 +90,7 @@ namespace Lieb.Data
|
|||
Raid raid = GetRaid(raidId);
|
||||
context.RaidSignUps.RemoveRange(raid.SignUps);
|
||||
context.RaidRoles.RemoveRange(raid.Roles);
|
||||
context.RaidSignUpHistories.RemoveRange(raid.SignUpHistory);
|
||||
context.RaidLogs.RemoveRange(raid.RaidLogs);
|
||||
context.RaidReminders.RemoveRange(raid.Reminders);
|
||||
await context.SaveChangesAsync();
|
||||
context.Raids.Remove(raid);
|
||||
|
@ -125,9 +125,10 @@ namespace Lieb.Data
|
|||
RaidRoleId = plannedRoleId,
|
||||
SignUpType = signUpType
|
||||
};
|
||||
string userName = context.LiebUsers.FirstOrDefault(l => l.Id == liebUserId)?.Name;
|
||||
context.RaidSignUps.Add(signUp);
|
||||
await context.SaveChangesAsync();
|
||||
await LogSignUp(signUp, signedUpByUserId);
|
||||
await LogSignUp(signUp, userName, signedUpByUserId);
|
||||
}
|
||||
await _discordService.PostRaidMessage(raidId);
|
||||
}
|
||||
|
@ -150,7 +151,7 @@ namespace Lieb.Data
|
|||
};
|
||||
context.RaidSignUps.Add(signUp);
|
||||
await context.SaveChangesAsync();
|
||||
await LogSignUp(signUp, signedUpByUserId);
|
||||
await LogSignUp(signUp, userName, signedUpByUserId);
|
||||
await _discordService.PostRaidMessage(raidId);
|
||||
}
|
||||
|
||||
|
@ -162,7 +163,7 @@ namespace Lieb.Data
|
|||
context.RaidSignUps.RemoveRange(signUps);
|
||||
|
||||
//change to SignedOff
|
||||
RaidSignUp? signUp = context.RaidSignUps.FirstOrDefault(x => x.RaidId == raidId && x.LiebUserId == liebUserId && x.SignUpType != SignUpType.Flex);
|
||||
RaidSignUp? signUp = context.RaidSignUps.Include(s => s.LiebUser).FirstOrDefault(x => x.RaidId == raidId && x.LiebUserId == liebUserId && x.SignUpType != SignUpType.Flex);
|
||||
if (signUp != null)
|
||||
{
|
||||
signUp.SignUpType = SignUpType.SignedOff;
|
||||
|
@ -174,7 +175,7 @@ namespace Lieb.Data
|
|||
context.RaidRoles.Remove(signUp.RaidRole);
|
||||
signUp.RaidRole = raid.Roles.FirstOrDefault(r => r.IsRandomSignUpRole, CreateRandomSignUpRole(raid.RaidType));
|
||||
}
|
||||
await LogSignUp(signUp, signedOffByUserId);
|
||||
await LogSignUp(signUp, signUp.LiebUser.Name, signedOffByUserId);
|
||||
}
|
||||
await context.SaveChangesAsync();
|
||||
await _discordService.PostRaidMessage(raidId);
|
||||
|
@ -192,7 +193,7 @@ namespace Lieb.Data
|
|||
if(signUp != null)
|
||||
{
|
||||
signUp.SignUpType = SignUpType.SignedOff;
|
||||
await LogSignUp(signUp, signedOffByUserId);
|
||||
await LogSignUp(signUp, userName, signedOffByUserId);
|
||||
}
|
||||
await _discordService.PostRaidMessage(raidId);
|
||||
}
|
||||
|
@ -218,7 +219,7 @@ namespace Lieb.Data
|
|||
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
|
||||
List<RaidSignUp> signUps = context.RaidSignUps.Where(x => x.RaidId == raidId && x.LiebUserId == liebUserId).ToList();
|
||||
List<RaidSignUp> signUps = context.RaidSignUps.Where(x => x.RaidId == raidId && x.LiebUserId == liebUserId).Include(s => s.LiebUser).ToList();
|
||||
|
||||
RaidSignUp? signUp = signUps.FirstOrDefault(x => x.SignUpType != SignUpType.Flex);
|
||||
RaidSignUp? flexSignUp = signUps.FirstOrDefault(x => x.SignUpType == SignUpType.Flex && x.RaidRoleId == plannedRoleId);
|
||||
|
@ -234,7 +235,7 @@ namespace Lieb.Data
|
|||
{
|
||||
signUp.RaidRoleId = plannedRoleId;
|
||||
signUp.SignUpType = signUpType;
|
||||
await LogSignUp(signUp);
|
||||
await LogSignUp(signUp, signUp.LiebUser.Name);
|
||||
}
|
||||
context.SaveChanges();
|
||||
if(postChanges)
|
||||
|
@ -391,23 +392,13 @@ namespace Lieb.Data
|
|||
return true;
|
||||
}
|
||||
|
||||
private async Task LogSignUp(RaidSignUp signUp, ulong signedUpBy = 0)
|
||||
private async Task LogSignUp(RaidSignUp signUp, string userName, ulong signedUpBy = 0)
|
||||
{
|
||||
RaidSignUpHistory history = new RaidSignUpHistory()
|
||||
{
|
||||
RaidId = signUp.RaidId,
|
||||
UserId = signUp.LiebUserId,
|
||||
SignUpType = signUp.SignUpType,
|
||||
Time = DateTimeOffset.UtcNow,
|
||||
UserName = signUp.ExternalUserName,
|
||||
GuildWars2AccountId = signUp.GuildWars2AccountId
|
||||
};
|
||||
if(signedUpBy != 0)
|
||||
{
|
||||
history.UserId = signedUpBy;
|
||||
}
|
||||
ulong userId = signedUpBy > 0 ? signedUpBy : signUp.LiebUserId;
|
||||
RaidLog log = RaidLog.CreateSignUpLog(userId, signUp, userName);
|
||||
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
await context.RaidSignUpHistories.AddAsync(history);
|
||||
await context.RaidLogs.AddAsync(log);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace Lieb.Models.GuildWars2.Raid
|
|||
|
||||
public ICollection<RaidSignUp> SignUps { get; set; } = new HashSet<RaidSignUp>();
|
||||
|
||||
public ICollection<RaidSignUpHistory> SignUpHistory { get; set; } = new HashSet<RaidSignUpHistory>();
|
||||
public ICollection<RaidLog> RaidLogs { get; set; } = new HashSet<RaidLog>();
|
||||
|
||||
public Raid() { }
|
||||
|
||||
|
|
72
Lieb/Models/GuildWars2/Raid/RaidLog.cs
Normal file
72
Lieb/Models/GuildWars2/Raid/RaidLog.cs
Normal file
|
@ -0,0 +1,72 @@
|
|||
|
||||
using System.Text.Json;
|
||||
|
||||
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;}
|
||||
|
||||
public Raid? Raid { get; set; }
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
namespace Lieb.Models.GuildWars2.Raid
|
||||
{
|
||||
public class RaidSignUpHistory
|
||||
{
|
||||
public int RaidSignUpHistoryId { get; set; }
|
||||
|
||||
public int RaidId { get; set; }
|
||||
|
||||
public ulong UserId {get; set;}
|
||||
public int GuildWars2AccountId { get; set; }
|
||||
|
||||
//public ulong SignedUpByUserId {get; set;}
|
||||
|
||||
public string UserName {get; set;} = string.Empty;
|
||||
|
||||
public DateTimeOffset Time { get; set; } = DateTimeOffset.Now;
|
||||
|
||||
public SignUpType SignUpType { get; set; }
|
||||
|
||||
public LiebUser User {get; set;}
|
||||
|
||||
//public LiebUser SignedUpByUser {get; set;}
|
||||
|
||||
public Raid Raid { get; set; }
|
||||
|
||||
public GuildWars2Account GuildWars2Account { get; set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue