Skip to content

Commit

Permalink
Fix forcelink of existing users.
Browse files Browse the repository at this point in the history
  • Loading branch information
GianniKoch committed Mar 8, 2024
1 parent 74dfd9f commit 4bdefc0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,16 @@ public virtual async Task Handle(CommandContext ctx, string _)
return scoreSaberId;
}

protected Task CreateScoreLink(ulong discordId, string scoreSaberId)
protected async Task CreateScoreLink(ulong discordId, string scoreSaberId)
{
return GlobalUserSettingsRepository.CreateOrUpdateScoreSaberLink(discordId, scoreSaberId);
var existingUserSetting = await GlobalUserSettingsRepository.GetByScoreSaberId(scoreSaberId);

if(existingUserSetting != null)
{
await GlobalUserSettingsRepository.DeleteAsync(existingUserSetting);
}

await GlobalUserSettingsRepository.CreateOrUpdateScoreSaberLink(discordId, scoreSaberId);

// TODO: Role assignment logic (Preferably call into service)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,17 @@ public async Task UpdateBirthday(ulong discordUserId, LocalDate? birthday, Cance

await context.SaveChangesAsync(cts).ConfigureAwait(false);
}

public async Task<GlobalUserSettings?> GetByScoreSaberId(string scoreSaberId, CancellationToken cts)
{
await using var context = await _appDbContextFactory.CreateDbContextAsync(cts);
return await context.GlobalUserSettings.SingleOrDefaultAsync(g => g.ScoreSaberId == scoreSaberId, cts);
}

public async Task DeleteAsync(GlobalUserSettings existingUserSetting, CancellationToken cts = default)
{
await using var context = await _appDbContextFactory.CreateDbContextAsync(cts);
context.GlobalUserSettings.Remove(existingUserSetting);
await context.SaveChangesAsync(cts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public interface IGlobalUserSettingsRepository
Task<GlobalUserSettings?> LookupSettingsByScoreSaberId(string scoreSaberId, CancellationToken cts = default);
Task<List<ScoreSaberAccountLink>> GetAllScoreSaberAccountLinks(CancellationToken cts = default);
Task CreateOrUpdateScoreSaberLink(ulong discordUserId, string scoreSaberId, CancellationToken cts = default);

Task<List<GlobalUserSettings>> GetAllBirthdayGirls(int dayOfMonth, int month, CancellationToken cts = default);
Task UpdateBirthday(ulong discordUserId, LocalDate? birthday, CancellationToken cts = default);
Task<GlobalUserSettings?> GetByScoreSaberId(string scoreSaberId, CancellationToken cts = default);
Task DeleteAsync(GlobalUserSettings existingUserSetting, CancellationToken cts = default);
}

0 comments on commit 4bdefc0

Please sign in to comment.