mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 16:11:10 +00:00
Adds the server-side theme repository and reworks the web theme engine onto it
This commit is contained in:
1 parent
85928f7c3c
commit
bf8faba24d
136 files changed
+6942
-1197
No files matched your search
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.Themes;
|
||||
using Lumina.Application.Core.Themes.Management.Commands.DeleteTheme;
|
||||
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.DeleteTheme;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/themes/{themeId}</c> route.
|
||||
/// </summary>
|
||||
public class DeleteThemeEndpoint : BaseEndpoint<DeleteThemeRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<DeleteThemeCommand, Result<Success>> _deleteThemeCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteThemeEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="deleteThemeCommandHandler">Injected service for handling delete theme commands.</param>
|
||||
public DeleteThemeEndpoint(ICommandHandler<DeleteThemeCommand, Result<Success>> deleteThemeCommandHandler)
|
||||
{
|
||||
_deleteThemeCommandHandler = deleteThemeCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.DELETE);
|
||||
Routes(ApiRoutes.Themes.DELETE_THEME);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the theme identified by <paramref name="request"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the theme to delete.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(DeleteThemeRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<Success> result = await _deleteThemeCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.NoContent(), Problem);
|
||||
}
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
#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.DeleteTheme;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="DeleteThemeEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DeleteThemeEndpointSummary : Summary<DeleteThemeEndpoint, DeleteThemeRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteThemeEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public DeleteThemeEndpointSummary()
|
||||
{
|
||||
Summary = "Deletes a theme.";
|
||||
Description = "Deletes the theme identified by the request, switching to another available theme when the deleted theme was the active one.";
|
||||
|
||||
ExampleRequest = new DeleteThemeRequest(
|
||||
ThemeId: "neon-grid"
|
||||
);
|
||||
|
||||
RequestParam(r => r.ThemeId, "The manifest id of the theme to delete. Required.");
|
||||
|
||||
Response(204, "The theme was successfully deleted.");
|
||||
|
||||
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}"
|
||||
},
|
||||
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}"
|
||||
},
|
||||
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}"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the user is not an Admin, the theme is the last bundled theme, or the active theme cannot be replaced.", "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}",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Failure",
|
||||
status = 403,
|
||||
detail = "LastBundledThemeCannotBeDeleted",
|
||||
instance = "/api/v1/themes/{themeId}",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Failure",
|
||||
status = 403,
|
||||
detail = "ThemeCannotBeDeleted",
|
||||
instance = "/api/v1/themes/{themeId}",
|
||||
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}",
|
||||
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}",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"ThemeIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.Themes;
|
||||
using Lumina.Application.Core.Themes.Management.Commands.InstallTheme;
|
||||
using Lumina.Contracts.Requests.Themes;
|
||||
using Lumina.Contracts.Responses.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.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Management.InstallTheme;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/themes</c> route.
|
||||
/// </summary>
|
||||
public class InstallThemeEndpoint : BaseEndpoint<InstallThemeRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<InstallThemeCommand, Result<ThemeResponse>> _installThemeCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InstallThemeEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="installThemeCommandHandler">Injected service for handling install theme commands.</param>
|
||||
public InstallThemeEndpoint(ICommandHandler<InstallThemeCommand, Result<ThemeResponse>> installThemeCommandHandler)
|
||||
{
|
||||
_installThemeCommandHandler = installThemeCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.POST);
|
||||
Routes(ApiRoutes.Themes.INSTALL_THEME);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Installs the theme pack uploaded in the multipart form of the request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request object.</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)
|
||||
{
|
||||
IFormFile? archive = HttpContext.Request.Form.Files.FirstOrDefault();
|
||||
Result<ThemeResponse> result = await _installThemeCommandHandler.HandleAsync(request.ToCommand(archive?.OpenReadStream(), archive?.FileName), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Themes;
|
||||
using Lumina.Contracts.Responses.Themes;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Themes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Management.InstallTheme;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="InstallThemeEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class InstallThemeEndpointSummary : Summary<InstallThemeEndpoint, InstallThemeRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InstallThemeEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public InstallThemeEndpointSummary()
|
||||
{
|
||||
Summary = "Installs a theme pack.";
|
||||
Description = "Installs the theme pack uploaded in the multipart form of the request, replacing the files of an existing theme with the same manifest id.";
|
||||
|
||||
Response(200, "The theme was successfully installed.",
|
||||
example: new ThemeResponse(
|
||||
Id: Guid.NewGuid(),
|
||||
ThemeId: "lumina-default",
|
||||
Name: "Lumina Default",
|
||||
Description: "A clean, readable theme.",
|
||||
Author: "Lumina Team",
|
||||
Version: "1.2.0",
|
||||
PreviewPath: "preview.png",
|
||||
InstallSource: ThemeInstallSource.Uploaded,
|
||||
IsCurrent: null,
|
||||
InstalledAtUtc: DateTime.UtcNow
|
||||
));
|
||||
|
||||
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"
|
||||
},
|
||||
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"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/themes"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the user is not an Admin, or the uploaded theme pack is not readable.", "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",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Failure",
|
||||
status = 403,
|
||||
detail = "ThemeArchiveNotReadable",
|
||||
instance = "/api/v1/themes",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Failure",
|
||||
status = 403,
|
||||
detail = "ThemeFilesUnreadable",
|
||||
instance = "/api/v1/themes",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-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",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"ThemeArchiveCannotBeNull"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.Themes;
|
||||
using Lumina.Application.Core.Themes.Management.Commands.SetCurrentTheme;
|
||||
using Lumina.Contracts.Requests.Themes;
|
||||
using Lumina.Contracts.Responses.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.SetCurrentTheme;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/themes/current</c> route.
|
||||
/// </summary>
|
||||
public class SetCurrentThemeEndpoint : BaseEndpoint<SetCurrentThemeRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<SetCurrentThemeCommand, Result<ThemeResponse>> _setCurrentThemeCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetCurrentThemeEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="setCurrentThemeCommandHandler">Injected service for handling set current theme commands.</param>
|
||||
public SetCurrentThemeEndpoint(ICommandHandler<SetCurrentThemeCommand, Result<ThemeResponse>> setCurrentThemeCommandHandler)
|
||||
{
|
||||
_setCurrentThemeCommandHandler = setCurrentThemeCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.PUT);
|
||||
Routes(ApiRoutes.Themes.SET_CURRENT_THEME);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the theme stored in <paramref name="request"/> as the currently active theme.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the theme to activate.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(SetCurrentThemeRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<ThemeResponse> result = await _setCurrentThemeCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Themes;
|
||||
using Lumina.Contracts.Responses.Themes;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Themes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Management.SetCurrentTheme;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="SetCurrentThemeEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SetCurrentThemeEndpointSummary : Summary<SetCurrentThemeEndpoint, SetCurrentThemeRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetCurrentThemeEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public SetCurrentThemeEndpointSummary()
|
||||
{
|
||||
Summary = "Sets the currently active theme.";
|
||||
Description = "Sets the theme identified by the request as the currently active theme.";
|
||||
|
||||
ExampleRequest = new SetCurrentThemeRequest(
|
||||
ThemeId: "lumina-default"
|
||||
);
|
||||
|
||||
RequestParam(r => r.ThemeId, "The manifest id of the theme to activate. Required.");
|
||||
|
||||
Response(200, "The theme was successfully activated.",
|
||||
example: new ThemeResponse(
|
||||
Id: Guid.NewGuid(),
|
||||
ThemeId: "lumina-default",
|
||||
Name: "Lumina Default",
|
||||
Description: "A clean, readable theme.",
|
||||
Author: "Lumina Team",
|
||||
Version: "1.2.0",
|
||||
PreviewPath: "preview.png",
|
||||
InstallSource: ThemeInstallSource.Bundled,
|
||||
IsCurrent: true,
|
||||
InstalledAtUtc: DateTime.UtcNow
|
||||
));
|
||||
|
||||
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/current"
|
||||
},
|
||||
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/current"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/themes/current"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the user is not an Admin.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Failure",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = "/api/v1/themes/current",
|
||||
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/current",
|
||||
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/current",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"ThemeIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Themes.Management.Queries.GetCurrentTheme;
|
||||
using Lumina.Contracts.Responses.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.Queries.GetCurrentTheme;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/themes/current</c> route.
|
||||
/// </summary>
|
||||
public class GetCurrentThemeEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetCurrentThemeQuery, Result<ThemeResponse>> _getCurrentThemeQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetCurrentThemeEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getCurrentThemeQueryHandler">Injected service for handling get current theme queries.</param>
|
||||
public GetCurrentThemeEndpoint(IQueryHandler<GetCurrentThemeQuery, Result<ThemeResponse>> getCurrentThemeQueryHandler)
|
||||
{
|
||||
_getCurrentThemeQueryHandler = getCurrentThemeQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Themes.GET_CURRENT_THEME);
|
||||
Version(1);
|
||||
AllowAnonymous();
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently active theme.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest _, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<ThemeResponse> result = await _getCurrentThemeQueryHandler.HandleAsync(new GetCurrentThemeQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Responses.Themes;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Themes;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Queries.GetCurrentTheme;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetCurrentThemeEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetCurrentThemeEndpointSummary : Summary<GetCurrentThemeEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetCurrentThemeEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetCurrentThemeEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the currently active theme.";
|
||||
Description = "Retrieves the metadata of the theme that is currently active.";
|
||||
|
||||
Response(200, "The currently active theme is returned.",
|
||||
example: new ThemeResponse(
|
||||
Id: Guid.NewGuid(),
|
||||
ThemeId: "lumina-default",
|
||||
Name: "Lumina Default",
|
||||
Description: "A clean, readable theme.",
|
||||
Author: "Lumina Team",
|
||||
Version: "1.2.0",
|
||||
PreviewPath: "preview.png",
|
||||
InstallSource: ThemeInstallSource.Bundled,
|
||||
IsCurrent: true,
|
||||
InstalledAtUtc: DateTime.UtcNow
|
||||
));
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.Themes;
|
||||
using Lumina.Application.Core.Themes.Management.Queries.GetThemeArchive;
|
||||
using Lumina.Contracts.Requests.Themes;
|
||||
using Lumina.Contracts.Responses.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.Queries.GetThemeArchive;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/themes/{themeId}/archive</c> route.
|
||||
/// </summary>
|
||||
public class GetThemeArchiveEndpoint : BaseEndpoint<GetThemeArchiveRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetThemeArchiveQuery, Result<ThemeArchiveResponse>> _getThemeArchiveQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThemeArchiveEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getThemeArchiveQueryHandler">Injected service for handling get theme archive queries.</param>
|
||||
public GetThemeArchiveEndpoint(IQueryHandler<GetThemeArchiveQuery, Result<ThemeArchiveResponse>> getThemeArchiveQueryHandler)
|
||||
{
|
||||
_getThemeArchiveQueryHandler = getThemeArchiveQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Themes.GET_THEME_ARCHIVE);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the downloadable archive of the theme identified by <paramref name="request"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the theme to archive.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetThemeArchiveRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<ThemeArchiveResponse> result = await _getThemeArchiveQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.File(success.Bytes, success.ContentType, fileDownloadName: success.FileName), Problem);
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Themes;
|
||||
using Lumina.Contracts.Responses.Themes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Queries.GetThemeArchive;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetThemeArchiveEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThemeArchiveEndpointSummary : Summary<GetThemeArchiveEndpoint, GetThemeArchiveRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThemeArchiveEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetThemeArchiveEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the archive of a theme.";
|
||||
Description = "Retrieves the downloadable ZIP archive of an installed theme.";
|
||||
|
||||
ExampleRequest = new GetThemeArchiveRequest(
|
||||
ThemeId: "lumina-default"
|
||||
);
|
||||
|
||||
RequestParam(r => r.ThemeId, "The manifest id of the theme. Required.");
|
||||
|
||||
Response(200, "The ZIP archive of the theme is returned.", "application/zip",
|
||||
example: new ThemeArchiveResponse(
|
||||
Bytes: [],
|
||||
FileName: "lumina-default.zip",
|
||||
ContentType: "application/zip"
|
||||
));
|
||||
|
||||
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}/archive"
|
||||
},
|
||||
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}/archive"
|
||||
},
|
||||
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}/archive"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
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}/archive",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"ThemeIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-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}/archive",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.Themes;
|
||||
using Lumina.Application.Core.Themes.Management.Queries.GetThemeAsset;
|
||||
using Lumina.Contracts.Requests.Themes;
|
||||
using Lumina.Contracts.Responses.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.Queries.GetThemeAsset;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/themes/{themeId}/assets/{assetPath}</c> route.
|
||||
/// </summary>
|
||||
public class GetThemeAssetEndpoint : BaseEndpoint<GetThemeAssetRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetThemeAssetQuery, Result<ThemeAssetResponse>> _getThemeAssetQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThemeAssetEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getThemeAssetQueryHandler">Injected service for handling get theme asset queries.</param>
|
||||
public GetThemeAssetEndpoint(IQueryHandler<GetThemeAssetQuery, Result<ThemeAssetResponse>> getThemeAssetQueryHandler)
|
||||
{
|
||||
_getThemeAssetQueryHandler = getThemeAssetQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Themes.GET_THEME_ASSET);
|
||||
Version(1);
|
||||
AllowAnonymous();
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the asset of the theme stored in <paramref name="request"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the theme and the path of the asset to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetThemeAssetRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<ThemeAssetResponse> result = await _getThemeAssetQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.File(success.Bytes, success.ContentType), Problem);
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Themes;
|
||||
using Lumina.Contracts.Responses.Themes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Queries.GetThemeAsset;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetThemeAssetEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThemeAssetEndpointSummary : Summary<GetThemeAssetEndpoint, GetThemeAssetRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThemeAssetEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetThemeAssetEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves an asset file of a theme.";
|
||||
Description = "Retrieves the binary content of an asset file of a theme, with its MIME content type.";
|
||||
|
||||
ExampleRequest = new GetThemeAssetRequest(
|
||||
ThemeId: "lumina-default",
|
||||
AssetPath: "assets/style.css"
|
||||
);
|
||||
|
||||
RequestParam(r => r.ThemeId, "The manifest id of the theme. Required.");
|
||||
RequestParam(r => r.AssetPath, "The asset path relative to the theme pack root. Required.");
|
||||
|
||||
Response(200, "The asset file of the theme is returned.", "application/octet-stream");
|
||||
|
||||
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}/assets/{assetPath}",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"ThemeIdCannotBeEmpty",
|
||||
"ThemeAssetPathCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the stored files of the theme are not readable.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Failure",
|
||||
status = 403,
|
||||
detail = "ThemeFilesUnreadable",
|
||||
instance = "/api/v1/themes/{themeId}/assets/{assetPath}",
|
||||
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}/assets/{assetPath}",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Themes.Management.Queries.GetThemeSettings;
|
||||
using Lumina.Contracts.Responses.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.Queries.GetThemeSettings;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/themes/settings</c> route.
|
||||
/// </summary>
|
||||
public class GetThemeSettingsEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetThemeSettingsQuery, Result<ThemeSettingsResponse>> _getThemeSettingsQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThemeSettingsEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getThemeSettingsQueryHandler">Injected service for handling get theme settings queries.</param>
|
||||
public GetThemeSettingsEndpoint(IQueryHandler<GetThemeSettingsQuery, Result<ThemeSettingsResponse>> getThemeSettingsQueryHandler)
|
||||
{
|
||||
_getThemeSettingsQueryHandler = getThemeSettingsQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Themes.GET_THEME_SETTINGS);
|
||||
Version(1);
|
||||
AllowAnonymous();
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the theme engine settings.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest _, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<ThemeSettingsResponse> result = await _getThemeSettingsQueryHandler.HandleAsync(new GetThemeSettingsQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Responses.Themes;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Queries.GetThemeSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetThemeSettingsEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThemeSettingsEndpointSummary : Summary<GetThemeSettingsEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThemeSettingsEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetThemeSettingsEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the theme engine settings.";
|
||||
Description = "Retrieves the settings of the theme engine, including whether theme scripts are allowed and the maximum archive size.";
|
||||
|
||||
Response(200, "The theme engine settings are returned.",
|
||||
example: new ThemeSettingsResponse(
|
||||
MaxArchiveBytes: 8388608,
|
||||
AllowThemeScripts: false,
|
||||
DefaultThemeId: "lumina-default"
|
||||
));
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.Themes;
|
||||
using Lumina.Application.Core.Themes.Management.Queries.GetThemeTemplate;
|
||||
using Lumina.Contracts.Requests.Themes;
|
||||
using Lumina.Contracts.Responses.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.Queries.GetThemeTemplate;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/themes/{themeId}/templates/{pageKey}</c> route.
|
||||
/// </summary>
|
||||
public class GetThemeTemplateEndpoint : BaseEndpoint<GetThemeTemplateRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetThemeTemplateQuery, Result<ThemeTemplateResponse>> _getThemeTemplateQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThemeTemplateEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getThemeTemplateQueryHandler">Injected service for handling get theme template queries.</param>
|
||||
public GetThemeTemplateEndpoint(IQueryHandler<GetThemeTemplateQuery, Result<ThemeTemplateResponse>> getThemeTemplateQueryHandler)
|
||||
{
|
||||
_getThemeTemplateQueryHandler = getThemeTemplateQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Themes.GET_THEME_TEMPLATE);
|
||||
Version(1);
|
||||
AllowAnonymous();
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the template of the theme selected by the page key stored in <paramref name="request"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the theme and the page key of the template to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetThemeTemplateRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<ThemeTemplateResponse> result = await _getThemeTemplateQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Themes;
|
||||
using Lumina.Contracts.Responses.Themes;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Themes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Queries.GetThemeTemplate;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetThemeTemplateEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThemeTemplateEndpointSummary : Summary<GetThemeTemplateEndpoint, GetThemeTemplateRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThemeTemplateEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetThemeTemplateEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the template of a theme.";
|
||||
Description = "Retrieves the raw template of a theme selected by a page key, after applying the theme engine sanitization.";
|
||||
|
||||
ExampleRequest = new GetThemeTemplateRequest(
|
||||
ThemeId: "lumina-default",
|
||||
PageKey: "index"
|
||||
);
|
||||
|
||||
RequestParam(r => r.ThemeId, "The manifest id of the theme. Required.");
|
||||
RequestParam(r => r.PageKey, "The page key that selects the template. Required.");
|
||||
|
||||
Response(200, "The template of the theme is returned.",
|
||||
example: new ThemeTemplateResponse(
|
||||
new ThemeResponse(
|
||||
Id: Guid.NewGuid(),
|
||||
ThemeId: "lumina-default",
|
||||
Name: "Lumina Default",
|
||||
Description: "A clean, readable theme.",
|
||||
Author: "Lumina Team",
|
||||
Version: "1.2.0",
|
||||
PreviewPath: "preview.png",
|
||||
InstallSource: ThemeInstallSource.Bundled,
|
||||
IsCurrent: true,
|
||||
InstalledAtUtc: DateTime.UtcNow
|
||||
),
|
||||
"<html><body><div class=\"content\">{{content}}</div></body></html>"
|
||||
));
|
||||
|
||||
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}/templates/{pageKey}",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"ThemeIdCannotBeEmpty",
|
||||
"PageKeyCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the stored files of the theme are not readable.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Failure",
|
||||
status = 403,
|
||||
detail = "ThemeNotAvailable",
|
||||
instance = "/api/v1/themes/{themeId}/templates/{pageKey}",
|
||||
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}/templates/{pageKey}",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Themes.Management.Queries.GetThemes;
|
||||
using Lumina.Contracts.Responses.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.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Queries.GetThemes;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/themes</c> route.
|
||||
/// </summary>
|
||||
public class GetThemesEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetThemesQuery, Result<IReadOnlyList<ThemeResponse>>> _getThemesQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThemesEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getThemesQueryHandler">Injected service for handling get themes queries.</param>
|
||||
public GetThemesEndpoint(IQueryHandler<GetThemesQuery, Result<IReadOnlyList<ThemeResponse>>> getThemesQueryHandler)
|
||||
{
|
||||
_getThemesQueryHandler = getThemesQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Themes.GET_THEMES);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of all the installed themes.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest _, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<IReadOnlyList<ThemeResponse>> result = await _getThemesQueryHandler.HandleAsync(new GetThemesQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Responses.Themes;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Themes;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Queries.GetThemes;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetThemesEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThemesEndpointSummary : Summary<GetThemesEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThemesEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetThemesEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the installed themes.";
|
||||
Description = "Retrieves the list of all installed themes.";
|
||||
|
||||
Response(200, "The list of installed themes is returned.",
|
||||
example: new ThemeResponse[] {
|
||||
new (
|
||||
Id: Guid.NewGuid(),
|
||||
ThemeId: "lumina-default",
|
||||
Name: "Lumina Default",
|
||||
Description: "A clean, readable theme.",
|
||||
Author: "Lumina Team",
|
||||
Version: "1.2.0",
|
||||
PreviewPath: "preview.png",
|
||||
InstallSource: ThemeInstallSource.Bundled,
|
||||
IsCurrent: true,
|
||||
InstalledAtUtc: DateTime.UtcNow
|
||||
),
|
||||
new (
|
||||
Id: Guid.NewGuid(),
|
||||
ThemeId: "neon-grid",
|
||||
Name: "Neon Grid",
|
||||
Description: "A dark theme with a neon grid background.",
|
||||
Author: "Lumina Team",
|
||||
Version: "0.9.3",
|
||||
PreviewPath: "preview.jpg",
|
||||
InstallSource: ThemeInstallSource.Uploaded,
|
||||
IsCurrent: null,
|
||||
InstalledAtUtc: DateTime.UtcNow
|
||||
)
|
||||
});
|
||||
|
||||
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"
|
||||
},
|
||||
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"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/themes"
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user