mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 09:11:10 +00:00
Rewords additional code comments as complete sentences
This commit is contained in:
1 parent
36e43b7999
commit
871644b3c9
23 files changed
+171
-140
No files matched your search
@@ -26,7 +26,7 @@ public static class LibraryMapping
|
||||
LibraryType = domainEntity.LibraryType,
|
||||
UserId = domainEntity.UserId.Value,
|
||||
ContentLocations = [.. domainEntity.ContentLocations.Select(path => new LibraryContentLocationEntity() { Path = path.Path })],
|
||||
CoverImage = domainEntity.CoverImage,
|
||||
CoverImage = domainEntity.CoverImage.HasValue ? domainEntity.CoverImage.Value : null,
|
||||
IsEnabled = domainEntity.IsEnabled,
|
||||
IsLocked = domainEntity.IsLocked,
|
||||
CanDownloadMetadataFromWeb = domainEntity.CanDownloadMetadataFromWeb,
|
||||
@@ -46,8 +46,9 @@ public static class LibraryMapping
|
||||
})],
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedOnUtc = domainEntity.UpdatedOnUtc.HasValue ? domainEntity.UpdatedOnUtc : null,
|
||||
UpdatedBy = Guid.Empty
|
||||
// The audit columns are owned by the auditing interceptor, which stamps only the rows that actually changed, so they are never mapped here.
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -77,6 +77,36 @@ public static class ScheduledJobEntityMapping
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to a copy that carries the provided status and execution timestamps.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <param name="status">The status to assign to the converted entity.</param>
|
||||
/// <param name="lastStartedOnUtc">The last start time to assign to the converted entity.</param>
|
||||
/// <param name="lastCompletedOnUtc">The last completion time to assign to the converted entity.</param>
|
||||
/// <returns>The converted repository entity.</returns>
|
||||
public static ScheduledJobEntity ToUpdatedRepositoryEntity(this ScheduledJobEntity repositoryEntity, ScheduledJobStatus status, DateTime? lastStartedOnUtc, DateTime? lastCompletedOnUtc)
|
||||
{
|
||||
return new ScheduledJobEntity
|
||||
{
|
||||
Id = repositoryEntity.Id,
|
||||
Name = repositoryEntity.Name,
|
||||
TaskType = repositoryEntity.TaskType,
|
||||
ScheduleType = repositoryEntity.ScheduleType,
|
||||
IntervalMinutes = repositoryEntity.IntervalMinutes,
|
||||
Hour = repositoryEntity.Hour,
|
||||
Minute = repositoryEntity.Minute,
|
||||
Status = status,
|
||||
OwnerUserId = repositoryEntity.OwnerUserId,
|
||||
LastStartedOnUtc = lastStartedOnUtc,
|
||||
LastCompletedOnUtc = lastCompletedOnUtc,
|
||||
CreatedOnUtc = repositoryEntity.CreatedOnUtc,
|
||||
CreatedBy = repositoryEntity.CreatedBy,
|
||||
UpdatedOnUtc = repositoryEntity.UpdatedOnUtc,
|
||||
UpdatedBy = repositoryEntity.UpdatedBy
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the schedule of <paramref name="repositoryEntity"/> from its flattened schedule properties.
|
||||
/// </summary>
|
||||
|
||||
+25
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
|
||||
using Lumina.Contracts.Responses.Scheduling;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Scheduling;
|
||||
@@ -26,4 +27,28 @@ public static class ScheduledJobExecutionEntityMapping
|
||||
repositoryEntity.CompletedOnUtc
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to a copy that carries the provided completion time.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <param name="completedOnUtc">The completion time to assign to the converted entity.</param>
|
||||
/// <returns>The converted repository entity.</returns>
|
||||
public static ScheduledJobExecutionEntity ToUpdatedRepositoryEntity(this ScheduledJobExecutionEntity repositoryEntity, DateTime? completedOnUtc)
|
||||
{
|
||||
return new ScheduledJobExecutionEntity
|
||||
{
|
||||
Id = repositoryEntity.Id,
|
||||
ScheduledJobId = repositoryEntity.ScheduledJobId,
|
||||
TaskType = repositoryEntity.TaskType,
|
||||
IsCycleRun = repositoryEntity.IsCycleRun,
|
||||
WasCycleActive = repositoryEntity.WasCycleActive,
|
||||
StartedOnUtc = repositoryEntity.StartedOnUtc,
|
||||
CompletedOnUtc = completedOnUtc,
|
||||
CreatedOnUtc = repositoryEntity.CreatedOnUtc,
|
||||
CreatedBy = repositoryEntity.CreatedBy,
|
||||
UpdatedOnUtc = repositoryEntity.UpdatedOnUtc,
|
||||
UpdatedBy = repositoryEntity.UpdatedBy
|
||||
};
|
||||
}
|
||||
}
|
||||
+7
-6
@@ -1,14 +1,15 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
@@ -49,17 +50,17 @@ public class GetPermissionsQueryHandler : IQueryHandler<GetPermissionsQuery, Res
|
||||
/// </returns>
|
||||
public async Task<Result<IEnumerable<PermissionResponse>>> HandleAsync(GetPermissionsQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
// an authenticated request must always carry a user identity
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// only admins can see the list of authorization permissions
|
||||
// Only admins can see the list of authorization permissions.
|
||||
bool isAdmin = await _authorizationService.IsInRoleAsync(userId, "Admin", cancellationToken).ConfigureAwait(false);
|
||||
if (!isAdmin)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
Result<IEnumerable<PermissionEntity>> getPermissionsResult = await _unitOfWork.PermissionRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
return getPermissionsResult.Match(value => Result.From(value.ToResponses()), errors => errors);
|
||||
Result<PaginatedResultDto<PermissionEntity>> getPermissionsResult = await _unitOfWork.PermissionRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
return getPermissionsResult.Match(value => Result.From(value.Data.ToResponses()), errors => errors);
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
|
||||
@@ -10,6 +9,7 @@ using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
@@ -57,18 +57,19 @@ public class GetRolePermissionsQueryHandler : IQueryHandler<GetRolePermissionsQu
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
// an authenticated request must always carry a user identity
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// only admins can see the list of authorization roles
|
||||
// Only admins can see the list of authorization roles.
|
||||
bool isAdmin = await _authorizationService.IsInRoleAsync(userId, "Admin", cancellationToken).ConfigureAwait(false);
|
||||
if (!isAdmin)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
// get the role from the repository and return its role permissions
|
||||
Result<RoleEntity?> getRoleResult = await _roleRepository.GetByIdAsync(request.RoleId, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// Get the role from the repository and return its role permissions.
|
||||
Result<RoleEntity?> getRoleResult = await _roleRepository.GetByIdAsync(request.RoleId, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getRoleResult.IsFailure)
|
||||
return getRoleResult.Errors;
|
||||
else if (getRoleResult.Value is null)
|
||||
|
||||
+8
-5
@@ -1,14 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
@@ -49,17 +51,18 @@ public class GetRolesQueryHandler : IQueryHandler<GetRolesQuery, Result<IEnumera
|
||||
/// </returns>
|
||||
public async Task<Result<IEnumerable<RoleResponse>>> HandleAsync(GetRolesQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
// an authenticated request must always carry a user identity
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// only admins can see the list of authorization roles
|
||||
// Only admins can see the list of authorization roles.
|
||||
bool isAdmin = await _authorizationService.IsInRoleAsync(userId, "Admin", cancellationToken).ConfigureAwait(false);
|
||||
if (!isAdmin)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
Result<IEnumerable<RoleEntity>> getRolesResult = await _roleRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
return getRolesResult.Match(value => Result.From(value.ToResponses()), errors => errors);
|
||||
|
||||
Result<PaginatedResultDto<RoleEntity>> getRolesResult = await _roleRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
return getRolesResult.Match(value => Result.From(value.Data.ToResponses()), errors => errors);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,11 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Users;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Contracts.Responses.UsersManagement;
|
||||
using System.Collections.Generic;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -38,10 +38,10 @@ public class CheckInitializationQueryHandler : IQueryHandler<CheckInitialization
|
||||
/// </returns>
|
||||
public async Task<InitializationResponse> HandleAsync(CheckInitializationQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
// if the repository reports an error, or there are no users, the application has not been initialized
|
||||
Result<IEnumerable<UserEntity>> selectUsersResult = await _unitOfWork.UserRepository.GetAllAsync(cancellationToken);
|
||||
// If the repository reports an error, or there are no users, the application has not been initialized.
|
||||
Result<PaginatedResultDto<UserEntity>> selectUsersResult = await _unitOfWork.UserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken);
|
||||
if (!selectUsersResult.IsFailure)
|
||||
return new InitializationResponse(selectUsersResult.Value.Any());
|
||||
return new InitializationResponse(selectUsersResult.Value.Data.Any());
|
||||
return new InitializationResponse(false);
|
||||
}
|
||||
}
|
||||
+9
-7
@@ -4,6 +4,8 @@ using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
@@ -53,24 +55,24 @@ public class GetLibrariesQueryHandler : IQueryHandler<GetLibrariesQuery, Result<
|
||||
/// </returns>
|
||||
public async Task<Result<LibraryResponse[]>> HandleAsync(GetLibrariesQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
// an authenticated request must always carry a user identity
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// get the libraries from the repository
|
||||
Result<IEnumerable<LibraryEntity>> getLibrariesResult = await _unitOfWork.LibraryRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
// Get the libraries from the repository.
|
||||
Result<PaginatedResultDto<LibraryEntity>> getLibrariesResult = await _unitOfWork.LibraryRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getLibrariesResult.IsFailure)
|
||||
return getLibrariesResult.Errors;
|
||||
|
||||
// admins can see all libraries
|
||||
// Admins can see all libraries.
|
||||
if (await _authorizationService.IsInRoleAsync(userId, "Admin", cancellationToken).ConfigureAwait(false))
|
||||
return Result.From(getLibrariesResult.Value.Select(library => library.ToResponse()).ToArray());
|
||||
return Result.From(getLibrariesResult.Value.Data.Select(library => library.ToResponse()).ToArray());
|
||||
else
|
||||
{
|
||||
// for regular users, only take the libraries that belong to them
|
||||
LibraryResponse[] userLibraries = [.. getLibrariesResult.Value
|
||||
// For regular users, only take the libraries that belong to them.
|
||||
LibraryResponse[] userLibraries = [.. getLibrariesResult.Value.Data
|
||||
.Where(library => library.UserId == userId)
|
||||
.Select(library => library.ToResponse())];
|
||||
|
||||
|
||||
+2
-2
@@ -53,14 +53,14 @@ public class GetPluginSettingsQueryHandler : IQueryHandler<GetPluginSettingsQuer
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
Result<PluginEntity?> getPluginResult = await _unitOfWork.PluginRepository.GetByIdAsync(query.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
Result<PluginEntity?> getPluginResult = await _unitOfWork.PluginRepository.GetByIdAsync(query.PluginId, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getPluginResult.IsFailure)
|
||||
return getPluginResult.Errors;
|
||||
PluginEntity? pluginEntity = getPluginResult.Value;
|
||||
if (pluginEntity is null)
|
||||
return Errors.Plugins.PluginNotFound;
|
||||
|
||||
// the schema comes from the loaded plugin, the current values from the storage medium
|
||||
// The schema comes from the loaded plugin, the current values from the storage medium.
|
||||
IPlugin? loadedPlugin = _pluginManager.GetPlugin(query.PluginId);
|
||||
IReadOnlyList<PluginSettingDescriptorResponse> schema = loadedPlugin is not null
|
||||
? loadedPlugin.GetSettingsSchema().Select(setting => setting.ToResponse()).ToList()
|
||||
|
||||
+6
-4
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Themes;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Mapping.Themes;
|
||||
using Lumina.Contracts.Responses.Themes;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -41,14 +43,14 @@ public class GetThemesQueryHandler : IQueryHandler<GetThemesQuery, Result<IReadO
|
||||
/// </returns>
|
||||
public async Task<Result<IReadOnlyList<ThemeResponse>>> HandleAsync(GetThemesQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<IEnumerable<ThemeEntity>> getThemesResult = await _unitOfWork.ThemeRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
Result<PaginatedResultDto<ThemeEntity>> getThemesResult = await _unitOfWork.ThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getThemesResult.IsFailure)
|
||||
return getThemesResult.Errors;
|
||||
|
||||
// deleted bundled themes are returned as well, so the administration page can offer to restore them
|
||||
return Result.From<IReadOnlyList<ThemeResponse>>([.. getThemesResult.Value
|
||||
// Deleted bundled themes are returned as well, so the administration page can offer to restore them.
|
||||
return Result.From<IReadOnlyList<ThemeResponse>>([.. getThemesResult.Value.Data
|
||||
.OrderBy(theme => theme.IsDeleted)
|
||||
// the shipped bundled themes are listed before the user themes, so the defaults stay the most visible
|
||||
// The shipped bundled themes are listed before the user themes, so the defaults stay the most visible.
|
||||
.ThenByDescending(theme => theme.InstallSource == ThemeInstallSource.Bundled)
|
||||
.ThenBy(theme => theme.Name, StringComparer.OrdinalIgnoreCase)
|
||||
.Select(theme => theme.ToResponse())]);
|
||||
|
||||
+6
-4
@@ -4,6 +4,8 @@ using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Users;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
@@ -50,17 +52,17 @@ public class GetUsersQueryHandler : IQueryHandler<GetUsersQuery, Result<IEnumera
|
||||
/// </returns>
|
||||
public async Task<Result<IEnumerable<UserResponse>>> HandleAsync(GetUsersQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
// an authenticated request must always carry a user identity
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// only admins can see the list of users
|
||||
// Only admins can see the list of users.
|
||||
bool isAdmin = await _authorizationService.IsInRoleAsync(userId, "Admin", cancellationToken).ConfigureAwait(false);
|
||||
if (!isAdmin)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
Result<IEnumerable<UserEntity>> getRolesResult = await _unitOfWork.UserRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
return getRolesResult.Match(value => Result.From(value.ToResponses()), errors => errors);
|
||||
Result<PaginatedResultDto<UserEntity>> getRolesResult = await _unitOfWork.UserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
return getRolesResult.Match(value => Result.From(value.Data.ToResponses()), errors => errors);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user