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

@@ -34,7 +34,8 @@ public class InstallThemeEndpointSummary : Summary<InstallThemeEndpoint, EmptyRe
PreviewPath: "preview.png",
InstallSource: ThemeInstallSource.Uploaded,
IsCurrent: null,
InstalledAtUtc: DateTime.UtcNow
InstalledAtUtc: DateTime.UtcNow,
IsDeleted: false
));
Response(401, "Authentication required.", "application/problem+json",
@@ -0,0 +1,53 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.Themes;
using Lumina.Application.Core.Themes.Management.Commands.RestoreTheme;
using Lumina.Contracts.Requests.Themes;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Themes;
using Lumina.Presentation.Api.Core.Endpoints.Common;
using Microsoft.AspNetCore.Http;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Management.RestoreTheme;
/// <summary>
/// API endpoint for the <c>/themes/{themeId}/restore</c> route.
/// </summary>
public class RestoreThemeEndpoint : BaseEndpoint<RestoreThemeRequest, IResult>
{
private readonly ICommandHandler<RestoreThemeCommand, Result<Success>> _restoreThemeCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="RestoreThemeEndpoint"/> class.
/// </summary>
/// <param name="restoreThemeCommandHandler">Injected service for handling restore theme commands.</param>
public RestoreThemeEndpoint(ICommandHandler<RestoreThemeCommand, Result<Success>> restoreThemeCommandHandler)
{
_restoreThemeCommandHandler = restoreThemeCommandHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.POST);
Routes(ApiRoutes.Themes.RESTORE_THEME);
Version(1);
DontCatchExceptions();
}
/// <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)
{
Result<Success> result = await _restoreThemeCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.NoContent(), Problem);
}
}
@@ -0,0 +1,120 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.Themes;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Management.RestoreTheme;
/// <summary>
/// Class used for providing a textual description for the <see cref="RestoreThemeEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class RestoreThemeEndpointSummary : Summary<RestoreThemeEndpoint, RestoreThemeRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="RestoreThemeEndpointSummary"/> class.
/// </summary>
public RestoreThemeEndpointSummary()
{
Summary = "Restores a deleted bundled theme.";
Description = "Restores the files and reactivates a bundled theme that was soft deleted by the user, restoring the pack from the shipped archive.";
ExampleRequest = new RestoreThemeRequest(
ThemeId: "editorial-paper"
);
RequestParam(r => r.ThemeId, "The manifest id of the bundled theme to restore. Required.");
Response(204, "The theme was successfully restored.");
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/themes/{themeId}/restore"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/themes/{themeId}/restore"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/themes/{themeId}/restore"
}
}
);
Response(403, "The request failed because the user is not an Admin or the theme is not a soft deleted bundled theme.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/themes/{themeId}/restore",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
status = 403,
detail = "ThemeCannotBeRestored",
instance = "/api/v1/themes/{themeId}/restore",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
}
);
Response(404, "The request failed because the provided theme does not exist.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "ThemeNotFound",
instance = "/api/v1/themes/{themeId}/restore",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
);
Response(422, "The request did not pass validation checks.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/themes/{themeId}/restore",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"ThemeIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -41,7 +41,8 @@ public class SetCurrentThemeEndpointSummary : Summary<SetCurrentThemeEndpoint, S
PreviewPath: "preview.png",
InstallSource: ThemeInstallSource.Bundled,
IsCurrent: true,
InstalledAtUtc: DateTime.UtcNow
InstalledAtUtc: DateTime.UtcNow,
IsDeleted: false
));
Response(401, "Authentication required.", "application/problem+json",
@@ -33,7 +33,8 @@ public class GetCurrentThemeEndpointSummary : Summary<GetCurrentThemeEndpoint, E
PreviewPath: "preview.png",
InstallSource: ThemeInstallSource.Bundled,
IsCurrent: true,
InstalledAtUtc: DateTime.UtcNow
InstalledAtUtc: DateTime.UtcNow,
IsDeleted: false
));
}
}
@@ -44,7 +44,8 @@ public class GetThemeTemplateEndpointSummary : Summary<GetThemeTemplateEndpoint,
PreviewPath: "preview.png",
InstallSource: ThemeInstallSource.Bundled,
IsCurrent: true,
InstalledAtUtc: DateTime.UtcNow
InstalledAtUtc: DateTime.UtcNow,
IsDeleted: false
),
"<html><body><div class=\"content\">{{content}}</div></body></html>"
));
@@ -34,7 +34,8 @@ public class GetThemesEndpointSummary : Summary<GetThemesEndpoint, EmptyRequest>
PreviewPath: "preview.png",
InstallSource: ThemeInstallSource.Bundled,
IsCurrent: true,
InstalledAtUtc: DateTime.UtcNow
InstalledAtUtc: DateTime.UtcNow,
IsDeleted: false
),
new (
Id: Guid.NewGuid(),
@@ -46,7 +47,8 @@ public class GetThemesEndpointSummary : Summary<GetThemesEndpoint, EmptyRequest>
PreviewPath: "preview.jpg",
InstallSource: ThemeInstallSource.Uploaded,
IsCurrent: null,
InstalledAtUtc: DateTime.UtcNow
InstalledAtUtc: DateTime.UtcNow,
IsDeleted: false
)
});