mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 09:11:10 +00:00
Uses the empty request type for the theme install endpoint
This commit is contained in:
1 parent
ebafd743b5
commit
6bb3449d4f
4 files changed
+5
-44
No files matched your search
@@ -1,25 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using Lumina.Application.Core.Themes.Management.Commands.InstallTheme;
|
|
||||||
using Lumina.Contracts.Requests.Themes;
|
|
||||||
using System.IO;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Application.Common.Mapping.Themes;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Extension methods for converting <see cref="InstallThemeRequest"/>.
|
|
||||||
/// </summary>
|
|
||||||
public static class InstallThemeRequestMapping
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Converts <paramref name="request"/> to <see cref="InstallThemeCommand"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request to be converted.</param>
|
|
||||||
/// <param name="archive">The ZIP archive stream of the theme pack.</param>
|
|
||||||
/// <param name="fileName">The file name of the uploaded archive.</param>
|
|
||||||
/// <returns>The converted command.</returns>
|
|
||||||
public static InstallThemeCommand ToCommand(this InstallThemeRequest request, Stream? archive, string? fileName)
|
|
||||||
{
|
|
||||||
return new InstallThemeCommand(archive, fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
|
||||||
using System;
|
|
||||||
using System.Diagnostics;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace Lumina.Contracts.Requests.Themes;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a request to install a theme pack, sent as a multipart form whose single file field contains the theme archive.
|
|
||||||
/// </summary>
|
|
||||||
[DebuggerDisplay("InstallThemeRequest")]
|
|
||||||
public record InstallThemeRequest;
|
|
||||||
+4
-5
@@ -1,8 +1,6 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Application.Common.CQRS;
|
using Lumina.Application.Common.CQRS;
|
||||||
using Lumina.Application.Common.Mapping.Themes;
|
|
||||||
using Lumina.Application.Core.Themes.Management.Commands.InstallTheme;
|
using Lumina.Application.Core.Themes.Management.Commands.InstallTheme;
|
||||||
using Lumina.Contracts.Requests.Themes;
|
|
||||||
using Lumina.Contracts.Responses.Themes;
|
using Lumina.Contracts.Responses.Themes;
|
||||||
using Lumina.Domain.Common.Primitives;
|
using Lumina.Domain.Common.Primitives;
|
||||||
using Lumina.Presentation.Api.Common.Routes.Themes;
|
using Lumina.Presentation.Api.Common.Routes.Themes;
|
||||||
@@ -18,7 +16,7 @@ namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Management.InstallTheme;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// API endpoint for the <c>/themes</c> route.
|
/// API endpoint for the <c>/themes</c> route.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class InstallThemeEndpoint : BaseEndpoint<InstallThemeRequest, IResult>
|
public class InstallThemeEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
|
||||||
{
|
{
|
||||||
private readonly ICommandHandler<InstallThemeCommand, Result<ThemeResponse>> _installThemeCommandHandler;
|
private readonly ICommandHandler<InstallThemeCommand, Result<ThemeResponse>> _installThemeCommandHandler;
|
||||||
|
|
||||||
@@ -47,10 +45,11 @@ public class InstallThemeEndpoint : BaseEndpoint<InstallThemeRequest, IResult>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request">The request object.</param>
|
/// <param name="request">The request object.</param>
|
||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||||
public override async Task<IResult> ExecuteAsync(InstallThemeRequest request, CancellationToken cancellationToken)
|
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
IFormFile? archive = HttpContext.Request.Form.Files.FirstOrDefault();
|
IFormFile? archive = HttpContext.Request.Form.Files.FirstOrDefault();
|
||||||
Result<ThemeResponse> result = await _installThemeCommandHandler.HandleAsync(request.ToCommand(archive?.OpenReadStream(), archive?.FileName), cancellationToken).ConfigureAwait(false);
|
InstallThemeCommand command = new(archive?.OpenReadStream(), archive?.FileName);
|
||||||
|
Result<ThemeResponse> result = await _installThemeCommandHandler.HandleAsync(command, cancellationToken).ConfigureAwait(false);
|
||||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Lumina.Contracts.Requests.Themes;
|
|
||||||
using Lumina.Contracts.Responses.Themes;
|
using Lumina.Contracts.Responses.Themes;
|
||||||
using Lumina.Domain.SharedKernel.Common.Enums.Themes;
|
using Lumina.Domain.SharedKernel.Common.Enums.Themes;
|
||||||
using System;
|
using System;
|
||||||
@@ -14,7 +13,7 @@ namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Management.InstallTheme;
|
|||||||
/// Class used for providing a textual description for the <see cref="InstallThemeEndpoint"/> API endpoint, for OpenAPI.
|
/// Class used for providing a textual description for the <see cref="InstallThemeEndpoint"/> API endpoint, for OpenAPI.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class InstallThemeEndpointSummary : Summary<InstallThemeEndpoint, InstallThemeRequest>
|
public class InstallThemeEndpointSummary : Summary<InstallThemeEndpoint, EmptyRequest>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="InstallThemeEndpointSummary"/> class.
|
/// Initializes a new instance of the <see cref="InstallThemeEndpointSummary"/> class.
|
||||||
|
|||||||
Reference in new issue
Block a user