From 733e174cacd83629fe3836b92c1de1a891a5e86d Mon Sep 17 00:00:00 2001 From: Binary Alley Date: Mon, 17 Aug 2026 11:36:55 -0700 Subject: [PATCH] feat: adds FastEndpoints core infrastructure and contracts to the web project --- .../Common/Api/ApiHttpClient.cs | 36 +-- .../Common/Api/IApiHttpClient.cs | 4 +- .../Authorization/AuthorizationPolicies.cs | 11 + .../Authorization/AuthorizationService.cs | 38 +-- .../Authorization/IAuthorizationService.cs | 16 -- .../InitializationCheckPreProcessor.cs | 32 +++ .../Authorization/InitializationHandler.cs | 14 +- .../PermissionAuthorizationHandler.cs | 42 ++++ .../Authorization/PermissionRequirement.cs | 26 +++ .../Authorization/RoleAuthorizationHandler.cs | 42 ++++ .../Common/Authorization/RoleRequirement.cs | 25 ++ .../Common/DTO/Authorization/PermissionDto.cs | 18 ++ .../Common/DTO/Authorization/RoleDto.cs | 17 ++ .../DTO/Authorization/RolePermissionsDto.cs | 16 ++ .../DTO/Authorization/UserPermissionsDto.cs | 17 ++ .../Common/DTO/Common/ErrorViewDto.cs | 20 ++ .../Common/DTO/Common/GenreDto.cs | 17 ++ .../Common/DTO/Common/LanguageInfoDto.cs | 27 +++ .../Common/DTO/Common/NotificationDto.cs | 20 ++ .../Common/DTO/Common/ProblemDetailsDto.cs | 52 +++++ .../Common/DTO/Common/RatingDto.cs | 27 +++ .../Common/DTO/Common/ReleaseInfoDto.cs | 44 ++++ .../Common/DTO/Common/SuccessResponse.cs | 13 ++ .../Common/DTO/Common/SuccessResponseOfT.cs | 16 ++ .../Common/DTO/Common/TagDto.cs | 17 ++ .../Configuration/EncryptionSettingsDto.cs | 19 ++ .../Configuration/ServerConfigurationDto.cs | 29 +++ .../DTO/FileSystemManagement/BlobDataDto.cs | 22 ++ .../DTO/FileSystemManagement/DirectoryDto.cs | 18 ++ .../DTO/FileSystemManagement/FileDto.cs | 17 ++ .../FileSystemManagement/FileSystemItemDto.cs | 33 +++ .../FileSystemTreeNodeDto.cs | 44 ++++ .../FileSystemManagement/FileSystemTypeDto.cs | 18 ++ .../DTO/FileSystemManagement/PathExistsDto.cs | 14 ++ .../FileSystemManagement/PathSegmentDto.cs | 17 ++ .../FileSystemManagement/PathSeparatorDto.cs | 14 ++ .../DTO/FileSystemManagement/PathValidDto.cs | 14 ++ .../Common/DTO/Libraries/BookLiteDto.cs | 33 +++ .../Common/DTO/Libraries/LibraryDto.cs | 71 ++++++ .../Libraries/LibraryScanJobProgressDto.cs | 32 +++ .../DTO/Libraries/LibraryScanProgressDto.cs | 53 +++++ .../DTO/Libraries/PaginatedBookLiteDto.cs | 38 +++ .../Common/DTO/Libraries/ScanLibraryDto.cs | 23 ++ .../MediaContributors/MediaContributorDto.cs | 22 ++ .../MediaContributorNameDto.cs | 22 ++ .../MediaContributorRoleDto.cs | 22 ++ .../DTO/Plugins/LibraryMetadataProviderDto.cs | 33 +++ .../Common/DTO/Plugins/PluginDto.cs | 55 +++++ .../DTO/Plugins/PluginSettingDescriptorDto.cs | 39 ++++ .../Common/DTO/Plugins/PluginSettingsDto.cs | 29 +++ .../Common/DTO/UsersManagement/UserDto.cs | 17 ++ .../DTO/UsersManagement/UserSettingsDto.cs | 33 +++ .../BookLibrary/BookDto.cs | 216 ++++++++++++++++++ .../BookLibrary/BookRatingDto.cs | 19 ++ .../BookLibrary/BookSeriesDto.cs | 17 ++ .../BookLibrary/IsbnDto.cs | 23 ++ .../BookLibrary/LightBookDto.cs | 33 +++ .../WrittenContentMetadataDto.cs | 64 ++++++ .../PresentationWebLayerConfiguration.cs | 10 +- .../PresentationWebLayerServices.cs | 67 ++++-- .../Common/Exceptions/ApiException.cs | 6 +- .../Common/Http/RazorViewResult.cs | 65 ++++++ .../Localization/CoreHtmlLocalizerFactory.cs | 55 +++++ .../Requests/Authorization/AddRoleRequest.cs | 18 ++ .../Authorization/DeleteRoleRequest.cs | 15 ++ .../GetRolePermissionsRequest.cs | 15 ++ .../GetUserPermissionsRequest.cs | 15 ++ .../Authorization/GetUserRoleRequest.cs | 15 ++ .../Authorization/UpdateRoleRequest.cs | 20 ++ .../UpdateUserRoleAndPermissionsRequest.cs | 20 ++ .../Common/Requests/Common/EmptyRequest.cs | 6 + .../Directories/GetDirectoriesRequest.cs | 16 ++ .../Files/GetFilesRequest.cs | 16 ++ .../Files/GetTreeFilesRequest.cs | 16 ++ .../Path/CheckPathExistsRequest.cs | 16 ++ .../Path/GetPathParentRequest.cs | 14 ++ .../Path/GetPathRootRequest.cs | 14 ++ .../Path/SplitPathRequest.cs | 14 ++ .../Path/ValidatePathRequest.cs | 14 ++ .../Requests/Libraries/GetBooksLiteRequest.cs | 56 +++++ .../Management/CancelLibraryScanRequest.cs | 17 ++ .../Management/DeleteLibraryRequest.cs | 15 ++ .../Library/Management/EditLibraryRequest.cs | 15 ++ .../Management/GetMetadataProvidersRequest.cs | 15 ++ .../Library/Management/ScanLibraryRequest.cs | 15 ++ .../BookLibrary/Books/GetBookRequest.cs | 15 ++ .../BookLibrary/Books/GetBooksViewRequest.cs | 15 ++ .../Plugins/GetPluginSettingsRequest.cs | 15 ++ .../ReorderLibraryMetadataProvidersRequest.cs | 24 ++ ...etLibraryMetadataProviderEnabledRequest.cs | 29 +++ .../Plugins/UpdatePluginSettingsRequest.cs | 24 ++ .../Requests/Tools/SetLanguageRequest.cs | 16 ++ .../Authentication/LoginViewRequest.cs | 14 ++ .../UsersManagement/ChangePasswordRequest.cs | 20 ++ .../Requests/UsersManagement/LoginRequest.cs | 20 ++ .../UsersManagement/RecoverPasswordRequest.cs | 16 ++ .../UsersManagement/RegisterRequest.cs | 22 ++ .../Authorization/GetAuthorizationResponse.cs | 20 ++ .../UsersManagement/ChangePasswordResponse.cs | 14 ++ .../UsersManagement/InitializationResponse.cs | 17 ++ .../UsersManagement/LoginResponse.cs | 21 ++ .../RecoverPasswordResponse.cs | 14 ++ .../UsersManagement/RegisterResponse.cs | 17 ++ .../Common/Routes/ApiRoutes.Authentication.cs | 19 ++ .../Common/Routes/ApiRoutes.Authorization.cs | 18 ++ .../Common/Routes/ApiRoutes.Books.cs | 15 ++ .../Common/Routes/ApiRoutes.Directories.cs | 15 ++ .../Common/Routes/ApiRoutes.Drives.cs | 15 ++ .../Common/Routes/ApiRoutes.FileSystem.cs | 15 ++ .../Common/Routes/ApiRoutes.Files.cs | 16 ++ .../Common/Routes/ApiRoutes.Initialization.cs | 16 ++ .../Common/Routes/ApiRoutes.Libraries.cs | 28 +++ .../Common/Routes/ApiRoutes.Path.cs | 20 ++ .../Common/Routes/ApiRoutes.Permissions.cs | 15 ++ .../Common/Routes/ApiRoutes.Plugins.cs | 17 ++ .../Common/Routes/ApiRoutes.Roles.cs | 19 ++ .../Common/Routes/ApiRoutes.Users.cs | 16 ++ .../Common/Routes/WebRoutes.Admin.cs | 24 ++ .../Common/Routes/WebRoutes.Authentication.cs | 25 ++ .../Common/Routes/WebRoutes.Books.cs | 17 ++ .../Common/Routes/WebRoutes.Directories.cs | 15 ++ .../Common/Routes/WebRoutes.Drives.cs | 15 ++ .../Common/Routes/WebRoutes.FileSystem.cs | 15 ++ .../Common/Routes/WebRoutes.Files.cs | 16 ++ .../Common/Routes/WebRoutes.Home.cs | 19 ++ .../Common/Routes/WebRoutes.Language.cs | 15 ++ .../Routes/WebRoutes.LibraryManagement.cs | 29 +++ .../Common/Routes/WebRoutes.Path.cs | 20 ++ .../Common/Routes/WebRoutes.Plugins.cs | 18 ++ .../Common/Routes/WebRoutes.Settings.cs | 17 ++ .../Common/Security/CryptographyService.cs | 8 +- .../Services/CachedAuthorizationHandler.cs | 5 +- .../Common/Services/CachedResponse.cs | 23 ++ .../Common/Services/IUrlService.cs | 13 +- .../Common/Services/UrlService.cs | 78 ++++--- .../EncryptionSettingsModelValidator.cs | 4 +- .../ServerConfigurationModelValidator.cs | 4 +- 137 files changed, 3139 insertions(+), 158 deletions(-) create mode 100644 src/Lumina.Presentation.Web/Common/Authorization/AuthorizationPolicies.cs create mode 100644 src/Lumina.Presentation.Web/Common/Authorization/InitializationCheckPreProcessor.cs create mode 100644 src/Lumina.Presentation.Web/Common/Authorization/PermissionAuthorizationHandler.cs create mode 100644 src/Lumina.Presentation.Web/Common/Authorization/PermissionRequirement.cs create mode 100644 src/Lumina.Presentation.Web/Common/Authorization/RoleAuthorizationHandler.cs create mode 100644 src/Lumina.Presentation.Web/Common/Authorization/RoleRequirement.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Authorization/PermissionDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Authorization/RoleDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Authorization/RolePermissionsDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Authorization/UserPermissionsDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Common/ErrorViewDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Common/GenreDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Common/LanguageInfoDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Common/NotificationDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Common/ProblemDetailsDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Common/RatingDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Common/ReleaseInfoDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Common/SuccessResponse.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Common/SuccessResponseOfT.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Common/TagDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Configuration/EncryptionSettingsDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Configuration/ServerConfigurationDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/BlobDataDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/DirectoryDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/FileDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/FileSystemItemDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/FileSystemTreeNodeDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/FileSystemTypeDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/PathExistsDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/PathSegmentDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/PathSeparatorDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/PathValidDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Libraries/BookLiteDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryScanJobProgressDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryScanProgressDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Libraries/PaginatedBookLiteDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Libraries/ScanLibraryDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/MediaContributors/MediaContributorDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/MediaContributors/MediaContributorNameDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/MediaContributors/MediaContributorRoleDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Plugins/LibraryMetadataProviderDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Plugins/PluginDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Plugins/PluginSettingDescriptorDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Plugins/PluginSettingsDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/UsersManagement/UserDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/UsersManagement/UserSettingsDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/BookDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/BookRatingDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/BookSeriesDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/IsbnDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/LightBookDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/WrittenContentMetadataDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/Http/RazorViewResult.cs create mode 100644 src/Lumina.Presentation.Web/Common/Localization/CoreHtmlLocalizerFactory.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Authorization/AddRoleRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Authorization/DeleteRoleRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Authorization/GetRolePermissionsRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Authorization/GetUserPermissionsRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Authorization/GetUserRoleRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Authorization/UpdateRoleRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Authorization/UpdateUserRoleAndPermissionsRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Common/EmptyRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Directories/GetDirectoriesRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Files/GetFilesRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Files/GetTreeFilesRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/CheckPathExistsRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/GetPathParentRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/GetPathRootRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/SplitPathRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/ValidatePathRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Libraries/GetBooksLiteRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Library/Management/CancelLibraryScanRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Library/Management/DeleteLibraryRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Library/Management/EditLibraryRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Library/Management/GetMetadataProvidersRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Library/Management/ScanLibraryRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Library/WrittenContentLibrary/BookLibrary/Books/GetBookRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Library/WrittenContentLibrary/BookLibrary/Books/GetBooksViewRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Plugins/GetPluginSettingsRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Plugins/ReorderLibraryMetadataProvidersRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Plugins/SetLibraryMetadataProviderEnabledRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Plugins/UpdatePluginSettingsRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Tools/SetLanguageRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/UsersManagement/Authentication/LoginViewRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/UsersManagement/ChangePasswordRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/UsersManagement/LoginRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/UsersManagement/RecoverPasswordRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/UsersManagement/RegisterRequest.cs create mode 100644 src/Lumina.Presentation.Web/Common/Responses/Authorization/GetAuthorizationResponse.cs create mode 100644 src/Lumina.Presentation.Web/Common/Responses/UsersManagement/ChangePasswordResponse.cs create mode 100644 src/Lumina.Presentation.Web/Common/Responses/UsersManagement/InitializationResponse.cs create mode 100644 src/Lumina.Presentation.Web/Common/Responses/UsersManagement/LoginResponse.cs create mode 100644 src/Lumina.Presentation.Web/Common/Responses/UsersManagement/RecoverPasswordResponse.cs create mode 100644 src/Lumina.Presentation.Web/Common/Responses/UsersManagement/RegisterResponse.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Authentication.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Authorization.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Books.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Directories.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Drives.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.FileSystem.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Files.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Initialization.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Libraries.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Path.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Permissions.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Plugins.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Roles.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Users.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Admin.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Authentication.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Books.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Directories.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Drives.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/WebRoutes.FileSystem.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Files.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Home.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Language.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/WebRoutes.LibraryManagement.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Path.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Plugins.cs create mode 100644 src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Settings.cs create mode 100644 src/Lumina.Presentation.Web/Common/Services/CachedResponse.cs diff --git a/src/Lumina.Presentation.Web/Common/Api/ApiHttpClient.cs b/src/Lumina.Presentation.Web/Common/Api/ApiHttpClient.cs index 350dce6b..f0651b05 100644 --- a/src/Lumina.Presentation.Web/Common/Api/ApiHttpClient.cs +++ b/src/Lumina.Presentation.Web/Common/Api/ApiHttpClient.cs @@ -1,8 +1,8 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.DTO.Common; +using Lumina.Presentation.Web.Common.DTO.Configuration; +using Lumina.Presentation.Web.Common.DTO.FileSystemManagement; using Lumina.Presentation.Web.Common.Exceptions; -using Lumina.Presentation.Web.Common.Models.Common; -using Lumina.Presentation.Web.Common.Models.Configuration; -using Lumina.Presentation.Web.Common.Models.FileSystemManagement; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; using System; @@ -35,13 +35,13 @@ public class ApiHttpClient : IApiHttpClient /// Injected HttpClient for interacting with the API. /// Injected service for providing the current HTTP context. /// Injected server configuration application settings. - public ApiHttpClient(HttpClient httpClient, IHttpContextAccessor httpContextAccessor, IOptionsSnapshot serverConfigurationOptions) + public ApiHttpClient(HttpClient httpClient, IHttpContextAccessor httpContextAccessor, IOptionsSnapshot serverConfigurationOptions) { _httpClient = httpClient; _httpContext = httpContextAccessor.HttpContext; // read the API server configuration values from the configuration, and assign them to the injected client - ServerConfigurationModel serverConfigurationModel = serverConfigurationOptions.Value; - httpClient.BaseAddress = new Uri($"{serverConfigurationModel.BaseAddress}:{serverConfigurationModel.Port}/api/v{serverConfigurationModel.ApiVersion}/"); + ServerConfigurationDto serverConfiguration = serverConfigurationOptions.Value; + httpClient.BaseAddress = new Uri($"{serverConfiguration.BaseAddress}:{serverConfiguration.Port}/api/v{serverConfiguration.ApiVersion}/"); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); @@ -101,7 +101,7 @@ public class ApiHttpClient : IApiHttpClient /// The API endpoint where the request is being sent. /// Cancellation token that can be used to stop the execution. /// A model containing the deserialized blob. - public async Task GetBlobAsync(string endpoint, CancellationToken cancellationToken = default) + public async Task GetBlobAsync(string endpoint, CancellationToken cancellationToken = default) { using HttpRequestMessage request = new(HttpMethod.Get, endpoint); AuthenticationHeaderValue? authenticationHeader = GetAuthenticationHeader(); @@ -112,10 +112,10 @@ public class ApiHttpClient : IApiHttpClient { // read the content as a string, for error messages string content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - ProblemDetailsModel? problemDetails = null; + ProblemDetailsDto? problemDetails = null; try { - problemDetails = JsonSerializer.Deserialize(content, _jsonOptions); + problemDetails = JsonSerializer.Deserialize(content, _jsonOptions); } catch { /* if we can't deserialize to ProblemDetails, we'll just use the status code */ } throw new ApiException(problemDetails, response.StatusCode); @@ -123,7 +123,7 @@ public class ApiHttpClient : IApiHttpClient // if the response is successful, read it as a byte array byte[] responseContent = await response.Content.ReadAsByteArrayAsync(cancellationToken).ConfigureAwait(false); string contentType = response.Content.Headers.ContentType?.ToString() ?? "application/octet-stream"; - return new BlobDataModel { Data = responseContent, ContentType = contentType }; + return new BlobDataDto { Data = responseContent, ContentType = contentType }; } /// @@ -142,12 +142,12 @@ public class ApiHttpClient : IApiHttpClient HttpResponseMessage response = await _httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - ProblemDetailsModel? problemDetails = null; + ProblemDetailsDto? problemDetails = null; string content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - // attempt to deserialize the response content to ProblemDetailsModel if the request fails + // attempt to deserialize the response content to ProblemDetailsDto if the request fails try { - problemDetails = JsonSerializer.Deserialize(content, _jsonOptions); + problemDetails = JsonSerializer.Deserialize(content, _jsonOptions); } catch { /* if we can't deserialize to ProblemDetails, we'll just use the status code */ } throw new ApiException(problemDetails, response.StatusCode, request.RequestUri?.AbsolutePath); @@ -194,13 +194,13 @@ public class ApiHttpClient : IApiHttpClient /// /// Sends an HTTP request and deserializes the response into the specified type if the request is successful. - /// If the request fails, it attempts to deserialize the response content into a and throws an . + /// If the request fails, it attempts to deserialize the response content into a and throws an . /// /// The expected type of the response content. /// The to be sent. /// Cancellation token that can be used to stop the execution. /// The deserialized response content as an object of type . - /// Thrown if the response is not successful, with the if available. + /// Thrown if the response is not successful, with the if available. private async Task SendRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) { // send the HTTP request and read the response @@ -216,11 +216,11 @@ public class ApiHttpClient : IApiHttpClient } else { - ProblemDetailsModel? problemDetails = null; - // attempt to deserialize the response content to ProblemDetailsModel if the request fails + ProblemDetailsDto? problemDetails = null; + // attempt to deserialize the response content to ProblemDetailsDto if the request fails try { - problemDetails = JsonSerializer.Deserialize(content, _jsonOptions); + problemDetails = JsonSerializer.Deserialize(content, _jsonOptions); } catch { /* if we can't deserialize to ProblemDetails, we'll just use the status code */ } throw new ApiException(problemDetails, response.StatusCode, request.RequestUri?.AbsolutePath); diff --git a/src/Lumina.Presentation.Web/Common/Api/IApiHttpClient.cs b/src/Lumina.Presentation.Web/Common/Api/IApiHttpClient.cs index 86a1e71d..cfbb30ad 100644 --- a/src/Lumina.Presentation.Web/Common/Api/IApiHttpClient.cs +++ b/src/Lumina.Presentation.Web/Common/Api/IApiHttpClient.cs @@ -1,5 +1,5 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Presentation.Web.Common.Models.FileSystemManagement; +using Lumina.Presentation.Web.Common.DTO.FileSystemManagement; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -36,7 +36,7 @@ public interface IApiHttpClient /// The API endpoint where the request is being sent. /// Cancellation token that can be used to stop the execution. /// A model containing the deserialized blob. - Task GetBlobAsync(string endpoint, CancellationToken cancellationToken = default); + Task GetBlobAsync(string endpoint, CancellationToken cancellationToken = default); /// /// Sends a DELETE request to the specified as an asynchronous operation. diff --git a/src/Lumina.Presentation.Web/Common/Authorization/AuthorizationPolicies.cs b/src/Lumina.Presentation.Web/Common/Authorization/AuthorizationPolicies.cs new file mode 100644 index 00000000..87034320 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Authorization/AuthorizationPolicies.cs @@ -0,0 +1,11 @@ +namespace Lumina.Presentation.Web.Common.Authorization; + +/// +/// Contains the names of the authorization policies defined in the Web application. +/// +public static class AuthorizationPolicies +{ + public const string REQUIRE_ADMIN_ROLE = "RequireAdminRole"; + public const string REQUIRE_CREATE_LIBRARIES_PERMISSION = "RequireCreateLibrariesPermission"; + public const string REQUIRE_INITIALIZATION = "RequireInitialization"; +} diff --git a/src/Lumina.Presentation.Web/Common/Authorization/AuthorizationService.cs b/src/Lumina.Presentation.Web/Common/Authorization/AuthorizationService.cs index f6357404..b47d54e2 100644 --- a/src/Lumina.Presentation.Web/Common/Authorization/AuthorizationService.cs +++ b/src/Lumina.Presentation.Web/Common/Authorization/AuthorizationService.cs @@ -1,7 +1,7 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Presentation.Web.Common.Api; using Lumina.Presentation.Web.Common.Enums.Authorization; -using Lumina.Presentation.Web.Common.Models.Authorization; +using Lumina.Presentation.Web.Common.Responses.Authorization; using Microsoft.AspNetCore.Http; using System; using System.Linq; @@ -55,42 +55,6 @@ public class AuthorizationService : IAuthorizationService return authorization.Role == role; } - /// - /// Evaluates whether the currently logged in user meets the conditions defined in the specified authorization policy. - /// - /// The type of authorization policy to evaluate. - /// Cancellation token that can be used to stop the execution. - /// if the currently logged in user satisfies the policy, otherwise. - public Task EvaluatePolicyAsync(CancellationToken cancellationToken) - { - throw new NotImplementedException(); - } - - /// - /// Evaluates whether the currently logged in user meets the conditions defined in the specified authorization requirement. - /// - /// The authorization requirements to check. - /// if the currently logged in user satisfies the requirement, otherwise. - public async Task EvaluateAuthorizationAsync(AuthorizationRequirementModel requirement) - { - GetAuthorizationResponse authorization = await GetUserAuthorizationAsync(CancellationToken.None); - - if (requirement.Roles?.Length > 0 && !requirement.Roles.Any(role => authorization.Role?.Contains(role) == true)) - return false; - - if (requirement.Permissions?.Length > 0 && !requirement.Permissions.Any(permission => authorization.Permissions.Contains(permission))) - return false; - - //if (_requirement.PolicyType is not null) - //{ - // bool response = await _apiHttpClient.PostAsync($"auth/evaluate-policy/{_requirement.PolicyType.Name}", null!); - // if (!response) - // return false; - //} - - return true; - } - /// /// Retrieves user authorization details from the authorization service. /// diff --git a/src/Lumina.Presentation.Web/Common/Authorization/IAuthorizationService.cs b/src/Lumina.Presentation.Web/Common/Authorization/IAuthorizationService.cs index 7a0481be..462ab82d 100644 --- a/src/Lumina.Presentation.Web/Common/Authorization/IAuthorizationService.cs +++ b/src/Lumina.Presentation.Web/Common/Authorization/IAuthorizationService.cs @@ -1,6 +1,5 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Presentation.Web.Common.Enums.Authorization; -using Lumina.Presentation.Web.Common.Models.Authorization; using System.Threading; using System.Threading.Tasks; #endregion @@ -27,19 +26,4 @@ public interface IAuthorizationService /// Cancellation token that can be used to stop the execution. /// if the currently logged in user is in the specified role, otherwise. Task IsInRoleAsync(string role, CancellationToken cancellationToken); - - /// - /// Evaluates whether the currently logged in user meets the conditions defined in the specified authorization policy. - /// - /// The type of authorization policy to evaluate. - /// Cancellation token that can be used to stop the execution. - /// if the currently logged in user satisfies the policy, otherwise. - Task EvaluatePolicyAsync(CancellationToken cancellationToken); - - /// - /// Evaluates whether the currently logged in user meets the conditions defined in the specified authorization requirement. - /// - /// The authorization requirements to check. - /// if the currently logged in user satisfies the requirement, otherwise. - Task EvaluateAuthorizationAsync(AuthorizationRequirementModel requirement); } diff --git a/src/Lumina.Presentation.Web/Common/Authorization/InitializationCheckPreProcessor.cs b/src/Lumina.Presentation.Web/Common/Authorization/InitializationCheckPreProcessor.cs new file mode 100644 index 00000000..3e84c97d --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Authorization/InitializationCheckPreProcessor.cs @@ -0,0 +1,32 @@ +#region ========================================================================= USING ===================================================================================== +using FastEndpoints; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Presentation.Web.Common.Authorization; + +/// +/// FastEndpoints pre-processor that runs the application initialization check before the endpoint handler executes. +/// +/// +/// The check runs the RequireInitialization authorization policy, which queries the remote API and records the pending super admin setup state in the session. +/// Its result is deliberately ignored, because the pages that use this processor must be reachable both before and after the application is initialized. +/// +/// The type of the request of the endpoint to which this pre-processor is applied. +public class InitializationCheckPreProcessor : IPreProcessor where TRequest : notnull +{ + /// + /// Runs the initialization check for the current request. + /// + /// The pre-processor context for the current request. + /// Cancellation token that can be used to stop the execution. + public async Task PreProcessAsync(IPreProcessorContext preProcessorContext, CancellationToken cancellationToken) + { + HttpContext httpContext = preProcessorContext.HttpContext; + Microsoft.AspNetCore.Authorization.IAuthorizationService authorizationService = httpContext.RequestServices.GetRequiredService(); + await authorizationService.AuthorizeAsync(httpContext.User, httpContext, AuthorizationPolicies.REQUIRE_INITIALIZATION).ConfigureAwait(false); + } +} diff --git a/src/Lumina.Presentation.Web/Common/Authorization/InitializationHandler.cs b/src/Lumina.Presentation.Web/Common/Authorization/InitializationHandler.cs index 51dd850c..02788de9 100644 --- a/src/Lumina.Presentation.Web/Common/Authorization/InitializationHandler.cs +++ b/src/Lumina.Presentation.Web/Common/Authorization/InitializationHandler.cs @@ -1,7 +1,7 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Presentation.Web.Common.Api; using Lumina.Presentation.Web.Common.Http; -using Lumina.Presentation.Web.Common.Models.UsersManagement; +using Lumina.Presentation.Web.Common.Responses.UsersManagement; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using System.Threading.Tasks; @@ -28,17 +28,17 @@ public class InitializationHandler : AuthorizationHandler /// Checks the application initialization status and authorizes the requirement if initialized. /// - /// The authorization context. - /// The initialization requirement to be evaluated. - protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, InitializationRequirement requirement) + /// The authorization context. + /// The initialization requirement to be evaluated. + protected override async Task HandleRequirementAsync(AuthorizationHandlerContext authorizationHandlerContext, InitializationRequirement initializationRequirement) { - InitializationModel result = await _apiHttpClient.GetAsync("initialization/").ConfigureAwait(false); - HttpContext? httpContext = context.Resource as HttpContext; + InitializationResponse result = await _apiHttpClient.GetAsync("initialization/").ConfigureAwait(false); + HttpContext? httpContext = authorizationHandlerContext.Resource as HttpContext; if (result.IsInitialized) { // admin account was registered, remove this requirement from the session httpContext?.Session.Remove(HttpContextItemKeys.PENDING_SUPER_ADMIN_SETUP); - context.Succeed(requirement); + authorizationHandlerContext.Succeed(initializationRequirement); } else // store in session that super admin setup is needed httpContext?.Session.SetString(HttpContextItemKeys.PENDING_SUPER_ADMIN_SETUP, "true"); diff --git a/src/Lumina.Presentation.Web/Common/Authorization/PermissionAuthorizationHandler.cs b/src/Lumina.Presentation.Web/Common/Authorization/PermissionAuthorizationHandler.cs new file mode 100644 index 00000000..ce4b912b --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Authorization/PermissionAuthorizationHandler.cs @@ -0,0 +1,42 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Authorization; +using Microsoft.AspNetCore.Authorization; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Presentation.Web.Common.Authorization; + +/// +/// Handles the by checking the currently logged in user's permissions against the remote API. +/// +public class PermissionAuthorizationHandler : AuthorizationHandler +{ + private readonly IAuthorizationService _authorizationService; + + /// + /// Initializes a new instance of the class. + /// + /// Injected service for authorization checks against the remote API. + public PermissionAuthorizationHandler(IAuthorizationService authorizationService) + { + _authorizationService = authorizationService; + } + + /// + /// Succeeds the requirement when the currently logged in user holds any of the required permissions. + /// + /// The authorization context. + /// The permission requirement to evaluate. + protected override async Task HandleRequirementAsync(AuthorizationHandlerContext authorizationHandlerContext, PermissionRequirement permissionRequirement) + { + foreach (AuthorizationPermission permission in permissionRequirement.Permissions) + { + if (await _authorizationService.HasPermissionAsync(permission, CancellationToken.None).ConfigureAwait(false)) + { + authorizationHandlerContext.Succeed(permissionRequirement); + return; + } + } + } +} diff --git a/src/Lumina.Presentation.Web/Common/Authorization/PermissionRequirement.cs b/src/Lumina.Presentation.Web/Common/Authorization/PermissionRequirement.cs new file mode 100644 index 00000000..8eb80a9c --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Authorization/PermissionRequirement.cs @@ -0,0 +1,26 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Authorization; +using Microsoft.AspNetCore.Authorization; +#endregion + +namespace Lumina.Presentation.Web.Common.Authorization; + +/// +/// Defines a requirement that the user must hold at least one of the specified permissions. +/// +public class PermissionRequirement : IAuthorizationRequirement +{ + /// + /// Gets the permissions that allow access, of which the user must hold at least one. + /// + public AuthorizationPermission[] Permissions { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The permissions that allow access. + public PermissionRequirement(params AuthorizationPermission[] permissions) + { + Permissions = permissions; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Authorization/RoleAuthorizationHandler.cs b/src/Lumina.Presentation.Web/Common/Authorization/RoleAuthorizationHandler.cs new file mode 100644 index 00000000..30657694 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Authorization/RoleAuthorizationHandler.cs @@ -0,0 +1,42 @@ +#region ========================================================================= USING ===================================================================================== +using Microsoft.AspNetCore.Authorization; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Presentation.Web.Common.Authorization; + +/// +/// Handles the by checking the currently logged in user's role against the remote API. +/// +public class RoleAuthorizationHandler : AuthorizationHandler +{ + private readonly IAuthorizationService _authorizationService; + + /// + /// Initializes a new instance of the class. + /// + /// Injected service for authorization checks against the remote API. + public RoleAuthorizationHandler(IAuthorizationService authorizationService) + { + _authorizationService = authorizationService; + } + + /// + /// Succeeds the requirement when the currently logged in user belongs to any of the required roles. + /// + /// The authorization context. + /// The role requirement to evaluate. + protected override async Task HandleRequirementAsync(AuthorizationHandlerContext authorizationHandlerContext, RoleRequirement roleRequirement) + { + foreach (string role in roleRequirement.Roles) + { + if (await _authorizationService.IsInRoleAsync(role, CancellationToken.None).ConfigureAwait(false)) + { + authorizationHandlerContext.Succeed(roleRequirement); + return; + } + } + } +} diff --git a/src/Lumina.Presentation.Web/Common/Authorization/RoleRequirement.cs b/src/Lumina.Presentation.Web/Common/Authorization/RoleRequirement.cs new file mode 100644 index 00000000..eb82ef3c --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Authorization/RoleRequirement.cs @@ -0,0 +1,25 @@ +#region ========================================================================= USING ===================================================================================== +using Microsoft.AspNetCore.Authorization; +#endregion + +namespace Lumina.Presentation.Web.Common.Authorization; + +/// +/// Defines a requirement that the user must belong to at least one of the specified roles. +/// +public class RoleRequirement : IAuthorizationRequirement +{ + /// + /// Gets the roles that allow access, of which the user must belong to at least one. + /// + public string[] Roles { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The roles that allow access. + public RoleRequirement(params string[] roles) + { + Roles = roles; + } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Authorization/PermissionDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Authorization/PermissionDto.cs new file mode 100644 index 00000000..f2c78c77 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Authorization/PermissionDto.cs @@ -0,0 +1,18 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Authorization; +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Authorization; + +/// +/// Data transfer object for an authorization permission. +/// +/// The unique identifier of the permission. +/// The name of the permission. +[DebuggerDisplay("Id: {Id}, PermissionName: {PermissionName}")] +public record PermissionDto( + Guid Id, + AuthorizationPermission PermissionName +); diff --git a/src/Lumina.Presentation.Web/Common/DTO/Authorization/RoleDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Authorization/RoleDto.cs new file mode 100644 index 00000000..d815d97f --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Authorization/RoleDto.cs @@ -0,0 +1,17 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Authorization; + +/// +/// Data transfer object for an authorization role. +/// +/// The unique identifier of the role. +/// The name of the role. +[DebuggerDisplay("Id: {Id}, RoleName: {RoleName}")] +public record RoleDto( + Guid Id, + string RoleName +); diff --git a/src/Lumina.Presentation.Web/Common/DTO/Authorization/RolePermissionsDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Authorization/RolePermissionsDto.cs new file mode 100644 index 00000000..218bbb79 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Authorization/RolePermissionsDto.cs @@ -0,0 +1,16 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Authorization; + +/// +/// Data transfer object for a model for an authorization role with its permissions. +/// +/// The authorization role. +/// The permissions of the authorization role. +[DebuggerDisplay("Role: {Role}")] +public record RolePermissionsDto( + RoleDto Role, + PermissionDto[] Permissions +); diff --git a/src/Lumina.Presentation.Web/Common/DTO/Authorization/UserPermissionsDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Authorization/UserPermissionsDto.cs new file mode 100644 index 00000000..1dc5a417 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Authorization/UserPermissionsDto.cs @@ -0,0 +1,17 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.DTO.UsersManagement; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Authorization; + +/// +/// Data transfer object for a user with its authorization permissions. +/// +/// The user. +/// The authorization permissions of the user. +[DebuggerDisplay("User: {User}")] +public record UserPermissionsDto( + UserDto User, + PermissionDto[] Permissions +); diff --git a/src/Lumina.Presentation.Web/Common/DTO/Common/ErrorViewDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Common/ErrorViewDto.cs new file mode 100644 index 00000000..2790c5b0 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Common/ErrorViewDto.cs @@ -0,0 +1,20 @@ +using System.Diagnostics; + +namespace Lumina.Presentation.Web.Common.DTO.Common; + +/// +/// Data transfer object for the data shown on the error page. +/// +[DebuggerDisplay("RequestId: {RequestId}, ShowRequestId: {ShowRequestId}")] +public class ErrorViewDto +{ + /// + /// Gets or sets the request identifier to display. + /// + public string? RequestId { get; set; } + + /// + /// Gets a value indicating whether the request identifier should be shown. + /// + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Common/GenreDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Common/GenreDto.cs new file mode 100644 index 00000000..5bda54a8 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Common/GenreDto.cs @@ -0,0 +1,17 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Common; + +/// +/// Data transfer object for a request to get genre information. +/// +[DebuggerDisplay("{Name}")] +public class GenreDto +{ + /// + /// Gets the name of the genre element of the media item. + /// + public string? Name { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Common/LanguageInfoDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Common/LanguageInfoDto.cs new file mode 100644 index 00000000..9d2689a4 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Common/LanguageInfoDto.cs @@ -0,0 +1,27 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Common; + +/// +/// Data transfer object for a request to get language information. +/// +[DebuggerDisplay("{LanguageName}")] +public class LanguageInfoDto +{ + /// + /// Gets the ISO 639-1 two-letter language code. + /// + public string? LanguageCode { get; set; } + + /// + /// Gets the full name of the language in English. + /// + public string? LanguageName { get; set; } + + /// + /// Gets an optional native name of the language. + /// + public string? NativeName { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Common/NotificationDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Common/NotificationDto.cs new file mode 100644 index 00000000..3131e6e3 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Common/NotificationDto.cs @@ -0,0 +1,20 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Notifications; +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Common; + +/// +/// Data transfer object for notifications. +/// +/// The id of the notification. +/// The message of the notification. +/// The type of the notification. +[DebuggerDisplay("Id: {Id}, Message: {Message}")] +public record struct NotificationDto( + Guid Id, + string Message, + NotificationType Type +); diff --git a/src/Lumina.Presentation.Web/Common/DTO/Common/ProblemDetailsDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Common/ProblemDetailsDto.cs new file mode 100644 index 00000000..915399b4 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Common/ProblemDetailsDto.cs @@ -0,0 +1,52 @@ +#region ========================================================================= USING ===================================================================================== +using System.Collections.Generic; +using System.Diagnostics; +using System.Text.Json; +using System.Text.Json.Serialization; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Common; + +/// +/// Data transfer object that follows the RFC 7807 standard for problem details in HTTP APIs. +/// +[DebuggerDisplay("{Title} ({Status})")] +public class ProblemDetailsDto +{ + /// + /// Gets or sets the URI reference that identifies the problem type. + /// + [JsonPropertyName("type")] + public string? Type { get; set; } + + /// + /// Gets or sets a short, human-readable summary of the problem type. + /// + [JsonPropertyName("title")] + public string? Title { get; set; } + + /// + /// Gets or sets the HTTP status code generated by the server for this occurrence of the problem. + /// + [JsonPropertyName("status")] + public int? Status { get; set; } + + /// + /// Gets or sets a detailed explanation specific to this occurrence of the problem. + /// + [JsonPropertyName("detail")] + public string? Detail { get; set; } + + /// + /// Gets or sets a URI reference that identifies the specific occurrence of the problem. + /// + [JsonPropertyName("instance")] + public string? Instance { get; set; } + + /// + /// Gets or sets additional extension data that may be included with the problem details. + /// This allows for including extra, non-standard fields in the problem details. + /// + [JsonExtensionData] + public IDictionary? Extensions { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Common/RatingDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Common/RatingDto.cs new file mode 100644 index 00000000..a9202026 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Common/RatingDto.cs @@ -0,0 +1,27 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Common; + +/// +/// Data transfer object for a rating. +/// +[DebuggerDisplay("Value: {Value}, MaxValue: {MaxValue}")] +public abstract class RatingDto +{ + /// + /// Gets the numeric value of the rating. + /// + public decimal? Value { get; set; } + + /// + /// Gets the maximum possible rating value. + /// + public decimal? MaxValue { get; set; } + + /// + /// Gets the optional number of votes or reviews this rating is based on. + /// + public int? VoteCount { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Common/ReleaseInfoDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Common/ReleaseInfoDto.cs new file mode 100644 index 00000000..9050347c --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Common/ReleaseInfoDto.cs @@ -0,0 +1,44 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Common; + +/// +/// Data transfer object for a request to get release information. +/// +[DebuggerDisplay("OriginalReleaseDate: {OriginalReleaseDate}")] +public class ReleaseInfoDto +{ + /// + /// Gets the optional original release date of the media item. + /// + public DateOnly? OriginalReleaseDate { get; set; } + + /// + /// Gets the optional original release year of the media item. + /// This is useful when only the year of original release is known. + /// + public int? OriginalReleaseYear { get; set; } + + /// + /// Gets the optional re-release or reissue date of the media item. + /// + public DateOnly? ReReleaseDate { get; set; } + + /// + /// Gets the optional re-release or reissue year of the media item. + /// + public int? ReReleaseYear { get; set; } + + /// + /// Gets the optional country or region of release. + /// + public string? ReleaseCountry { get; set; } + + /// + /// Gets the optional release version or edition. (e.g. "Original", "Director's Cut", "2.0") + /// + public string? ReleaseVersion { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Common/SuccessResponse.cs b/src/Lumina.Presentation.Web/Common/DTO/Common/SuccessResponse.cs new file mode 100644 index 00000000..b776c4e1 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Common/SuccessResponse.cs @@ -0,0 +1,13 @@ +#region ========================================================================= USING ===================================================================================== +using System.Text.Json.Serialization; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Common; + +/// +/// Response data transfer object for the JSON responses of the web application that do not carry a payload. +/// +/// Whether the operation succeeded or not. +public record SuccessResponse( + [property: JsonPropertyName("success")] bool Success +); diff --git a/src/Lumina.Presentation.Web/Common/DTO/Common/SuccessResponseOfT.cs b/src/Lumina.Presentation.Web/Common/DTO/Common/SuccessResponseOfT.cs new file mode 100644 index 00000000..70e8e767 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Common/SuccessResponseOfT.cs @@ -0,0 +1,16 @@ +#region ========================================================================= USING ===================================================================================== +using System.Text.Json.Serialization; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Common; + +/// +/// Response data transfer object for the JSON responses of the web application that carry a payload. +/// +/// The type of the payload of the response. +/// Whether the operation succeeded or not. +/// The payload of the response. +public record SuccessResponse( + [property: JsonPropertyName("success")] bool Success, + [property: JsonPropertyName("data")] TData? Data +); diff --git a/src/Lumina.Presentation.Web/Common/DTO/Common/TagDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Common/TagDto.cs new file mode 100644 index 00000000..ebb1b0f2 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Common/TagDto.cs @@ -0,0 +1,17 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Common; + +/// +/// Data transfer object for a request to get tag information. +/// +[DebuggerDisplay("Name: {Name}")] +public class TagDto +{ + /// + /// Gets the name of the tag element of the media item. + /// + public string? Name { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Configuration/EncryptionSettingsDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Configuration/EncryptionSettingsDto.cs new file mode 100644 index 00000000..50c288b1 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Configuration/EncryptionSettingsDto.cs @@ -0,0 +1,19 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Configuration; + +/// +/// Data transfer object for deserializing media settings. +/// +[DebuggerDisplay("Section name: {SECTION_NAME}")] +public class EncryptionSettingsDto +{ + public const string SECTION_NAME = "EncryptionSettings"; + + /// + /// Gets or sets the root directory where media files are stored. + /// + public required string SecretKey { get; init; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Configuration/ServerConfigurationDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Configuration/ServerConfigurationDto.cs new file mode 100644 index 00000000..43dbc4f1 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Configuration/ServerConfigurationDto.cs @@ -0,0 +1,29 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Configuration; + +/// +/// Data transfer object for deserializing server configuration settings. +/// +[DebuggerDisplay("Section name: {SECTION_NAME}")] +public class ServerConfigurationDto +{ + public const string SECTION_NAME = "ServerConfiguration"; + + /// + /// Gets or sets the remote API server path. + /// + public required char ApiVersion { get; init; } + + /// + /// Gets or sets the remote API server path. + /// + public required string BaseAddress { get; init; } + + /// + /// Gets or sets the remote API server port. + /// + public required ushort Port { get; init; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/BlobDataDto.cs b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/BlobDataDto.cs new file mode 100644 index 00000000..d88611f4 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/BlobDataDto.cs @@ -0,0 +1,22 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement; + +/// +/// Data transfer object for a model for storing binary data (blob). +/// +[DebuggerDisplay("ContentType: {ContentType} (Data.Length)")] +public class BlobDataDto +{ + /// + /// Gets or sets the binary data as a byte array. + /// + public byte[] Data { get; set; } = null!; + + /// + /// Gets or sets the content type (MIME type) of the blob data, such as "image/png" for an image or "application/pdf" for a PDF document. + /// + public string ContentType { get; set; } = null!; +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/DirectoryDto.cs b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/DirectoryDto.cs new file mode 100644 index 00000000..831c2ccb --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/DirectoryDto.cs @@ -0,0 +1,18 @@ +#region ========================================================================= USING ===================================================================================== +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement; + +/// +/// Data transfer object for directories displayed in custom directory/file browser dialogs. +/// +[DebuggerDisplay("Path: {Path}")] +public class DirectoryDto : FileSystemItemDto +{ + /// + /// Gets or sets the children items of the directory. + /// + public List Items { get; set; } = []; +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/FileDto.cs b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/FileDto.cs new file mode 100644 index 00000000..690451ea --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/FileDto.cs @@ -0,0 +1,17 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement; + +/// +/// Data transfer object for files displayed in custom directory/file browser dialogs. +/// +[DebuggerDisplay("Path: {Path}")] +public class FileDto : FileSystemItemDto +{ + /// + /// Gets or sets the size of the file, in bytes + /// + public long Size { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/FileSystemItemDto.cs b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/FileSystemItemDto.cs new file mode 100644 index 00000000..e5cad9fd --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/FileSystemItemDto.cs @@ -0,0 +1,33 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement; + +/// +/// Base data transfer object for files and directories displayed in custom directory/file browser dialogs. +/// +[DebuggerDisplay("Path: {Path}")] +public abstract class FileSystemItemDto +{ + /// + /// Gets or sets the full path to the file system item. + /// + public string? Path { get; set; } + + /// + /// Gets or sets the name of the file system item. + /// + public string? Name { get; set; } + + /// + /// Gets or sets the creation date of the file system item. + /// + public DateTime DateCreated { get; set; } + + /// + /// Gets or sets the modification date of the file system item. + /// + public DateTime DateModified { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/FileSystemTreeNodeDto.cs b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/FileSystemTreeNodeDto.cs new file mode 100644 index 00000000..1188fda8 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/FileSystemTreeNodeDto.cs @@ -0,0 +1,44 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.FileSystem; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement; + +/// +/// Data transfer object for a file system node. +/// +[DebuggerDisplay("Path: {Path}")] +public class FileSystemTreeNodeDto +{ + /// + /// Gets or sets the full path of the file or directory. + /// + public string Path { get; set; } = null!; + + /// + /// Gets or sets the name of the file or directory. + /// + public string Name { get; set; } = null!; + + /// + /// Gets or sets the type of the item, indicating whether it is a file, directory, or drive. + /// + public FileSystemItemType ItemType { get; set; } + + /// + /// Gets or sets a value indicating whether the node is expanded. + /// + public bool IsExpanded { get; set; } + + /// + /// Gets or sets a value indicating whether the child nodes have been loaded. + /// + public bool ChildrenLoaded { get; set; } + + /// + /// Gets or sets the list of child nodes. + /// + public List Children { get; set; } = []; +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/FileSystemTypeDto.cs b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/FileSystemTypeDto.cs new file mode 100644 index 00000000..3f7e83b3 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/FileSystemTypeDto.cs @@ -0,0 +1,18 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.FileSystem; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement; + +/// +/// Data transfer object containing the file system platform type. +/// ` +[DebuggerDisplay("PlatformType: {PlatformType}")] +public class FileSystemTypeDto +{ + /// + /// Gets or sets the file system platform type. + /// + public PlatformType PlatformType { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/PathExistsDto.cs b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/PathExistsDto.cs new file mode 100644 index 00000000..ed2d13da --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/PathExistsDto.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement; + +/// +/// Data transfer object for a response to the inquiry about the existence of a file system path. +/// +/// Whether a file system path exists or not. +[DebuggerDisplay("Exists: {Exists}")] +public record PathExistsDto( + bool Exists +); diff --git a/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/PathSegmentDto.cs b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/PathSegmentDto.cs new file mode 100644 index 00000000..12a5cdb9 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/PathSegmentDto.cs @@ -0,0 +1,17 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement; + +/// +/// Data transfer object for a response containing a file system path. +/// +[DebuggerDisplay("Path: {Path}")] +public class PathSegmentDto +{ + /// + /// Gets or sets the returned path. + /// + public string Path { get; set; } = null!; +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/PathSeparatorDto.cs b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/PathSeparatorDto.cs new file mode 100644 index 00000000..1db9134e --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/PathSeparatorDto.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement; + +/// +/// Data transfer object for a file system path separator. +/// +/// The system's path separator. +[DebuggerDisplay("Separator: {Separator}")] +public record PathSeparatorDto( + string Separator +); diff --git a/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/PathValidDto.cs b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/PathValidDto.cs new file mode 100644 index 00000000..c29d4085 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/FileSystemManagement/PathValidDto.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement; + +/// +/// Data transfer object for a response to the inquiry about the validity of a file system path. +/// +/// Whether a file system path is valid or not. +[DebuggerDisplay("IsValid: {IsValid}")] +public record PathValidDto( + bool IsValid +); diff --git a/src/Lumina.Presentation.Web/Common/DTO/Libraries/BookLiteDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Libraries/BookLiteDto.cs new file mode 100644 index 00000000..091bd10e --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Libraries/BookLiteDto.cs @@ -0,0 +1,33 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Libraries; + +/// +/// Data transfer object for a lightweight book element, containing only the properties needed by the client for card-style navigation. +/// +[DebuggerDisplay("Title: {Title}")] +public class BookLiteDto +{ + /// + /// Gets or sets the Id of the book. + /// + public Guid Id { get; set; } + + /// + /// Gets or sets the title of the book. + /// + public string Title { get; set; } = string.Empty; + + /// + /// Gets or sets the release year of the book (re-release year, if available, or original release year), if known. + /// + public int? ReleaseYear { get; set; } + + /// + /// Gets or sets the path of the image representing the cover of the book, if available. + /// + public string? CoverPath { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryDto.cs new file mode 100644 index 00000000..bc43dad9 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryDto.cs @@ -0,0 +1,71 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Library; +using System; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Libraries; + +/// +/// Data transfer object for a library element. +/// +[DebuggerDisplay("Title: {Title}")] +public class LibraryDto +{ + /// + /// Gets or sets the unique identifier of the media library. + /// + public Guid? Id { get; set; } + + /// + /// Gets or sets the unique identifier of the user owning the media library. + /// + public Guid? UserId { get; set; } + + /// + /// Gets or sets the title of the library. + /// + public string? Title { get; set; } + + /// + /// Gets or sets the type of the library. + /// + public string? LibraryType { get; set; } + + /// + /// Gets or sets the path of the image file used as the cover for the library. + /// + public string? CoverImage { get; set; } + + /// + /// Gets or sets the collection of directories that contain the library files. + /// + public List ContentLocations { get; set; } = []; + + /// + /// Gets or sets whether this media library is enabled or not. A disabled media library is never shown or changed. + /// + public bool IsEnabled { get; set; } = true; + + /// + /// Gets or sets whether this media library is locked or not. A locked media library is displayed, but is never changed or updated. + /// + public bool IsLocked { get; set; } = false; + + /// + /// Gets or sets whether this media library should update the metadata of its elements from the web, or not. + /// + public bool DownloadMetadataFromWeb { get; set; } = true; + + /// + /// Gets or sets whether this media library should copy the downloaded metadata into the media library content locations, or not. + /// + public bool ShouldSaveMetadataInMediaDirectories { get; set; } = false; + + /// + /// Gets or sets whether this media library should skip the directories whose contents have not changed since the last scan, during the scan. This is an opt-in setting, because it relies on directory metadata, + /// which does not change when the contents of an existing file are edited, and such edits could be missed while this setting is enabled. + /// + public bool ShouldSkipUnchangedDirectoriesDuringScan { get; set; } = false; +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryScanJobProgressDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryScanJobProgressDto.cs new file mode 100644 index 00000000..bdf38653 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryScanJobProgressDto.cs @@ -0,0 +1,32 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Libraries; + +/// +/// Data transfer object for a media library scan job progress model. +/// +[DebuggerDisplay("CompletedItems: {CompletedItems}; TotalItems: {TotalItems}")] +public class LibraryScanJobProgressDto +{ + /// + /// Gets or sets the number of completed items of the media library scan job. + /// + public int CompletedItems { get; set; } + + /// + /// Gets or sets the total number of items of the media library scan job. + /// + public int TotalItems { get; set; } + + /// + /// Gets or sets the current operation being performed by the media library scan job. + /// + public string? CurrentOperation { get; set; } + + /// + /// Gets or sets the ratio between the total number and the completed number of items, as a percentage. + /// + public decimal ProgressPercentage { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryScanProgressDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryScanProgressDto.cs new file mode 100644 index 00000000..579a5cc4 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryScanProgressDto.cs @@ -0,0 +1,53 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Libraries; + +/// +/// Data transfer object for a media library scan progress model. +/// +[DebuggerDisplay("ScanId: {ScanId}; UserId: {UserId}; LibraryId: {LibraryId}")] +public class LibraryScanProgressDto +{ + /// + /// Gets or sets the unique identifier of the media library scan. + /// + public Guid ScanId { get; set; } + + /// + /// Gets or sets the unique identifier of the user initiating this media library scan. + /// + public Guid UserId { get; set; } + + /// + /// Gets or sets the unique identifier of the media library that is scanned. + /// + public Guid LibraryId { get; set; } + + /// + /// Gets or sets the number of completed jobs of the media library scan job. + /// + public int CompletedJobs { get; set; } + + /// + /// Gets or sets the total number of jobs of the media library scan job. + /// + public int TotalJobs { get; set; } + + /// + /// Gets or sets the optional current job progress of the media library scan. + /// + public LibraryScanJobProgressDto? CurrentJobProgress { get; set; } + + /// + /// Gets or sets the status of the media library scan. + /// + public string? Status { get; set; } + + /// + /// Gets or sets the ratio between the total number and the completed number of jobs, as a percentage. + /// + public decimal OverallProgressPercentage { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Libraries/PaginatedBookLiteDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Libraries/PaginatedBookLiteDto.cs new file mode 100644 index 00000000..763276e0 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Libraries/PaginatedBookLiteDto.cs @@ -0,0 +1,38 @@ +#region ========================================================================= USING ===================================================================================== +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Libraries; + +/// +/// Data transfer object for a paginated collection of lightweight book elements, together with pagination metadata. +/// +[DebuggerDisplay("CurrentPage: {CurrentPage}; Count: {Count}")] +public class PaginatedBookLiteDto +{ + /// + /// Gets or sets the collection of lightweight book elements associated with this instance. + /// + public IReadOnlyList Data { get; set; } = []; + + /// + /// Gets or sets the current page number in a paginated collection. + /// + public int CurrentPage { get; set; } + + /// + /// Gets or sets the number of items to include per page in paginated results. + /// + public int PerPage { get; set; } + + /// + /// Gets or sets the total number of elements available in the paginated result set. + /// + public int Count { get; set; } + + /// + /// Gets or sets the total number of pages based on elements available in the result set and per page. + /// + public int NumberOfPages { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Libraries/ScanLibraryDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Libraries/ScanLibraryDto.cs new file mode 100644 index 00000000..2f99ef7b --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Libraries/ScanLibraryDto.cs @@ -0,0 +1,23 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Libraries; + +/// +/// Data transfer object for a media library scan response. +/// +[DebuggerDisplay("ScanId: {ScanId} LibraryId: {LibraryId}")] +public class ScanLibraryDto +{ + /// + /// Gets or sets the Id of the media library scan. + /// + public Guid? ScanId { get; set; } + + /// + /// Gets or sets the Id of the scanned media library. + /// + public Guid? LibraryId { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/MediaContributors/MediaContributorDto.cs b/src/Lumina.Presentation.Web/Common/DTO/MediaContributors/MediaContributorDto.cs new file mode 100644 index 00000000..97587776 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/MediaContributors/MediaContributorDto.cs @@ -0,0 +1,22 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.MediaContributors; + +/// +/// Data transfer object for a media contributor. +/// +[DebuggerDisplay("Name: {Name}")] +public class MediaContributorDto +{ + /// + /// Gets the name of the contributor. + /// + public MediaContributorNameDto? Name { get; set; } + + /// + /// Gets the role of the contributor. + /// + public MediaContributorRoleDto? Role { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/MediaContributors/MediaContributorNameDto.cs b/src/Lumina.Presentation.Web/Common/DTO/MediaContributors/MediaContributorNameDto.cs new file mode 100644 index 00000000..23831e71 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/MediaContributors/MediaContributorNameDto.cs @@ -0,0 +1,22 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.MediaContributors; + +/// +/// Data transfer object for a media contributor name. +/// +[DebuggerDisplay("DisplayName: {DisplayName}")] +public class MediaContributorNameDto +{ + /// + /// Gets the name by which the contributor is popularly known. + /// + public string? DisplayName { get; set; } + + /// + /// Gets the legal name of the contributor. + /// + public string? LegalName { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/MediaContributors/MediaContributorRoleDto.cs b/src/Lumina.Presentation.Web/Common/DTO/MediaContributors/MediaContributorRoleDto.cs new file mode 100644 index 00000000..74eaf370 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/MediaContributors/MediaContributorRoleDto.cs @@ -0,0 +1,22 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.MediaContributors; + +/// +/// Data transfer object for a media contributor role. +/// +[DebuggerDisplay("Name: {Name}")] +public class MediaContributorRoleDto +{ + /// + /// Gets the value representing this object. + /// + public string? Name { get; set; } + + /// + /// Gets the category of this object. + /// + public string? Category { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Plugins/LibraryMetadataProviderDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Plugins/LibraryMetadataProviderDto.cs new file mode 100644 index 00000000..787e8562 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Plugins/LibraryMetadataProviderDto.cs @@ -0,0 +1,33 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Plugins; + +/// +/// Data transfer object for a metadata provider configured for a media library. +/// +[DebuggerDisplay("Name: {Name}")] +public class LibraryMetadataProviderDto +{ + /// + /// Gets or sets the unique identifier of the plugin providing the metadata. + /// + public Guid PluginId { get; set; } + + /// + /// Gets or sets the display name of the metadata provider. + /// + public string Name { get; set; } = string.Empty; + + /// + /// Gets or sets whether the metadata provider is enabled for the media library. + /// + public bool IsEnabled { get; set; } + + /// + /// Gets or sets the rank of the metadata provider, determining the order in which providers are tried. + /// + public int Rank { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Plugins/PluginDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Plugins/PluginDto.cs new file mode 100644 index 00000000..9c67faae --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Plugins/PluginDto.cs @@ -0,0 +1,55 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Plugins; +using System; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Plugins; + +/// +/// Data transfer object for a detected plugin. +/// +[DebuggerDisplay("Name: {Name}")] +public class PluginDto +{ + /// + /// Gets or sets the unique identifier of the plugin. + /// + public Guid Id { get; set; } + + /// + /// Gets or sets the display name of the plugin. + /// + public string Name { get; set; } = string.Empty; + + /// + /// Gets or sets the author of the plugin. + /// + public string Author { get; set; } = string.Empty; + + /// + /// Gets or sets the version of the plugin. + /// + public string Version { get; set; } = string.Empty; + + /// + /// Gets or sets the description of the plugin. + /// + public string Description { get; set; } = string.Empty; + + /// + /// Gets or sets the load status of the plugin. + /// + public PluginLoadStatus LoadStatus { get; set; } + + /// + /// Gets or sets the error message when the plugin failed to load. + /// + public string? LoadError { get; set; } + + /// + /// Gets or sets the settings of the plugin. + /// + public Dictionary? Settings { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Plugins/PluginSettingDescriptorDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Plugins/PluginSettingDescriptorDto.cs new file mode 100644 index 00000000..a5e4c206 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Plugins/PluginSettingDescriptorDto.cs @@ -0,0 +1,39 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Plugins; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Plugins; + +/// +/// Data transfer object for a single setting of a plugin. +/// +[DebuggerDisplay("Key: {Key}, Label: {Label}")] +public class PluginSettingDescriptorDto +{ + /// + /// Gets or sets the unique key of the setting. + /// + public string Key { get; set; } = string.Empty; + + /// + /// Gets or sets the display label of the setting. + /// + public string Label { get; set; } = string.Empty; + + /// + /// Gets or sets the type of the setting. + /// + public PluginSettingType Type { get; set; } + + /// + /// Gets or sets the default value of the setting. + /// + public string? DefaultValue { get; set; } + + /// + /// Gets or sets the list of allowed values, when the setting is a selection. + /// + public IReadOnlyList? AllowedValues { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Plugins/PluginSettingsDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Plugins/PluginSettingsDto.cs new file mode 100644 index 00000000..75fd0900 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Plugins/PluginSettingsDto.cs @@ -0,0 +1,29 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Plugins; + +/// +/// Data transfer object for the settings of a plugin and their schema. +/// +[DebuggerDisplay("PluginId: {PluginId}")] +public class PluginSettingsDto +{ + /// + /// Gets or sets the unique identifier of the plugin. + /// + public Guid PluginId { get; set; } + + /// + /// Gets or sets the schema of the plugin settings. + /// + public List Schema { get; set; } = []; + + /// + /// Gets or sets the current values of the plugin settings. + /// + public Dictionary? Settings { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/UsersManagement/UserDto.cs b/src/Lumina.Presentation.Web/Common/DTO/UsersManagement/UserDto.cs new file mode 100644 index 00000000..4a2abdd0 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/UsersManagement/UserDto.cs @@ -0,0 +1,17 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.UsersManagement; + +/// +/// Data transfer object for a user. +/// +/// The unique identifier of the user. +/// The username of the user. +[DebuggerDisplay("Id: {Id}, Username: {Username}")] +public record UserDto( + Guid Id, + string Username +); diff --git a/src/Lumina.Presentation.Web/Common/DTO/UsersManagement/UserSettingsDto.cs b/src/Lumina.Presentation.Web/Common/DTO/UsersManagement/UserSettingsDto.cs new file mode 100644 index 00000000..ad009888 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/UsersManagement/UserSettingsDto.cs @@ -0,0 +1,33 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.UsersManagement; + +/// +/// Data transfer object for the settings of a user. +/// +[DebuggerDisplay("IsPaginationEnabled: {IsPaginationEnabled}; ItemsPerPage: {ItemsPerPage}")] +public class UserSettingsDto +{ + /// + /// Gets or sets the unique identifier of the user that owns these settings. + /// + public Guid? UserId { get; set; } + + /// + /// Gets or sets whether pagination is enabled for the user, or not. + /// + public bool IsPaginationEnabled { get; set; } = true; + + /// + /// Gets or sets the number of library items displayed per page when pagination is enabled. + /// + public int ItemsPerPage { get; set; } = 48; + + /// + /// Gets or sets whether the "The" prefix of library item titles is ignored by the alpha picker, or not. + /// + public bool IgnoreThePrefixForAlphaPicker { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/BookDto.cs b/src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/BookDto.cs new file mode 100644 index 00000000..b746cff9 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/BookDto.cs @@ -0,0 +1,216 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.DTO.Common; +using System; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary.BookLibrary; + +/// +/// Data transfer object for a book. +/// +[DebuggerDisplay("Title: {Title}")] +public class BookDto +{ + /// + /// Gets the Id of the media item. + /// + public Guid Id { get; init; } + + /// + /// Gets the Id of the media library this book belongs to. + /// + public Guid LibraryId { get; init; } + + /// + /// Gets the file system path of the book. + /// + public string Path { get; init; } = null!; + + /// + /// Gets the title of the media item. + /// + public string Title { get; init; } = null!; + + /// + /// Gets the original title of the media item. + /// + public string? OriginalTitle { get; init; } + + /// + /// Gets the optional description of the media item. + /// + public string? Description { get; init; } + + /// + /// Gets the optional original release date of the media item. + /// + public DateOnly? OriginalReleaseDate { get; init; } + + /// + /// Gets the optional original release year of the media item. + /// This is useful when only the year of original release is known. + /// + public int? OriginalReleaseYear { get; init; } + + /// + /// Gets the optional re-release or reissue date of the media item. + /// + public DateOnly? ReReleaseDate { get; init; } + + /// + /// Gets the optional re-release or reissue year of the media item. + /// + public int? ReReleaseYear { get; init; } + + /// + /// Gets the optional country or region of release. + /// + public string? ReleaseCountry { get; init; } + + /// + /// Gets the optional release version or edition. (e.g. "Original", "Director's Cut", "2.0") + /// + public string? ReleaseVersion { get; init; } + + /// + /// Gets the ISO 639-1 two-letter language code. + /// + public string? LanguageCode { get; init; } + + /// + /// Gets the full name of the language in English. + /// + public string? LanguageName { get; init; } + + /// + /// Gets an optional native name of the language. + /// + public string? LanguageNativeName { get; init; } + + /// + /// Gets the optional ISO 639-1 two-letter original language code. + /// + public string? OriginalLanguageCode { get; init; } + + /// + /// Gets the optional full name of the original language in English. + /// + public string? OriginalLanguageName { get; init; } + + /// + /// Gets an optional native name of the original language. + /// + public string? OriginalLanguageNativeName { get; init; } + + /// + /// Gets the list of tags associated with the media item. + /// + public HashSet Tags { get; set; } = []; + + /// + /// Gets the list of genres associated with the media item. + /// + public HashSet Genres { get; set; } = []; + + /// + /// Gets the publisher of the written content. + /// + public string? Publisher { get; init; } + + /// + /// Gets the number of pages in the written content. + /// + public int? PageCount { get; init; } + + /// + /// Gets the format of the book (e.g., Hardcover, Paperback), if applicable. + /// + public string Format { get; init; } = null!; + + /// + /// Gets the edition of the book, if applicable. + /// + public string? Edition { get; init; } + + /// + /// Gets the volume or book number in the series, if applicable. + /// + public int? VolumeNumber { get; init; } + + /// + /// Gets the series id, if the book is part of a series. + /// + //public Guid? BookSeriesId { get; init; } = null; + + /// + /// Gets the ASIN (Amazon Standard Identification Number) of the book. + /// + public string? ASIN { get; init; } = null!; + + /// + /// Gets the Goodreads ID of the book. + /// + public string? GoodreadsId { get; init; } = null!; + + /// + /// Gets the Library of Congress Control Number (LCCN) of the book. + /// + public string? LCCN { get; init; } = null!; + + /// + /// Gets the OCLC Number (WorldCat identifier) of the book. + /// + public string? OCLCNumber { get; init; } = null!; + + /// + /// Gets the Open Library ID of the book. + /// + public string? OpenLibraryId { get; init; } = null!; + + /// + /// Gets the LibraryThing ID of the book. + /// + public string? LibraryThingId { get; init; } = null!; + + /// + /// Gets the Google Books ID of the book. + /// + public string? GoogleBooksId { get; init; } = null!; + + /// + /// Gets the Barnes & Noble ID of the book. + /// + public string? BarnesAndNobleId { get; init; } = null!; + + /// + /// Gets the Apple Books ID of the book. + /// + public string? AppleBooksId { get; init; } = null!; + + /// + /// Gets the list of ISBN (International Standard Book Number) of the book. + /// + public List ISBNs { get; set; } = []; + + /// + /// Gets the list of media contributors (actors, directors, etc) starring in this book. + /// + //public List ContributorIds { get; init; } = []; + + /// + /// Gets the list of ratings for this book. + /// + public List Ratings { get; init; } = []; + + /// + /// Gets the time and date when the entity was added. + /// + public DateTime Created { get; set; } + + /// + /// Gets the optional time and date when the entity was updated. + /// + public DateTime? Updated { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/BookRatingDto.cs b/src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/BookRatingDto.cs new file mode 100644 index 00000000..488dfa33 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/BookRatingDto.cs @@ -0,0 +1,19 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.BookLibrary; +using System.Diagnostics; +using Lumina.Presentation.Web.Common.DTO.Common; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary.BookLibrary; + +/// +/// Data transfer object for a book rating. +/// +[DebuggerDisplay("Value: {Value}, MaxValue: {MaxValue}")] +public class BookRatingDto : RatingDto +{ + /// + /// Gets or sets the source of the book rating (e.g., a specific website or platform). + /// + public BookRatingSource? Source { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/BookSeriesDto.cs b/src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/BookSeriesDto.cs new file mode 100644 index 00000000..70d36931 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/BookSeriesDto.cs @@ -0,0 +1,17 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary.BookLibrary; + +/// +/// Data transfer object for a request to get book series information. +/// +[DebuggerDisplay("Title: {Title}")] +public class BookSeriesDto +{ + /// + /// Gets or sets the title of the book series. + /// + public string? Title { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/IsbnDto.cs b/src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/IsbnDto.cs new file mode 100644 index 00000000..8df5e093 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/IsbnDto.cs @@ -0,0 +1,23 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.BookLibrary; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary.BookLibrary; + +/// +/// Data transfer object for a request to get ISBN information. +/// +[DebuggerDisplay("Value: {Value} ({Format})")] +public class IsbnDto +{ + /// + /// Gets or sets the ISBN value. + /// + public string? Value { get; set; } + + /// + /// Gets or sets the format of the ISBN (e.g., ISBN-10 or ISBN-13). + /// + public IsbnFormat? Format { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/LightBookDto.cs b/src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/LightBookDto.cs new file mode 100644 index 00000000..047a8dd4 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/BookLibrary/LightBookDto.cs @@ -0,0 +1,33 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary.BookLibrary; + +/// +/// Data transfer object for a preview of important properties of a book. +/// +[DebuggerDisplay("Title: {Title}")] +public class LightBookDto +{ + /// + /// Gets the Id of the media item. + /// + public required Guid Id { get; init; } + + /// + /// Gets the title of the media item. + /// + public required string Title { get; init; } + + /// + /// Gets the optional release year (either re-release year, if available, or original release year, if known) of the media item. + /// + public int? ReleaseYear { get; init; } + + /// + /// Gets the optional path of the image representing the cover of this book. + /// + public string? CoverPath { get; init; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/WrittenContentMetadataDto.cs b/src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/WrittenContentMetadataDto.cs new file mode 100644 index 00000000..49ebd592 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/WrittenContentLibrary/WrittenContentMetadataDto.cs @@ -0,0 +1,64 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.DTO.Common; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.WrittenContentLibrary; + +/// +/// Data transfer object for written content metadata. +/// +[DebuggerDisplay("Title: {Title}")] +public class WrittenContentMetadataDto +{ + /// + /// Gets or sets the title of the written content. + /// + public string? Title { get; set; } + + /// + /// Gets or sets the original title of the written content, if different from the current title. + /// + public string? OriginalTitle { get; set; } + + /// + /// Gets or sets a brief description or summary of the written content. + /// + public string? Description { get; set; } + + /// + /// Gets or sets the release information, including release date and other relevant details. + /// + public ReleaseInfoDto? ReleaseInfo { get; set; } + + /// + /// Gets or sets the list of genres associated with the written content. + /// + public List? Genres { get; set; } + + /// + /// Gets or sets the list of tags that further describe or categorize the written content. + /// + public List? Tags { get; set; } + + /// + /// Gets or sets the language in which the written content is written. + /// + public LanguageInfoDto? Language { get; set; } + + /// + /// Gets or sets the original language of the written content, if it has been translated. + /// + public LanguageInfoDto? OriginalLanguage { get; set; } + + /// + /// Gets or sets the name of the publisher of the written content. + /// + public string? Publisher { get; set; } + + /// + /// Gets or sets the number of pages in the written content. + /// + public int? PageCount { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerConfiguration.cs b/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerConfiguration.cs index d0dc667e..8bea5b86 100644 --- a/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerConfiguration.cs +++ b/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerConfiguration.cs @@ -1,5 +1,5 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Presentation.Web.Common.Models.Configuration; +using Lumina.Presentation.Web.Common.DTO.Configuration; using Lumina.Presentation.Web.Common.Utilities; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -26,13 +26,13 @@ internal static class PresentationWebLayerConfiguration configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); configuration.AddJsonFile("appsettings.development.json", optional: true, reloadOnChange: true); - serviceCollection.AddOptions() - .Bind(configuration.GetRequiredSection(ServerConfigurationModel.SECTION_NAME)) + serviceCollection.AddOptions() + .Bind(configuration.GetRequiredSection(ServerConfigurationDto.SECTION_NAME)) .ValidateFluently() .ValidateOnStart(); - serviceCollection.AddOptions() - .Bind(configuration.GetRequiredSection(EncryptionSettingsModel.SECTION_NAME)) + serviceCollection.AddOptions() + .Bind(configuration.GetRequiredSection(EncryptionSettingsDto.SECTION_NAME)) .ValidateFluently() .ValidateOnStart(); diff --git a/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerServices.cs b/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerServices.cs index 1264f93d..bd606e3a 100644 --- a/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerServices.cs +++ b/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerServices.cs @@ -1,13 +1,13 @@ #region ========================================================================= USING ===================================================================================== +using FastEndpoints; +using FastEndpoints.Swagger; using FluentValidation; using Lumina.Presentation.Web.Common.Api; using Lumina.Presentation.Web.Common.Authorization; +using Lumina.Presentation.Web.Common.Enums.Authorization; using Lumina.Presentation.Web.Common.Exceptions; -using Lumina.Presentation.Web.Common.Filters.ActionFilters; -using Lumina.Presentation.Web.Common.Filters.AuthorizationFilters; using Lumina.Presentation.Web.Common.Http; -using Lumina.Presentation.Web.Common.MiddlewareFilters; -using Lumina.Presentation.Web.Common.Models.Authorization; +using Lumina.Presentation.Web.Common.Localization; using Lumina.Presentation.Web.Common.Security; using Lumina.Presentation.Web.Common.Services; using Microsoft.AspNetCore.Authentication.Cookies; @@ -18,6 +18,7 @@ using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Localization.Routing; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Localization; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.Extensions.DependencyInjection; using Polly; @@ -49,11 +50,7 @@ public static class PresentationWebLayerServices /// The updated . public static IServiceCollection AddPresentationWebLayerServices(this IServiceCollection services) { - services.AddControllersWithViews(mvcOptions => - { - mvcOptions.Filters.Add(new MiddlewareFilterAttribute(typeof(LocalizationPipeline))); // add localization middleware filter - mvcOptions.Filters.Add(); - }) + services.AddControllersWithViews() .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix) .AddDataAnnotationsLocalization() .AddJsonOptions(jsonOptions => @@ -62,11 +59,50 @@ public static class PresentationWebLayerServices jsonOptions.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles; // needed because file system API responses can have very nested structures jsonOptions.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); }); + + // configure the locations where the Razor view engine looks for views and layouts, since the views live under the Core directory + services.Configure(razorViewEngineOptions => + { + razorViewEngineOptions.ViewLocationFormats.Clear(); + razorViewEngineOptions.ViewLocationFormats.Add("/Core/Views/{1}/{0}.cshtml"); + razorViewEngineOptions.ViewLocationFormats.Add("/Core/Views/Shared/{0}.cshtml"); + }); + + // configure the JSON serialization settings used by Results.Json, so that the JSON responses of the endpoints match the MVC responses they replace + services.Configure(jsonOptions => + { + jsonOptions.SerializerOptions.MaxDepth = 256; + jsonOptions.SerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles; // needed because file system API responses can have very nested structures + jsonOptions.SerializerOptions.Converters.Add(new JsonStringEnumConverter()); + }); + + // register the FastEndpoints library, which replaces the MVC controllers for handling the application routes + services.AddFastEndpoints(); + // add OpenAPI document generation, so that the endpoints exposed by the web application are discoverable and their contracts are visible + services.AddOpenApi(); + services.SwaggerDocument(documentOptions => + { + documentOptions.SerializerSettings = jsonSerializerOptions => + { + jsonSerializerOptions.PropertyNamingPolicy = null; + jsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; + }; + documentOptions.DocumentSettings = aspNetCoreOpenApiDocumentGeneratorSettings => + { + aspNetCoreOpenApiDocumentGeneratorSettings.DocumentName = "v1"; + aspNetCoreOpenApiDocumentGeneratorSettings.Title = "Lumina Web"; + aspNetCoreOpenApiDocumentGeneratorSettings.Version = "v1"; + }; + documentOptions.RemoveEmptyRequestSchema = true; + documentOptions.ShortSchemaNames = true; + }); // configure URL-based localization services.AddLocalization(localizationOptions => { - localizationOptions.ResourcesPath = "Resources"; + localizationOptions.ResourcesPath = "Core/Resources"; }); + // resolve the resources of the views that live under the Core/Views directory + services.AddSingleton(); services.Configure(requestLocalizationOptions => { @@ -190,9 +226,12 @@ public static class PresentationWebLayerServices }; }); - // add an authorization policy that ensures application is initialized with super admin account before allowing access + // add authorization policies that ensure the application is initialized with the super admin account before allowing access, + // and that restrict access based on the roles and permissions retrieved from the remote API services.AddAuthorizationBuilder() - .AddPolicy("RequireInitialization", authorizationPolicyBuilder => authorizationPolicyBuilder.Requirements.Add(new InitializationRequirement())); + .AddPolicy(AuthorizationPolicies.REQUIRE_INITIALIZATION, authorizationPolicyBuilder => authorizationPolicyBuilder.Requirements.Add(new InitializationRequirement())) + .AddPolicy(AuthorizationPolicies.REQUIRE_ADMIN_ROLE, authorizationPolicyBuilder => authorizationPolicyBuilder.Requirements.Add(new RoleRequirement("Admin"))) + .AddPolicy(AuthorizationPolicies.REQUIRE_CREATE_LIBRARIES_PERMISSION, authorizationPolicyBuilder => authorizationPolicyBuilder.Requirements.Add(new PermissionRequirement(AuthorizationPermission.CanCreateLibraries))); // add forwarded headers middleware to handle reverse proxy scenarios services.Configure(forwardedHeadersOptions => @@ -237,13 +276,13 @@ public static class PresentationWebLayerServices .AddPolicyHandler(circuitBreakerPolicy); services.AddScoped(); - services.AddScoped(); - services.AddScoped(); // enable access to the current HTTP context in non-controller classes services.AddHttpContextAccessor(); services.AddScoped(); + services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddSingleton(); services.AddSingleton(); diff --git a/src/Lumina.Presentation.Web/Common/Exceptions/ApiException.cs b/src/Lumina.Presentation.Web/Common/Exceptions/ApiException.cs index 5557f482..95c75ae9 100644 --- a/src/Lumina.Presentation.Web/Common/Exceptions/ApiException.cs +++ b/src/Lumina.Presentation.Web/Common/Exceptions/ApiException.cs @@ -1,5 +1,5 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Presentation.Web.Common.Models.Common; +using Lumina.Presentation.Web.Common.DTO.Common; using System; using System.Net; #endregion @@ -19,7 +19,7 @@ public class ApiException : Exception /// /// Gets or sets the problem details represented by this exception. /// - public ProblemDetailsModel? ProblemDetails { get; } + public ProblemDetailsDto? ProblemDetails { get; } /// /// Gets or sets the absolute path of the API endpoint that produced this exception. @@ -32,7 +32,7 @@ public class ApiException : Exception /// The problem details object returned by the API. /// The HTTP status code returned by the API. /// The absolute path of the API endpoint that produced this exception. - public ApiException(ProblemDetailsModel? problemDetails, HttpStatusCode httpStatusCode, string? requestPath = null) : base(problemDetails?.Title ?? "An error occurred.") + public ApiException(ProblemDetailsDto? problemDetails, HttpStatusCode httpStatusCode, string? requestPath = null) : base(problemDetails?.Title ?? "An error occurred.") { ProblemDetails = problemDetails; HttpStatusCode = httpStatusCode; diff --git a/src/Lumina.Presentation.Web/Common/Http/RazorViewResult.cs b/src/Lumina.Presentation.Web/Common/Http/RazorViewResult.cs new file mode 100644 index 00000000..cdb5bd98 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Http/RazorViewResult.cs @@ -0,0 +1,65 @@ +#region ========================================================================= USING ===================================================================================== +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.Infrastructure; +using Microsoft.AspNetCore.Mvc.ModelBinding; +using Microsoft.AspNetCore.Mvc.ViewFeatures; +using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.DependencyInjection; +using System.Collections.Generic; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Presentation.Web.Common.Http; + +/// +/// that renders a Razor view through the MVC view engine, enabling FastEndpoints endpoints to serve the Razor views of the application. +/// +/// +/// The class does not expose a method for rendering Razor views, so this custom result reuses the MVC +/// execution machinery, which preserves layouts, sections, view components and tag helpers. +/// +public sealed class RazorViewResult : IResult +{ + private readonly string _viewName; + private readonly object? _model; + private readonly IReadOnlyDictionary _viewData; + + /// + /// Initializes a new instance of the class. + /// + /// The name or path of the view to render. + /// The model to pass to the view. + /// Optional additional view data entries made available to the view via ViewData. + public RazorViewResult(string viewName, object? model = null, IReadOnlyDictionary? viewData = null) + { + _viewName = viewName; + _model = model; + _viewData = viewData ?? new Dictionary(); + } + + /// + /// Renders the configured Razor view to the response. + /// + /// The for the current request. + public async Task ExecuteAsync(HttpContext httpContext) + { + // the only accessible ViewDataDictionary constructors require either a model state or an existing dictionary, so start from an empty one and assign the model + // through the Model setter; the setter rebases the model metadata on the runtime type of the value, which is what makes the asp-for tag helpers resolve the + // properties of the actual model type instead of a plain object + IModelMetadataProvider metadataProvider = httpContext.RequestServices.GetRequiredService(); + ViewDataDictionary viewData = new(metadataProvider, new ModelStateDictionary()) { Model = _model }; + foreach ((string key, object? value) in _viewData) + viewData[key] = value; + + // delegate to the MVC view execution machinery instead of rendering the view manually: it discovers the layout and _ViewStart, evaluates the sections, + // and resolves the view components and tag helpers, none of which the Results class can do since it has no view rendering support + ViewResult viewResult = new() { ViewName = _viewName, ViewData = viewData }; + IActionResultExecutor executor = httpContext.RequestServices.GetRequiredService>(); + // the view engine needs an ActionContext, which FastEndpoints does not provide; synthesize one that carries over the current route data, so that the + // culture route value (and therefore the URL-based localization) keeps working while the view is rendered + ActionContext actionContext = new(httpContext, httpContext.GetRouteData() ?? new RouteData(), new ActionDescriptor()); + await executor.ExecuteAsync(actionContext, viewResult).ConfigureAwait(false); + } +} diff --git a/src/Lumina.Presentation.Web/Common/Localization/CoreHtmlLocalizerFactory.cs b/src/Lumina.Presentation.Web/Common/Localization/CoreHtmlLocalizerFactory.cs new file mode 100644 index 00000000..f560d7b5 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Localization/CoreHtmlLocalizerFactory.cs @@ -0,0 +1,55 @@ +#region ========================================================================= USING ===================================================================================== +using Microsoft.AspNetCore.Mvc.Localization; +using Microsoft.Extensions.Localization; +using System; +#endregion + +namespace Lumina.Presentation.Web.Common.Localization; + +/// +/// that resolves the resources of the views that live under the Core/Views directory. +/// +/// +/// The view localizer derives the resource base name from the executing view path, so a view at /Core/Views/Auth/Login.cshtml produces the base name +/// {ApplicationName}.Core.Views.Auth.Login. Because the Core segment is only the directory that hosts the views and not part of the resource path, +/// it is stripped here, so that the resources are looked up at {ApplicationName}.Core.Resources.Views.Auth.Login, matching the resource files under +/// Core/Resources/Views/Auth. +/// +public class CoreHtmlLocalizerFactory : IHtmlLocalizerFactory +{ + private readonly HtmlLocalizerFactory _innerFactory; + + /// + /// Initializes a new instance of the class. + /// + /// Injected factory used to create the underlying string localizers. + public CoreHtmlLocalizerFactory(IStringLocalizerFactory stringLocalizerFactory) + { + _innerFactory = new HtmlLocalizerFactory(stringLocalizerFactory); + } + + /// + /// Creates an for the specified base name and location. + /// + /// The base name of the resource to load strings from. + /// The location to load resources from. + /// The created . + public IHtmlLocalizer Create(string baseName, string location) + { + string prefix = location + ".Core."; + string resourceBaseName = baseName.StartsWith(prefix, StringComparison.Ordinal) + ? location + "." + baseName.Substring(prefix.Length) + : baseName; + return _innerFactory.Create(resourceBaseName, location); + } + + /// + /// Creates an for the specified resource source type. + /// + /// The type of the resource to load strings from. + /// The created . + public IHtmlLocalizer Create(Type resourceSource) + { + return _innerFactory.Create(resourceSource); + } +} diff --git a/src/Lumina.Presentation.Web/Common/Requests/Authorization/AddRoleRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Authorization/AddRoleRequest.cs new file mode 100644 index 00000000..55d34f76 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Authorization/AddRoleRequest.cs @@ -0,0 +1,18 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Authorization; + +/// +/// Represents a request for adding an authorization role. +/// +/// The name of the role. Required. +/// The collection or permissions of the role. Required. +[DebuggerDisplay("RoleName: {RoleName}")] +public record AddRoleRequest( + string? RoleName, + List? Permissions +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/Authorization/DeleteRoleRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Authorization/DeleteRoleRequest.cs new file mode 100644 index 00000000..4becd239 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Authorization/DeleteRoleRequest.cs @@ -0,0 +1,15 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Authorization; + +/// +/// Represents a request for deleting an authorization role. +/// +/// The unique identifier of the role. Required. +[DebuggerDisplay("RoleId: {RoleId}")] +public record DeleteRoleRequest( + Guid RoleId +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/Authorization/GetRolePermissionsRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Authorization/GetRolePermissionsRequest.cs new file mode 100644 index 00000000..738e1b4e --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Authorization/GetRolePermissionsRequest.cs @@ -0,0 +1,15 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Authorization; + +/// +/// Represents a request to get the authorization permissions of a role identified by . +/// +/// The Id of authorization role. Required. +[DebuggerDisplay("RoleId: {RoleId}")] +public record GetRolePermissionsRequest( + Guid RoleId +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/Authorization/GetUserPermissionsRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Authorization/GetUserPermissionsRequest.cs new file mode 100644 index 00000000..25758d63 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Authorization/GetUserPermissionsRequest.cs @@ -0,0 +1,15 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Authorization; + +/// +/// Represents the request model for retrieving the authorization permissions of a user identified by . +/// +/// The unique identifier of the user for whom to get the authorization permissions. Required. +[DebuggerDisplay("UserId: {UserId}")] +public record GetUserPermissionsRequest( + Guid UserId +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/Authorization/GetUserRoleRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Authorization/GetUserRoleRequest.cs new file mode 100644 index 00000000..6080ba49 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Authorization/GetUserRoleRequest.cs @@ -0,0 +1,15 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Authorization; + +/// +/// Represents the request model for retrieving the authorization role of a user identified by . +/// +/// The unique identifier of the user for whom to get the authorization role. Required. +[DebuggerDisplay("UserId: {UserId}")] +public record GetUserRoleRequest( + Guid UserId +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/Authorization/UpdateRoleRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Authorization/UpdateRoleRequest.cs new file mode 100644 index 00000000..de8d4c45 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Authorization/UpdateRoleRequest.cs @@ -0,0 +1,20 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Authorization; + +/// +/// Represents a request for updating an existing authorization role. +/// +/// The unique identifier of the role. Required. +/// The name of the role. Required. +/// The collection of Ids of the permissions of the role. Required. +[DebuggerDisplay("RoleName: {RoleName}")] +public record UpdateRoleRequest( + Guid RoleId, + string? RoleName, + List? Permissions +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/Authorization/UpdateUserRoleAndPermissionsRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Authorization/UpdateUserRoleAndPermissionsRequest.cs new file mode 100644 index 00000000..21e9ad06 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Authorization/UpdateUserRoleAndPermissionsRequest.cs @@ -0,0 +1,20 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Authorization; + +/// +/// Represents a request for updating the authorization role and permissions of a user. +/// +/// The unique identifier of the user. Required. +/// The unique identifier of the role. Optional. +/// The collection of Ids of the permissions of the role. Optional. +[DebuggerDisplay("UserId: {UserId}")] +public record UpdateUserRoleAndPermissionsRequest( + Guid UserId, + Guid? RoleId, + List? Permissions +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/Common/EmptyRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Common/EmptyRequest.cs new file mode 100644 index 00000000..12334e34 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Common/EmptyRequest.cs @@ -0,0 +1,6 @@ +namespace Lumina.Presentation.Web.Common.Requests.Common; + +/// +/// Record used for empty requests and responses. +/// +public record struct EmptyRequest(); diff --git a/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Directories/GetDirectoriesRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Directories/GetDirectoriesRequest.cs new file mode 100644 index 00000000..6319e090 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Directories/GetDirectoriesRequest.cs @@ -0,0 +1,16 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.FileSystemManagement.Directories; + +/// +/// Represents a request to get the directories of a file system path. +/// +/// The file system path for which to get the directories. Required. +/// Whether to include hidden file system elements or not. Optional. +[DebuggerDisplay("Path: {Path}")] +public record GetDirectoriesRequest( + string? Path, + bool IncludeHiddenElements +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Files/GetFilesRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Files/GetFilesRequest.cs new file mode 100644 index 00000000..0448d103 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Files/GetFilesRequest.cs @@ -0,0 +1,16 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.FileSystemManagement.Files; + +/// +/// Represents a request to get the files at a file system path. +/// +/// The file system path for which to get the files. Required. +/// Whether to include hidden file system elements or not. Optional. +[DebuggerDisplay("Path: {Path}")] +public record GetFilesRequest( + string? Path, + bool IncludeHiddenElements +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Files/GetTreeFilesRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Files/GetTreeFilesRequest.cs new file mode 100644 index 00000000..f78a9dcc --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Files/GetTreeFilesRequest.cs @@ -0,0 +1,16 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.FileSystemManagement.Files; + +/// +/// Represents a request to get the files of a file system path. +/// +/// The file system path for which to get the tree files. Required. +/// Whether to include hidden file system elements or not. Optional. +[DebuggerDisplay("Path: {Path}")] +public record GetTreeFilesRequest( + string? Path, + bool IncludeHiddenElements +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/CheckPathExistsRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/CheckPathExistsRequest.cs new file mode 100644 index 00000000..78fb23a8 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/CheckPathExistsRequest.cs @@ -0,0 +1,16 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.FileSystemManagement.Path; + +/// +/// Represents a request to check the existence of a file system path. +/// +/// The file system path to check the exitence of. Required. +/// Whether to include hidden elements in the search results, or not. Optional. +[DebuggerDisplay("Path: {Path}, IncludeHiddenElements: {IncludeHiddenElements}")] +public record CheckPathExistsRequest( + string? Path, + bool IncludeHiddenElements +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/GetPathParentRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/GetPathParentRequest.cs new file mode 100644 index 00000000..c3bb5a7c --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/GetPathParentRequest.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.FileSystemManagement.Path; + +/// +/// Represents the request for retrieving the parent path of a file system path. +/// +/// The path for which the parent path is retrieved. +[DebuggerDisplay("Path: {Path}")] +public record GetPathParentRequest( + string? Path +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/GetPathRootRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/GetPathRootRequest.cs new file mode 100644 index 00000000..6c2660ae --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/GetPathRootRequest.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.FileSystemManagement.Path; + +/// +/// Represents a request to get the root of a file system path. +/// +/// The file system path for which to get the root. Required. +[DebuggerDisplay("Path: {Path}")] +public record GetPathRootRequest( + string? Path +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/SplitPathRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/SplitPathRequest.cs new file mode 100644 index 00000000..f8454901 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/SplitPathRequest.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.FileSystemManagement.Path; + +/// +/// Represents a request to split a file system path. +/// +/// The file system path for which to get the path segments. Required. +[DebuggerDisplay("Path: {Path}")] +public record SplitPathRequest( + string? Path +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/ValidatePathRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/ValidatePathRequest.cs new file mode 100644 index 00000000..b8664b9e --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/FileSystemManagement/Path/ValidatePathRequest.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.FileSystemManagement.Path; + +/// +/// Represents a request to check the validity of a file system path. +/// +/// The file system path to validate. Required. +[DebuggerDisplay("Path: {Path}")] +public record ValidatePathRequest( + string? Path +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/Libraries/GetBooksLiteRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Libraries/GetBooksLiteRequest.cs new file mode 100644 index 00000000..d6ccbcd7 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Libraries/GetBooksLiteRequest.cs @@ -0,0 +1,56 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Common; +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Libraries; + +/// +/// Represents a request to get the lightweight details of the books of a media library. +/// +[DebuggerDisplay("LibraryId: {LibraryId}")] +public class GetBooksLiteRequest +{ + /// + /// Gets or sets the Id of the media library whose books are retrieved. + /// + public Guid LibraryId { get; set; } + + /// + /// Gets or sets the page of results to retrieve. + /// + public int? CurrentPage { get; set; } + + /// + /// Gets or sets the maximum number of books to retrieve per page. + /// + public int? PerPage { get; set; } + + /// + /// Gets or sets the search term used to filter results. + /// + public string? SearchTerm { get; set; } + + /// + /// Gets or sets the alpha key used to filter the results by the first character of their title, for the alpha picker. + /// Can be to disable alpha filtering, a single ASCII letter (case-insensitive) to filter by that letter, + /// "#" to filter by titles whose first character is a digit, or "*" to filter by titles whose first character is neither a letter nor a digit. + /// + public string? FilterAlphaKey { get; set; } + + /// + /// Gets or sets whether the leading "The " prefix of a title is ignored when computing the alpha key, or not. + /// + public bool IgnoreThePrefixForAlphaPicker { get; set; } + + /// + /// Gets or sets the name of the field by which to sort the results. + /// + public string? SortBy { get; set; } + + /// + /// Gets or sets the direction in which to sort the results. + /// + public SortOrder? SortOrder { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/Requests/Library/Management/CancelLibraryScanRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Library/Management/CancelLibraryScanRequest.cs new file mode 100644 index 00000000..bd358060 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Library/Management/CancelLibraryScanRequest.cs @@ -0,0 +1,17 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Library.Management; + +/// +/// Represents a request to cancel the scan of a media library. +/// +/// The unique identifier of the media library whose scan is cancelled. Required. +/// The Id of scan to cancel. Required. +[DebuggerDisplay("LibraryId: {LibraryId}; ScanId: {ScanId}")] +public record CancelLibraryScanRequest( + Guid LibraryId, + Guid ScanId +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/Library/Management/DeleteLibraryRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Library/Management/DeleteLibraryRequest.cs new file mode 100644 index 00000000..928c8ce7 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Library/Management/DeleteLibraryRequest.cs @@ -0,0 +1,15 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Library.Management; + +/// +/// Represents a request to delete a media library by its Id. +/// +/// The unique identifier of the media library to be deleted. Required. +[DebuggerDisplay("Id: {Id}")] +public record DeleteLibraryRequest( + Guid Id +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/Library/Management/EditLibraryRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Library/Management/EditLibraryRequest.cs new file mode 100644 index 00000000..93b666b7 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Library/Management/EditLibraryRequest.cs @@ -0,0 +1,15 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Library.Management; + +/// +/// Represents the request for displaying the media library editing view. +/// +/// The unique identifier of the media library to edit. +[DebuggerDisplay("Id: {Id}")] +public record EditLibraryRequest( + Guid Id +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/Library/Management/GetMetadataProvidersRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Library/Management/GetMetadataProvidersRequest.cs new file mode 100644 index 00000000..ca866ef0 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Library/Management/GetMetadataProvidersRequest.cs @@ -0,0 +1,15 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Library.Management; + +/// +/// Represents the request for retrieving the metadata providers of a media library. +/// +/// The unique identifier of the media library whose metadata providers are retrieved. +[DebuggerDisplay("LibraryId: {LibraryId}")] +public record GetMetadataProvidersRequest( + Guid LibraryId +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/Library/Management/ScanLibraryRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Library/Management/ScanLibraryRequest.cs new file mode 100644 index 00000000..dbb07d0f --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Library/Management/ScanLibraryRequest.cs @@ -0,0 +1,15 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Library.Management; + +/// +/// Represents a request to scan a media library. +/// +/// The unique identifier of the media library to be scanned. Required. +[DebuggerDisplay("Id: {Id}")] +public record ScanLibraryRequest( + Guid Id +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/Library/WrittenContentLibrary/BookLibrary/Books/GetBookRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Library/WrittenContentLibrary/BookLibrary/Books/GetBookRequest.cs new file mode 100644 index 00000000..79725234 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Library/WrittenContentLibrary/BookLibrary/Books/GetBookRequest.cs @@ -0,0 +1,15 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Library.WrittenContentLibrary.BookLibrary.Books; + +/// +/// Represents a request to get a book by the specified Id. +/// +/// The unique identifier of the book to retrieve. +[DebuggerDisplay("Id: {Id}")] +public record GetBookRequest( + Guid Id +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/Library/WrittenContentLibrary/BookLibrary/Books/GetBooksViewRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Library/WrittenContentLibrary/BookLibrary/Books/GetBooksViewRequest.cs new file mode 100644 index 00000000..7ec4de40 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Library/WrittenContentLibrary/BookLibrary/Books/GetBooksViewRequest.cs @@ -0,0 +1,15 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Library.WrittenContentLibrary.BookLibrary.Books; + +/// +/// Represents the request for displaying the books browsing view. +/// +/// The unique identifier of the media library whose books are browsed. +[DebuggerDisplay("LibraryId: {LibraryId}")] +public record GetBooksViewRequest( + Guid? LibraryId +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/Plugins/GetPluginSettingsRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Plugins/GetPluginSettingsRequest.cs new file mode 100644 index 00000000..cdbbe52a --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Plugins/GetPluginSettingsRequest.cs @@ -0,0 +1,15 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Plugins; + +/// +/// Represents a request to get the settings of a plugin. +/// +/// The unique identifier of the plugin. Required. +[DebuggerDisplay("PluginId: {PluginId}")] +public record GetPluginSettingsRequest( + Guid PluginId +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/Plugins/ReorderLibraryMetadataProvidersRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Plugins/ReorderLibraryMetadataProvidersRequest.cs new file mode 100644 index 00000000..a88953b3 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Plugins/ReorderLibraryMetadataProvidersRequest.cs @@ -0,0 +1,24 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Plugins; + +/// +/// Represents a request to reorder the metadata providers of a media library. +/// +[DebuggerDisplay("LibraryId: {LibraryId}")] +public class ReorderLibraryMetadataProvidersRequest +{ + /// + /// Gets or sets the Id of the media library whose metadata providers are reordered. + /// + public Guid LibraryId { get; set; } + + /// + /// Gets or sets the plugin Ids in the new order, from highest to lowest rank. + /// + public List PluginIds { get; set; } = []; +} diff --git a/src/Lumina.Presentation.Web/Common/Requests/Plugins/SetLibraryMetadataProviderEnabledRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Plugins/SetLibraryMetadataProviderEnabledRequest.cs new file mode 100644 index 00000000..38046da0 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Plugins/SetLibraryMetadataProviderEnabledRequest.cs @@ -0,0 +1,29 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Plugins; + +/// +/// Represents a request to enable or disable a metadata provider for a media library. +/// +[DebuggerDisplay("LibraryId: {LibraryId}, PluginId: {PluginId}")] +public class SetLibraryMetadataProviderEnabledRequest +{ + /// + /// Gets or sets the Id of the media library whose metadata provider is enabled or disabled. + /// + public Guid LibraryId { get; set; } + + /// + /// Gets or sets the unique identifier of the plugin providing the metadata. + /// + public Guid PluginId { get; set; } + + /// + /// Gets or sets whether the metadata provider should be enabled for the media library. + /// + public bool IsEnabled { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/Requests/Plugins/UpdatePluginSettingsRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Plugins/UpdatePluginSettingsRequest.cs new file mode 100644 index 00000000..c48bac46 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Plugins/UpdatePluginSettingsRequest.cs @@ -0,0 +1,24 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Plugins; + +/// +/// Represents a request to update the settings of a plugin. +/// +[DebuggerDisplay("PluginId: {PluginId}")] +public class UpdatePluginSettingsRequest +{ + /// + /// Gets or sets the unique identifier of the plugin. + /// + public Guid PluginId { get; set; } + + /// + /// Gets or sets the settings of the plugin. + /// + public Dictionary? Settings { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/Requests/Tools/SetLanguageRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Tools/SetLanguageRequest.cs new file mode 100644 index 00000000..2db72ecc --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Tools/SetLanguageRequest.cs @@ -0,0 +1,16 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Tools; + +/// +/// Represents the request for setting the culture used by the application. +/// +/// The new culture to set. +/// The URL to return to, after setting the new culture. +[DebuggerDisplay("NewCulture: {NewCulture}, ReturnUrl: {ReturnUrl}")] +public record SetLanguageRequest( + string? NewCulture, + string? ReturnUrl +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/UsersManagement/Authentication/LoginViewRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/UsersManagement/Authentication/LoginViewRequest.cs new file mode 100644 index 00000000..a9dda6d5 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/UsersManagement/Authentication/LoginViewRequest.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.UsersManagement.Authentication; + +/// +/// Represents the request for displaying the account login view. +/// +/// The URL to return to, after login. +[DebuggerDisplay("ReturnUrl: {ReturnUrl}")] +public record LoginViewRequest( + string? ReturnUrl = null +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/UsersManagement/ChangePasswordRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/UsersManagement/ChangePasswordRequest.cs new file mode 100644 index 00000000..b899d829 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/UsersManagement/ChangePasswordRequest.cs @@ -0,0 +1,20 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.UsersManagement; + +/// +/// Represents the request model for account password change. +/// +/// The username of the account. Required. +/// The current password of the account. Required. +/// The new password of the account. Required. +/// The confirmation of the new password of the account. Required. +[DebuggerDisplay("Username: {Username}")] +public record ChangePasswordRequest( + string? Username, + string? CurrentPassword, + string? NewPassword, + string? NewPasswordConfirm +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/UsersManagement/LoginRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/UsersManagement/LoginRequest.cs new file mode 100644 index 00000000..bca229e8 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/UsersManagement/LoginRequest.cs @@ -0,0 +1,20 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.UsersManagement; + +/// +/// Represents the request model for user authentication. +/// +/// The username of the account to authenticate. Required. +/// The password of the account to authenticate. Required. +/// The TOTP (Time-Based One-Time Password) of the account to authenticate. Optional. +/// The URL to return to, after login. +[DebuggerDisplay("Username: {Username}")] +public record LoginRequest( + string? Username = null, + string? Password = null, + string? TotpCode = null, + string? ReturnUrl = null +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/UsersManagement/RecoverPasswordRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/UsersManagement/RecoverPasswordRequest.cs new file mode 100644 index 00000000..e41f7e8a --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/UsersManagement/RecoverPasswordRequest.cs @@ -0,0 +1,16 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.UsersManagement; + +/// +/// Represents the request model for account password recovery. +/// +/// The username of the account for which to recover the password. Required. +/// The TOTP (Time-Based One-Time Password) of the account for which to recover the password. Required. +[DebuggerDisplay("Username: {Username}")] +public record RecoverPasswordRequest( + string? Username, + string? TotpCode +); diff --git a/src/Lumina.Presentation.Web/Common/Requests/UsersManagement/RegisterRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/UsersManagement/RegisterRequest.cs new file mode 100644 index 00000000..9aa1c105 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/UsersManagement/RegisterRequest.cs @@ -0,0 +1,22 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.UsersManagement; + +/// +/// Represents the request model for user registration. +/// +/// The desired username for the new account. Required. +/// The password for the new account. Required. +/// The confirmation of the entered password, used to ensure consistency. Required. +/// Specifies the type of registration, e.g., "Admin" or "User". Required. +/// Indicates whether two-factor authentication (2FA) should be enabled for the new account. Optional. +[DebuggerDisplay("Username: {Username}")] +public record RegisterRequest( + string? Username, + string? Password, + string? PasswordConfirm, + string? RegistrationType, + bool Use2fa = true +); diff --git a/src/Lumina.Presentation.Web/Common/Responses/Authorization/GetAuthorizationResponse.cs b/src/Lumina.Presentation.Web/Common/Responses/Authorization/GetAuthorizationResponse.cs new file mode 100644 index 00000000..3190ff2d --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Responses/Authorization/GetAuthorizationResponse.cs @@ -0,0 +1,20 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Authorization; +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Responses.Authorization; + +/// +/// Represents the response model for an account authorization request. +/// +/// The unique identifier of the user for whom the authorization is retrieved. +/// The role associated to the user. +/// The collection of permissions associated to the user. +[DebuggerDisplay("UserId: {UserId}")] +public record GetAuthorizationResponse( + Guid UserId, + string? Role, + AuthorizationPermission[] Permissions +); diff --git a/src/Lumina.Presentation.Web/Common/Responses/UsersManagement/ChangePasswordResponse.cs b/src/Lumina.Presentation.Web/Common/Responses/UsersManagement/ChangePasswordResponse.cs new file mode 100644 index 00000000..7bd05bf6 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Responses/UsersManagement/ChangePasswordResponse.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Responses.UsersManagement; + +/// +/// Represents the response model for an account password change request. +/// +/// Whether the password was changed or not. +[DebuggerDisplay("IsPasswordChanged: {IsPasswordChanged}")] +public record ChangePasswordResponse( + bool IsPasswordChanged +); diff --git a/src/Lumina.Presentation.Web/Common/Responses/UsersManagement/InitializationResponse.cs b/src/Lumina.Presentation.Web/Common/Responses/UsersManagement/InitializationResponse.cs new file mode 100644 index 00000000..6f4582d7 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Responses/UsersManagement/InitializationResponse.cs @@ -0,0 +1,17 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Responses.UsersManagement; + +/// +/// Model for verifying the initialization status of the application. +/// +[DebuggerDisplay("IsInitialized: {IsInitialized}")] +public class InitializationResponse +{ + /// + /// Gets or sets a value indicating whether the application has been run before, and the super admin account has been created. + /// + public bool IsInitialized { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/Responses/UsersManagement/LoginResponse.cs b/src/Lumina.Presentation.Web/Common/Responses/UsersManagement/LoginResponse.cs new file mode 100644 index 00000000..0cd2dc7a --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Responses/UsersManagement/LoginResponse.cs @@ -0,0 +1,21 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Responses.UsersManagement; + +/// +/// Represents the response model for a user authentication. +/// +/// The unique identifier of the logged in user. +/// The username of the logged in user. +/// The JWT authentication token, if authentication failed or TOTP is required. +/// Indicates whether the user has Two-Factor Authentication enabled, or not. +[DebuggerDisplay("Username: {Username}")] +public record LoginResponse( + Guid Id, + string? Username, + string? Token, + bool UsesTotp +); diff --git a/src/Lumina.Presentation.Web/Common/Responses/UsersManagement/RecoverPasswordResponse.cs b/src/Lumina.Presentation.Web/Common/Responses/UsersManagement/RecoverPasswordResponse.cs new file mode 100644 index 00000000..514fc5dc --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Responses/UsersManagement/RecoverPasswordResponse.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Responses.UsersManagement; + +/// +/// Represents the response model for an account password reset request. +/// +/// Whether the password was reset or not. +[DebuggerDisplay("IsPasswordReset: {IsPasswordReset}")] +public record RecoverPasswordResponse( + bool IsPasswordReset +); diff --git a/src/Lumina.Presentation.Web/Common/Responses/UsersManagement/RegisterResponse.cs b/src/Lumina.Presentation.Web/Common/Responses/UsersManagement/RegisterResponse.cs new file mode 100644 index 00000000..be3fbf96 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Responses/UsersManagement/RegisterResponse.cs @@ -0,0 +1,17 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Responses.UsersManagement; + +/// +/// Represents the response model for a successful registration. +/// +/// The username of the registered user. +/// The TOTP (Time-Based One-Time Password) secret used for two-factor authentication. +[DebuggerDisplay("Username: {Username}")] +public record RegisterResponse( + string? Username, + string? TotpSecret +); diff --git a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Authentication.cs b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Authentication.cs new file mode 100644 index 00000000..0d17674c --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Authentication.cs @@ -0,0 +1,19 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of remote API routes called by this Web application. +/// +public static partial class ApiRoutes +{ + /// + /// Routes for the authentication endpoints of the remote API. + /// + public static class Authentication + { + public const string REGISTER_ACCOUNT = "auth/register"; + public const string LOGIN_ACCOUNT = "auth/login"; + public const string RECOVER_PASSWORD = "auth/recover-password"; + public const string CHANGE_PASSWORD = "auth/change-password"; + public const string USERS = "auth/users"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Authorization.cs b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Authorization.cs new file mode 100644 index 00000000..d1b2a239 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Authorization.cs @@ -0,0 +1,18 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of remote API routes called by this Web application. +/// +public static partial class ApiRoutes +{ + /// + /// Routes for the authorization endpoints of the remote API. + /// + public static class Authorization + { + public const string UPDATE_USER_ROLE_AND_PERMISSIONS_BY_USER_ID = "auth/users/{userId}/role-and-permissions"; + public const string GET_USER_PERMISSIONS_BY_USER_ID = "auth/users/{userId}/permissions"; + public const string GET_USER_ROLE_BY_USER_ID = "auth/users/{userId}/role"; + public const string GET_AUTHORIZATION = "auth/get-authorization"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Books.cs b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Books.cs new file mode 100644 index 00000000..c3aa70eb --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Books.cs @@ -0,0 +1,15 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of remote API routes called by this Web application. +/// +public static partial class ApiRoutes +{ + /// + /// Routes for the books endpoints of the remote API. + /// + public static class Books + { + public const string GET_BOOKS_LITE = "books/lite"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Directories.cs b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Directories.cs new file mode 100644 index 00000000..f79175fb --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Directories.cs @@ -0,0 +1,15 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of remote API routes called by this Web application. +/// +public static partial class ApiRoutes +{ + /// + /// Routes for the directories endpoints of the remote API. + /// + public static class Directories + { + public const string GET_DIRECTORIES = "directories/get-directories"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Drives.cs b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Drives.cs new file mode 100644 index 00000000..288d9d14 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Drives.cs @@ -0,0 +1,15 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of remote API routes called by this Web application. +/// +public static partial class ApiRoutes +{ + /// + /// Routes for the drives endpoints of the remote API. + /// + public static class Drives + { + public const string GET_DRIVES = "drives/get-drives"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.FileSystem.cs b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.FileSystem.cs new file mode 100644 index 00000000..b317b02b --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.FileSystem.cs @@ -0,0 +1,15 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of remote API routes called by this Web application. +/// +public static partial class ApiRoutes +{ + /// + /// Routes for the file system endpoints of the remote API. + /// + public static class FileSystem + { + public const string GET_TYPES = "file-system/get-type"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Files.cs b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Files.cs new file mode 100644 index 00000000..2d5d3c78 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Files.cs @@ -0,0 +1,16 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of remote API routes called by this Web application. +/// +public static partial class ApiRoutes +{ + /// + /// Routes for the files endpoints of the remote API. + /// + public static class Files + { + public const string GET_TREE_FILES = "files/get-tree-files"; + public const string GET_FILES = "files/get-files"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Initialization.cs b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Initialization.cs new file mode 100644 index 00000000..7f7921c0 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Initialization.cs @@ -0,0 +1,16 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of remote API routes called by this Web application. +/// +public static partial class ApiRoutes +{ + /// + /// Routes for the initialization endpoint of the remote API. + /// + public static class Initialization + { + public const string SETUP_APPLICATION = "initialization"; + public const string CHECK_INITIALIZATION = "initialization"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Libraries.cs b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Libraries.cs new file mode 100644 index 00000000..ceef0553 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Libraries.cs @@ -0,0 +1,28 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of remote API routes called by this Web application. +/// +public static partial class ApiRoutes +{ + /// + /// Routes for the media libraries endpoints of the remote API. + /// + public static class Libraries + { + public const string GET_LIBRARY_BY_ID = "libraries/{id}"; + public const string GET_LIBRARIES = "libraries"; + public const string GET_ENABLED_LIBRARIES = "libraries/enabled"; + public const string ADD_LIBRARY = "libraries"; + public const string UPDATE_LIBRARY = "libraries/{id}"; + public const string DELETE_LIBRARY = "libraries/{id}"; + public const string SCAN_LIBRARIES = "libraries/scans"; + public const string SCAN_LIBRARY = "libraries/{id}/scans"; + public const string GET_RUNNING_LIBRARIES_SCAN = "libraries/scans/running"; + public const string CANCEL_LIBRARIES_SCAN = "libraries/scans/cancel"; + public const string CANCEL_LIBRARY_SCAN = "libraries/{libraryId}/scans/{scanId}/cancel"; + public const string GET_LIBRARY_METADATA_PROVIDERS = "libraries/{libraryId}/metadata-providers"; + public const string SET_LIBRARY_METADATA_PROVIDER_ENABLED = "libraries/{libraryId}/metadata-providers/{pluginId}/enabled"; + public const string REORDER_LIBRARY_METADATA_PROVIDERS = "libraries/{libraryId}/metadata-providers/reorder"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Path.cs b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Path.cs new file mode 100644 index 00000000..4e056a6a --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Path.cs @@ -0,0 +1,20 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of remote API routes called by this Web application. +/// +public static partial class ApiRoutes +{ + /// + /// Routes for the paths endpoints of the remote API. + /// + public static class Path + { + public const string GET_PATH_ROOT = "path/get-path-root"; + public const string GET_PATH_SEPARATOR = "path/get-path-separator"; + public const string GET_PATH_PARENT = "path/get-path-parent"; + public const string SPLIT = "path/split"; + public const string VALIDATE = "path/validate"; + public const string CHECK_PATH_EXISTS = "path/check-path-exists"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Permissions.cs b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Permissions.cs new file mode 100644 index 00000000..5ccaf316 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Permissions.cs @@ -0,0 +1,15 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of remote API routes called by this Web application. +/// +public static partial class ApiRoutes +{ + /// + /// Routes for the permissions endpoints of the remote API. + /// + public static class Permissions + { + public const string GET_PERMISSIONS = "auth/permissions"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Plugins.cs b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Plugins.cs new file mode 100644 index 00000000..1371d505 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Plugins.cs @@ -0,0 +1,17 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of remote API routes called by this Web application. +/// +public static partial class ApiRoutes +{ + /// + /// Routes for the plugins endpoints of the remote API. + /// + public static class Plugins + { + public const string GET_PLUGINS = "plugins"; + public const string GET_PLUGIN_SETTINGS = "plugins/{pluginId}/settings"; + public const string UPDATE_PLUGIN_SETTINGS = "plugins/{pluginId}/settings"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Roles.cs b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Roles.cs new file mode 100644 index 00000000..09691d9b --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Roles.cs @@ -0,0 +1,19 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of remote API routes called by this Web application. +/// +public static partial class ApiRoutes +{ + /// + /// Routes for the roles endpoints of the remote API. + /// + public static class Roles + { + public const string GET_ROLE_PERMISSIONS_BY_ROLE_ID = "auth/roles/{roleId}/permissions"; + public const string GET_ROLES = "auth/roles"; + public const string CREATE_ROLE = "auth/roles"; + public const string UPDATE_ROLE = "auth/roles"; + public const string DELETE_ROLE = "auth/roles/{roleId}"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Users.cs b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Users.cs new file mode 100644 index 00000000..7ef9fa39 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Users.cs @@ -0,0 +1,16 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of remote API routes called by this Web application. +/// +public static partial class ApiRoutes +{ + /// + /// Routes for the users endpoints of the remote API. + /// + public static class Users + { + public const string GET_USER_SETTINGS = "users/me/settings"; + public const string UPDATE_USER_SETTINGS = "users/me/settings"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Admin.cs b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Admin.cs new file mode 100644 index 00000000..618d0b55 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Admin.cs @@ -0,0 +1,24 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of routes defined in the Web application. +/// +public static partial class WebRoutes +{ + /// + /// Routes for the administrator pages. + /// + public static class Admin + { + public const string MANAGE_ROLES = "{culture}/admin/manage-roles"; + public const string MANAGE_PERMISSIONS = "{culture}/admin/manage-permissions"; + public const string GET_PERMISSIONS_BY_ROLE_ID = "{culture}/admin/api-get-permissions-by-role-id/{roleId}"; + public const string GET_PERMISSIONS_BY_USER_ID = "{culture}/admin/api-get-permissions-by-user-id/{userId}"; + public const string GET_ROLE_BY_USER_ID = "{culture}/admin/api-get-role-by-user-id/{userId}"; + public const string GET_ROLES = "{culture}/admin/api-get-roles"; + public const string CREATE_ROLE = "{culture}/admin/api-create-role"; + public const string UPDATE_ROLE = "{culture}/admin/api-update-role"; + public const string DELETE_ROLE = "{culture}/admin/api-delete-role/{roleId}"; + public const string UPDATE_USER_AUTHORIZATION = "{culture}/admin/api-update-user-authorization"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Authentication.cs b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Authentication.cs new file mode 100644 index 00000000..60cb1ced --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Authentication.cs @@ -0,0 +1,25 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of routes defined in the Web application. +/// +public static partial class WebRoutes +{ + /// + /// Routes for the authentication pages. + /// + public static class Authentication + { + public const string REGISTER_VIEW = "{culture}/auth/register"; + public const string LOGIN_VIEW = "{culture}/auth/login/{returnUrl?}"; + public const string RECOVER_PASSWORD_VIEW = "{culture}/auth/recover-password"; + public const string CHANGE_PASSWORD_VIEW = "{culture}/auth/change-password"; + public const string PROFILE_VIEW = "{culture}/auth/profile"; + public const string ACCESS_DENIED_VIEW = "{culture}/auth/access-denied"; + public const string LOGOUT = "{culture}/auth/logout"; + public const string REGISTER = "{culture}/auth/api-register"; + public const string LOGIN = "{culture}/auth/api-login"; + public const string RECOVER_PASSWORD = "{culture}/auth/api-recover-password"; + public const string CHANGE_PASSWORD = "{culture}/auth/api-change-password"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Books.cs b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Books.cs new file mode 100644 index 00000000..1b5c58c2 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Books.cs @@ -0,0 +1,17 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of routes defined in the Web application. +/// +public static partial class WebRoutes +{ + /// + /// Routes for the books pages. + /// + public static class Books + { + public const string INDEX = "{culture}/library/written-content-library/books-library/books"; + public const string GET_LIBRARY_ITEMS = "{culture}/library/written-content-library/books-library/books/api-get-library-items"; + public const string EDIT_BOOK = "{culture}/library/written-content-library/books-library/books/{id}"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Directories.cs b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Directories.cs new file mode 100644 index 00000000..921c3392 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Directories.cs @@ -0,0 +1,15 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of routes defined in the Web application. +/// +public static partial class WebRoutes +{ + /// + /// Routes for the file system directories endpoints. + /// + public static class Directories + { + public const string GET_DIRECTORIES = "directories/api-get-directories"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Drives.cs b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Drives.cs new file mode 100644 index 00000000..23a36942 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Drives.cs @@ -0,0 +1,15 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of routes defined in the Web application. +/// +public static partial class WebRoutes +{ + /// + /// Routes for the file system drives endpoints. + /// + public static class Drives + { + public const string GET_DRIVES = "drives/api-get-drives"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.FileSystem.cs b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.FileSystem.cs new file mode 100644 index 00000000..e1b550de --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.FileSystem.cs @@ -0,0 +1,15 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of routes defined in the Web application. +/// +public static partial class WebRoutes +{ + /// + /// Routes for the file system endpoints. + /// + public static class FileSystem + { + public const string GET_TYPE = "file-system/api-get-type"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Files.cs b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Files.cs new file mode 100644 index 00000000..9756c9c7 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Files.cs @@ -0,0 +1,16 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of routes defined in the Web application. +/// +public static partial class WebRoutes +{ + /// + /// Routes for the file system files endpoints. + /// + public static class Files + { + public const string GET_TREE_FILES = "files/api-get-tree-files"; + public const string GET_FILES = "files/api-get-files"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Home.cs b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Home.cs new file mode 100644 index 00000000..9cde8458 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Home.cs @@ -0,0 +1,19 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of routes defined in the Web application. +/// +public static partial class WebRoutes +{ + /// + /// Routes for the home pages. + /// + public static class Home + { + public const string INDEX = "/"; + public const string INDEX_CULTURED = "{culture}"; + public const string PRIVACY = "{culture}/privacy"; + public const string ERROR = "{culture}/error"; + public const string NOT_FOUND = "{culture}/not-found"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Language.cs b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Language.cs new file mode 100644 index 00000000..5c2938e8 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Language.cs @@ -0,0 +1,15 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of routes defined in the Web application. +/// +public static partial class WebRoutes +{ + /// + /// Routes for the language tool pages. + /// + public static class Language + { + public const string SET_LANGUAGE = "{culture}/tools/language/set-language"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.LibraryManagement.cs b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.LibraryManagement.cs new file mode 100644 index 00000000..3a54fc3a --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.LibraryManagement.cs @@ -0,0 +1,29 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of routes defined in the Web application. +/// +public static partial class WebRoutes +{ + /// + /// Routes for the media libraries management pages. + /// + public static class LibraryManagement + { + public const string INDEX = "{culture}/libraries/manage"; + public const string ADD_LIBRARY = "{culture}/libraries/manage/item"; + public const string EDIT_LIBRARY = "{culture}/libraries/manage/item/{id}"; + public const string GET_LIBRARIES = "{culture}/libraries/manage/api-get-libraries"; + public const string GET_ENABLED_LIBRARIES = "{culture}/libraries/manage/api-get-enabled-libraries"; + public const string SAVE_LIBRARY = "{culture}/libraries/manage/api-item"; + public const string DELETE_LIBRARY = "{culture}/libraries/manage/api-item/{id}"; + public const string GET_RUNNING_LIBRARY_SCANS = "{culture}/libraries/manage/api-get-running-library-scans"; + public const string SCAN_LIBRARIES = "{culture}/libraries/manage/api-scan-libraries"; + public const string SCAN_LIBRARY = "{culture}/libraries/manage/api-scan-library/{id}"; + public const string CANCEL_LIBRARIES_SCAN = "{culture}/libraries/manage/api-cancel-libraries-scan"; + public const string CANCEL_LIBRARY_SCAN = "{culture}/libraries/manage/{libraryId}/api-cancel-library-scan/{scanId}"; + public const string GET_METADATA_PROVIDERS = "{culture}/libraries/manage/api-get-metadata-providers/{libraryId}"; + public const string SET_METADATA_PROVIDER_ENABLED = "{culture}/libraries/manage/api-set-metadata-provider-enabled"; + public const string REORDER_METADATA_PROVIDERS = "{culture}/libraries/manage/api-reorder-metadata-providers"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Path.cs b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Path.cs new file mode 100644 index 00000000..ebc7bab3 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Path.cs @@ -0,0 +1,20 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of routes defined in the Web application. +/// +public static partial class WebRoutes +{ + /// + /// Routes for the file system paths endpoints. + /// + public static class Path + { + public const string GET_PATH_ROOT = "path/api-get-path-root"; + public const string GET_PATH_SEPARATOR = "path/api-get-path-separator"; + public const string GET_PATH_PARENT = "path/api-get-path-parent"; + public const string SPLIT_PATH = "path/api-split"; + public const string VALIDATE_PATH = "path/api-validate"; + public const string CHECK_PATH_EXISTS = "path/api-check-path-exists"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Plugins.cs b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Plugins.cs new file mode 100644 index 00000000..6008922e --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Plugins.cs @@ -0,0 +1,18 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of routes defined in the Web application. +/// +public static partial class WebRoutes +{ + /// + /// Routes for the plugins pages. + /// + public static class Plugins + { + public const string INDEX = "{culture}/plugins"; + public const string GET_PLUGINS = "{culture}/plugins/api-get-plugins"; + public const string GET_PLUGIN_SETTINGS = "{culture}/plugins/api-get-plugin-settings/{pluginId}"; + public const string UPDATE_PLUGIN_SETTINGS = "{culture}/plugins/api-update-plugin-settings"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Settings.cs b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Settings.cs new file mode 100644 index 00000000..267383c8 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Settings.cs @@ -0,0 +1,17 @@ +namespace Lumina.Presentation.Web.Common.Routes; + +/// +/// Class for the collection of routes defined in the Web application. +/// +public static partial class WebRoutes +{ + /// + /// Routes for the user settings tool pages. + /// + public static class Settings + { + public const string INDEX = "{culture}/tools/settings"; + public const string GET_USER_SETTINGS = "{culture}/tools/settings/api-get-user-settings"; + public const string UPDATE_USER_SETTINGS = "{culture}/tools/settings/api-update-user-settings"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Security/CryptographyService.cs b/src/Lumina.Presentation.Web/Common/Security/CryptographyService.cs index b8480404..ac298e1f 100644 --- a/src/Lumina.Presentation.Web/Common/Security/CryptographyService.cs +++ b/src/Lumina.Presentation.Web/Common/Security/CryptographyService.cs @@ -1,5 +1,5 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Presentation.Web.Common.Models.Configuration; +using Lumina.Presentation.Web.Common.DTO.Configuration; using Microsoft.Extensions.Options; using System; using System.Security.Cryptography; @@ -18,10 +18,10 @@ public sealed class CryptographyService : ICryptographyService, IDisposable /// /// Initializes a new instance of the class. /// - /// Injected service for retrieving . - public CryptographyService(IOptions encryptionSettingsModelOptions) + /// Injected service for retrieving . + public CryptographyService(IOptions encryptionSettingsOptions) { - _key = Convert.FromBase64String(encryptionSettingsModelOptions.Value.SecretKey); + _key = Convert.FromBase64String(encryptionSettingsOptions.Value.SecretKey); } /// diff --git a/src/Lumina.Presentation.Web/Common/Services/CachedAuthorizationHandler.cs b/src/Lumina.Presentation.Web/Common/Services/CachedAuthorizationHandler.cs index fe999290..da8a46b5 100644 --- a/src/Lumina.Presentation.Web/Common/Services/CachedAuthorizationHandler.cs +++ b/src/Lumina.Presentation.Web/Common/Services/CachedAuthorizationHandler.cs @@ -1,5 +1,4 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Presentation.Web.Common.Models.Common; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Caching.Hybrid; using System; @@ -53,7 +52,7 @@ public class CachedAuthorizationHandler : DelegatingHandler return await base.SendAsync(request, cancellationToken).ConfigureAwait(false); } // otherwise, check the hybrid cache to see if there is a cached authorization - CachedResponseModel response = await _hybridCache.GetOrCreateAsync( + CachedResponse response = await _hybridCache.GetOrCreateAsync( cacheKey, async (cancellationToken) => { @@ -61,7 +60,7 @@ public class CachedAuthorizationHandler : DelegatingHandler HttpResponseMessage result = await base.SendAsync(request, cancellationToken).ConfigureAwait(false); string content = await result.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); // cache both status code and content - return new CachedResponseModel + return new CachedResponse { Content = content, StatusCode = result.StatusCode diff --git a/src/Lumina.Presentation.Web/Common/Services/CachedResponse.cs b/src/Lumina.Presentation.Web/Common/Services/CachedResponse.cs new file mode 100644 index 00000000..156cc880 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Services/CachedResponse.cs @@ -0,0 +1,23 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +using System.Net; +#endregion + +namespace Lumina.Presentation.Web.Common.Services; + +/// +/// Represents a cached HTTP response, including its content and status code. +/// +[DebuggerDisplay("StatusCode: {StatusCode}")] +public class CachedResponse +{ + /// + /// Gets or sets the content of the cached HTTP response. + /// + public string Content { get; set; } = string.Empty; + + /// + /// Gets or sets the HTTP status code of the cached response. + /// + public HttpStatusCode StatusCode { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/Services/IUrlService.cs b/src/Lumina.Presentation.Web/Common/Services/IUrlService.cs index 7542a8dd..93663e4d 100644 --- a/src/Lumina.Presentation.Web/Common/Services/IUrlService.cs +++ b/src/Lumina.Presentation.Web/Common/Services/IUrlService.cs @@ -1,16 +1,15 @@ namespace Lumina.Presentation.Web.Common.Services; /// -/// Interface for the service for generating URLs from action and controller names, with URL localization. +/// Interface for the service for generating absolute URLs from the application route templates, with URL localization. /// public interface IUrlService { /// - /// Generates an absolute URL for the specified controller action. + /// Generates an absolute URL for the specified route template. /// - /// The action name within the controller. - /// The controller name. - /// Optional additional route values, like query parameters. - /// An absolute URL to the specified action. - string? GetAbsoluteUrl(string action, string controller, object? additionalRouteValues = null); + /// The route template of the target page or endpoint, taken from the constants. + /// Optional additional route values, like route parameters. + /// An absolute URL to the specified route. + string? GetAbsoluteUrl(string routeTemplate, object? additionalRouteValues = null); } diff --git a/src/Lumina.Presentation.Web/Common/Services/UrlService.cs b/src/Lumina.Presentation.Web/Common/Services/UrlService.cs index 1f3cfd9f..acc29775 100644 --- a/src/Lumina.Presentation.Web/Common/Services/UrlService.cs +++ b/src/Lumina.Presentation.Web/Common/Services/UrlService.cs @@ -1,71 +1,73 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Routes; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.Controllers; -using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Routing; using System; -using System.Linq; +using System.Collections.Generic; using System.Reflection; #endregion namespace Lumina.Presentation.Web.Common.Services; /// -/// Service for generating URLs from action and controller names, with URL localization. +/// Service for generating absolute URLs for the application routes, with URL localization. /// public class UrlService : IUrlService { - private readonly LinkGenerator _linkGenerator; private readonly IHttpContextAccessor _httpContextAccessor; - private readonly IActionDescriptorCollectionProvider _actionDescriptorCollectionProvider; + + /// + /// The collection of route templates defined in the constants, used to validate the requested routes. + /// + private static readonly HashSet s_knownRouteTemplates = GetKnownRouteTemplates(); /// /// Initializes a new instance of the class. /// - /// The ASP.NET Core link generator service. /// Provides access to the current HTTP context. - /// The used to retrieve information about the application's routes and actions. - public UrlService(LinkGenerator linkGenerator, IHttpContextAccessor httpContextAccessor, IActionDescriptorCollectionProvider actionDescriptorCollectionProvider) + public UrlService(IHttpContextAccessor httpContextAccessor) { - _linkGenerator = linkGenerator; _httpContextAccessor = httpContextAccessor; - _actionDescriptorCollectionProvider = actionDescriptorCollectionProvider; } /// - /// Generates an absolute URL for the specified controller action. + /// Generates an absolute URL for the specified route template. /// - /// The action name within the controller. - /// The controller name. - /// Optional additional route values, like query parameters. - /// An absolute URL to the specified action. - public string? GetAbsoluteUrl(string action, string controller, object? additionalRouteValues = null) + /// The route template of the target page or endpoint, taken from the constants. + /// Optional additional route values, like route parameters. + /// An absolute URL to the specified route. + /// Thrown when is not one of the route templates defined in the constants. + public string? GetAbsoluteUrl(string routeTemplate, object? additionalRouteValues = null) { + // fail fast when the route template is not one of the ones defined in the WebRoutes constants, instead of silently generating a broken URL + if (!s_knownRouteTemplates.Contains(routeTemplate)) + throw new ArgumentException($"The route template '{routeTemplate}' is not defined in the WebRoutes constants.", nameof(routeTemplate)); + HttpContext? httpContext = _httpContextAccessor.HttpContext; if (httpContext is null) return null; - string scheme = httpContext.Request.Scheme; string culture = httpContext.Request.RouteValues["culture"]?.ToString() ?? "en-US"; - // find the controller's route template - ControllerActionDescriptor? controllerActionDescriptor = _actionDescriptorCollectionProvider - .ActionDescriptors.Items - .OfType() - .FirstOrDefault(controllerActionDescription => - controllerActionDescription.ControllerName.Equals(controller, StringComparison.OrdinalIgnoreCase) && - controllerActionDescription.ActionName.Equals(action, StringComparison.OrdinalIgnoreCase)); - if (controllerActionDescriptor is null) - return null; - // check if the route template contains {culture} - string? routeTemplate = controllerActionDescriptor.AttributeRouteInfo?.Template; - bool needsCulture = routeTemplate?.Contains("{culture}") == true; - // merge culture and additional values - RouteValueDictionary routeValues = []; - if (needsCulture) - routeValues.Add("culture", culture); + string path = routeTemplate.Replace("{culture}", culture, StringComparison.OrdinalIgnoreCase); if (additionalRouteValues is not null) - foreach (PropertyInfo prop in additionalRouteValues.GetType().GetProperties()) - routeValues.Add(prop.Name, prop.GetValue(additionalRouteValues)); + foreach (PropertyInfo property in additionalRouteValues.GetType().GetProperties()) + path = path.Replace($"{{{property.Name}}}", property.GetValue(additionalRouteValues)?.ToString(), StringComparison.OrdinalIgnoreCase); + // ensure the path starts with a slash, so that it is relative to the server root when concatenated with the host and the path base + if (!path.StartsWith('/')) + path = "/" + path; + // build the absolute URL from the request's scheme, host and path base + return $"{httpContext.Request.Scheme}://{httpContext.Request.Host}{httpContext.Request.PathBase}{path}"; + } - return _linkGenerator.GetUriByAction(httpContext: httpContext, action: action, controller: controller, values: routeValues, scheme: scheme); + /// + /// Collects the values of all route template constants defined in the class. + /// + /// The set of the route templates defined in the constants. + private static HashSet GetKnownRouteTemplates() + { + HashSet routeTemplates = []; + foreach (Type nestedType in typeof(WebRoutes).GetNestedTypes()) + foreach (FieldInfo field in nestedType.GetFields(BindingFlags.Public | BindingFlags.Static)) + if (field.IsLiteral && field.FieldType == typeof(string)) + routeTemplates.Add((string)field.GetValue(null)!); + return routeTemplates; } } diff --git a/src/Lumina.Presentation.Web/Common/Validators/EncryptionSettingsModelValidator.cs b/src/Lumina.Presentation.Web/Common/Validators/EncryptionSettingsModelValidator.cs index b05311bc..d08fbd42 100644 --- a/src/Lumina.Presentation.Web/Common/Validators/EncryptionSettingsModelValidator.cs +++ b/src/Lumina.Presentation.Web/Common/Validators/EncryptionSettingsModelValidator.cs @@ -1,6 +1,6 @@ #region ========================================================================= USING ===================================================================================== using FluentValidation; -using Lumina.Presentation.Web.Common.Models.Configuration; +using Lumina.Presentation.Web.Common.DTO.Configuration; using System; using System.Buffers.Text; #endregion @@ -10,7 +10,7 @@ namespace Lumina.Presentation.Web.Common.Validators; /// /// Validates the needed validation rules for the EncryptionSettings application configuration settings section. /// -public class EncryptionSettingsModelValidator : AbstractValidator +public class EncryptionSettingsModelValidator : AbstractValidator { /// /// Initializes a new instance of the class. diff --git a/src/Lumina.Presentation.Web/Common/Validators/ServerConfigurationModelValidator.cs b/src/Lumina.Presentation.Web/Common/Validators/ServerConfigurationModelValidator.cs index 17dcb612..8d8281f8 100644 --- a/src/Lumina.Presentation.Web/Common/Validators/ServerConfigurationModelValidator.cs +++ b/src/Lumina.Presentation.Web/Common/Validators/ServerConfigurationModelValidator.cs @@ -1,6 +1,6 @@ #region ========================================================================= USING ===================================================================================== using FluentValidation; -using Lumina.Presentation.Web.Common.Models.Configuration; +using Lumina.Presentation.Web.Common.DTO.Configuration; #endregion namespace Lumina.Presentation.Web.Common.Validators; @@ -8,7 +8,7 @@ namespace Lumina.Presentation.Web.Common.Validators; /// /// Validates the needed validation rules for the ServerConfiguration application configuration settings section. /// -public class ServerConfigurationModelValidator : AbstractValidator +public class ServerConfigurationModelValidator : AbstractValidator { /// /// Initializes a new instance of the class.