feat: freeze config backup model
the database model will probably change in the future, but backups should keep the same model even when that happens.
This commit is contained in:
parent
cbb07f9cc3
commit
d48ab7e16e
2 changed files with 117 additions and 21 deletions
|
|
@ -36,10 +36,7 @@ public partial class GuildsController
|
|||
|
||||
[Authorize]
|
||||
[HttpPost("config")]
|
||||
public async Task<IActionResult> ImportConfigAsync(
|
||||
string id,
|
||||
[FromBody] GuildConfigExport export
|
||||
)
|
||||
public async Task<IActionResult> ImportConfigAsync(string id, [FromBody] ConfigExport export)
|
||||
{
|
||||
var (guildId, _) = await ParseGuildAsync(id);
|
||||
if (export.Id != guildId.Value)
|
||||
|
|
@ -56,7 +53,7 @@ public partial class GuildsController
|
|||
|
||||
await guildRepository.ImportConfigAsync(
|
||||
guildId.Value,
|
||||
export.Channels,
|
||||
export.Channels.ToGuildConfig(),
|
||||
export.BannedSystems,
|
||||
export.KeyRoles
|
||||
);
|
||||
|
|
@ -86,32 +83,19 @@ public partial class GuildsController
|
|||
return NoContent();
|
||||
}
|
||||
|
||||
private async Task<GuildConfigExport> ToExport(Database.Models.Guild config)
|
||||
private async Task<ConfigExport> ToExport(Database.Models.Guild config)
|
||||
{
|
||||
var id = DiscordSnowflake.New(config.Id);
|
||||
var invites = await inviteRepository.GetGuildInvitesAsync(id);
|
||||
var watchlist = await watchlistRepository.GetGuildWatchlistAsync(id);
|
||||
|
||||
return new GuildConfigExport(
|
||||
return new ConfigExport(
|
||||
config.Id,
|
||||
config.Channels,
|
||||
ChannelsBackup.FromGuildConfig(config.Channels),
|
||||
config.BannedSystems,
|
||||
config.KeyRoles,
|
||||
invites.Select(i => new InviteExport(i.Code, i.Name)),
|
||||
watchlist.Select(w => new WatchlistExport(w.UserId, w.AddedAt, w.ModeratorId, w.Reason))
|
||||
);
|
||||
}
|
||||
|
||||
public record GuildConfigExport(
|
||||
ulong Id,
|
||||
Database.Models.Guild.ChannelConfig Channels,
|
||||
string[] BannedSystems,
|
||||
ulong[] KeyRoles,
|
||||
IEnumerable<InviteExport> Invites,
|
||||
IEnumerable<WatchlistExport> Watchlist
|
||||
);
|
||||
|
||||
public record InviteExport(string Code, string Name);
|
||||
|
||||
public record WatchlistExport(ulong UserId, Instant AddedAt, ulong ModeratorId, string Reason);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue