Adds a restore action for soft deleted bundled themes

This commit is contained in:
BinaryAlley committed 2026-08-21 11:47:51 -07:00
1 parent 15945c2e56
commit 7e54c990ad
49 files changed
+1666 -26

No files matched your search

@@ -0,0 +1,59 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Presentation.Web.Common.Authorization;
using Lumina.Presentation.Web.Common.Requests.Themes;
using Lumina.Presentation.Web.Common.Routes;
using Lumina.Presentation.Web.Core.Endpoints.Common;
using Lumina.Presentation.Web.Core.Themes;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.RestoreTheme;
/// <summary>
/// API endpoint for the <c>/{culture}/admin/themes/api-restore-theme/{themeId}</c> route.
/// </summary>
public class RestoreThemeEndpoint : BaseEndpoint<RestoreThemeRequest, IResult>
{
private readonly ThemeService _themeService;
/// <summary>
/// Initializes a new instance of the <see cref="RestoreThemeEndpoint"/> class.
/// </summary>
/// <param name="themeService">Injected service for interactions with the remote theme endpoints.</param>
public RestoreThemeEndpoint(ThemeService themeService)
{
_themeService = themeService;
}
/// <summary>
/// Configures the endpoint.
/// </summary>
public override void Configure()
{
base.Configure();
Verbs(Http.POST);
Routes(WebRoutes.Themes.RESTORE_THEME);
DontAutoTag();
Options(options => options.WithTags("Themes"));
Policies(AuthorizationPolicies.REQUIRE_ADMIN_ROLE);
EnableAntiforgery();
}
/// <summary>
/// Restores the soft deleted bundled theme identified by <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the theme to restore.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(RestoreThemeRequest request, CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(request.ThemeId))
return Results.Problem(statusCode: StatusCodes.Status400BadRequest, detail: "The theme id cannot be empty.");
await _themeService.RestoreThemeAsync(request.ThemeId, cancellationToken).ConfigureAwait(false);
return JsonSuccess();
}
}