diff --git a/DysonNetwork.Sphere/Account/AccountController.cs b/DysonNetwork.Sphere/Account/AccountController.cs index bb49b72..13eb9e8 100644 --- a/DysonNetwork.Sphere/Account/AccountController.cs +++ b/DysonNetwork.Sphere/Account/AccountController.cs @@ -428,4 +428,13 @@ public class AccountController( .Take(take) .ToListAsync(); } + + [HttpPost("/maintenance/ensureProfileCreated")] + [Authorize] + [RequiredPermission("maintenance", "accounts.profiles")] + public async Task EnsureProfileCreated() + { + await accounts.EnsureAccountProfileCreated(); + return Ok(); + } } \ No newline at end of file diff --git a/DysonNetwork.Sphere/Account/AccountService.cs b/DysonNetwork.Sphere/Account/AccountService.cs index 77d2fe0..74c7b48 100644 --- a/DysonNetwork.Sphere/Account/AccountService.cs +++ b/DysonNetwork.Sphere/Account/AccountService.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Reflection; using DysonNetwork.Sphere.Localization; using DysonNetwork.Sphere.Permission; +using EFCore.BulkExtensions; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Localization; @@ -48,4 +49,19 @@ public class AccountService( .FirstOrDefaultAsync(); return profile?.Level; } + + /// Maintenance methods for server administrator + + public async Task EnsureAccountProfileCreated() + { + var accountsId = await db.Accounts.Select(a => a.Id).ToListAsync(); + var existingId = await db.AccountProfiles.Select(p => p.AccountId).ToListAsync(); + var missingId = accountsId.Except(existingId).ToList(); + + if (missingId.Count != 0) + { + var newProfiles = missingId.Select(id => new Profile { AccountId = id }).ToList(); + await db.BulkInsertAsync(newProfiles); + } + } } \ No newline at end of file