diff --git a/docs/technical/api/scheduling/Api.Scheduling.md b/docs/technical/api/scheduling/Api.Scheduling.md index a93ec99e..fcc99550 100644 --- a/docs/technical/api/scheduling/Api.Scheduling.md +++ b/docs/technical/api/scheduling/Api.Scheduling.md @@ -23,6 +23,12 @@ - [Fire Scheduled Job](#fire-scheduled-job) - [Fire Scheduled Job Request](#fire-scheduled-job-request) - [Fire Scheduled Job Response](#fire-scheduled-job-response) + - [Get Scheduler Display Preferences](#get-scheduler-display-preferences) + - [Get Scheduler Display Preferences Request](#get-scheduler-display-preferences-request) + - [Get Scheduler Display Preferences Response](#get-scheduler-display-preferences-response) + - [Update Scheduler Display Preferences](#update-scheduler-display-preferences) + - [Update Scheduler Display Preferences Request](#update-scheduler-display-preferences-request) + - [Update Scheduler Display Preferences Response](#update-scheduler-display-preferences-response) ## Scheduled Jobs @@ -60,12 +66,57 @@ POST api/v1/scheduled-jobs "intervalMinutes": null, "hour": 3, "minute": 0, - "status": "Added", + "status": "Active", "lastStartedOnUtc": null, "lastCompletedOnUtc": null } ``` +### Get Scheduler Display Preferences + +#### Get Scheduler Display Preferences Request + +```js +GET api/v1/scheduled-jobs/display-preferences +``` + +#### Get Scheduler Display Preferences Response + +```js +200 Ok +``` + +```json +{ + "userId": "2cff0c0f-3a67-4e30-b94f-f4e948a3b64f", + "jobTypeFilter": "ScanMediaLibraries", + "displayTimeSpan": 10, + "displayTimeUnit": "Minutes" +} +``` + +### Update Scheduler Display Preferences + +#### Update Scheduler Display Preferences Request + +```js +PUT api/v1/scheduled-jobs/display-preferences +``` + +```json +{ + "jobTypeFilter": "ScanMediaLibraries", + "displayTimeSpan": 10, + "displayTimeUnit": "Minutes" +} +``` + +#### Update Scheduler Display Preferences Response + +```js +200 Ok +``` + ### Get Scheduled Jobs #### Get Scheduled Jobs Request diff --git a/docs/technical/requests/scheduling/GetSchedulerDisplayPreferences.http b/docs/technical/requests/scheduling/GetSchedulerDisplayPreferences.http new file mode 100644 index 00000000..99e15c76 --- /dev/null +++ b/docs/technical/requests/scheduling/GetSchedulerDisplayPreferences.http @@ -0,0 +1,2 @@ +GET {{host}}/api/v1/scheduled-jobs/display-preferences +Authorization: Bearer {{ACCESS_TOKEN}} diff --git a/docs/technical/requests/scheduling/UpdateSchedulerDisplayPreferences.http b/docs/technical/requests/scheduling/UpdateSchedulerDisplayPreferences.http new file mode 100644 index 00000000..16d64d14 --- /dev/null +++ b/docs/technical/requests/scheduling/UpdateSchedulerDisplayPreferences.http @@ -0,0 +1,9 @@ +PUT {{host}}/api/v1/scheduled-jobs/display-preferences +Authorization: Bearer {{ACCESS_TOKEN}} +Content-Type: application/json + +{ + "jobTypeFilter": "ScanMediaLibraries", + "displayTimeSpan": 10, + "displayTimeUnit": "Minutes" +} diff --git a/src/Lumina.Application/Common/DataAccess/Entities/Scheduling/SchedulerDisplayPreferencesEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/Scheduling/SchedulerDisplayPreferencesEntity.cs new file mode 100644 index 00000000..7cdfea0d --- /dev/null +++ b/src/Lumina.Application/Common/DataAccess/Entities/Scheduling/SchedulerDisplayPreferencesEntity.cs @@ -0,0 +1,60 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DataAccess.Entities.Common; +using Lumina.Domain.SharedKernel.Common.Enums.Scheduling; +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Application.Common.DataAccess.Entities.Scheduling; + +/// +/// Repository entity for the display preferences of the scheduler page of a user. +/// +[DebuggerDisplay("UserId: {UserId}, DisplayTimeSpan: {DisplayTimeSpan}")] +public class SchedulerDisplayPreferencesEntity : IStorageEntity, IAuditableEntity +{ + /// + /// Gets or sets the Id of the display preferences. + /// + public required Guid Id { get; init; } + + /// + /// Gets or sets the Id of the user that owns the display preferences. + /// + public required Guid UserId { get; set; } + + /// + /// Gets or sets the type of the scheduled job tasks whose executions are shown on the scheduler page, or when all of them are shown. + /// + public ScheduledTaskType? JobTypeFilter { get; set; } + + /// + /// Gets or sets the time span, expressed in , that the scheduler page shows. + /// + public required int DisplayTimeSpan { get; set; } + + /// + /// Gets or sets the unit in which the displayed time span of the scheduler page is expressed. + /// + public required SchedulerDisplayTimeUnit DisplayTimeUnit { get; set; } + + /// + /// Gets or sets the time and date when the entity was added. + /// + public required DateTime CreatedOnUtc { get; set; } + + /// + /// Gets or sets the Id of the user that created the entity. + /// + public required Guid CreatedBy { get; set; } + + /// + /// Gets or sets the optional time and date when the entity was updated. + /// + public DateTime? UpdatedOnUtc { get; set; } + + /// + /// Gets or sets the optional Id of the user that updated the entity. + /// + public required Guid? UpdatedBy { get; set; } +} diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Scheduling/ISchedulerDisplayPreferencesRepository.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Scheduling/ISchedulerDisplayPreferencesRepository.cs new file mode 100644 index 00000000..c574e898 --- /dev/null +++ b/src/Lumina.Application/Common/DataAccess/Repositories/Scheduling/ISchedulerDisplayPreferencesRepository.cs @@ -0,0 +1,32 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DataAccess.Entities.Scheduling; +using Lumina.Application.Common.DataAccess.Repositories.Common.Base; +using Lumina.Domain.Common.Primitives; +using System; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Application.Common.DataAccess.Repositories.Scheduling; + +/// +/// Interface for the repository for the display preferences of the scheduler page. +/// +public interface ISchedulerDisplayPreferencesRepository : IRepository +{ + /// + /// Gets the display preferences of the scheduler page of the user identified by , if they exist. + /// + /// The Id of the user whose display preferences are retrieved. + /// Cancellation token that can be used to stop the execution. + /// An containing either the display preferences of the user, or an error. + Task> GetByUserIdAsync(Guid userId, CancellationToken cancellationToken); + + /// + /// Inserts the display preferences of the scheduler page of a user, or updates them when they already exist. + /// + /// The display preferences to insert or update. + /// Cancellation token that can be used to stop the execution. + /// An representing either a successful operation, or an error. + Task> UpsertAsync(SchedulerDisplayPreferencesEntity preferences, CancellationToken cancellationToken); +} diff --git a/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs b/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs index 8a84bce4..9c4c7407 100644 --- a/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs +++ b/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs @@ -98,6 +98,11 @@ public interface IUnitOfWork /// IScheduledJobExecutionRepository ScheduledJobExecutionRepository { get; } + /// + /// Gets the scheduler display preferences repository. + /// + ISchedulerDisplayPreferencesRepository SchedulerDisplayPreferencesRepository { get; } + /// /// Gets the plugin repository. /// diff --git a/src/Lumina.Application/Common/Mapping/Scheduling/SchedulerDisplayPreferencesEntityMapping.cs b/src/Lumina.Application/Common/Mapping/Scheduling/SchedulerDisplayPreferencesEntityMapping.cs new file mode 100644 index 00000000..0e01d898 --- /dev/null +++ b/src/Lumina.Application/Common/Mapping/Scheduling/SchedulerDisplayPreferencesEntityMapping.cs @@ -0,0 +1,48 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DataAccess.Entities.Scheduling; +using Lumina.Contracts.Responses.Scheduling; +using Lumina.Domain.SharedKernel.Common.Enums.Scheduling; +using System; +#endregion + +namespace Lumina.Application.Common.Mapping.Scheduling; + +/// +/// Extension methods for converting . +/// +public static class SchedulerDisplayPreferencesEntityMapping +{ + private const int DEFAULT_DISPLAY_TIME_SPAN = 10; + private const SchedulerDisplayTimeUnit DEFAULT_DISPLAY_TIME_UNIT = SchedulerDisplayTimeUnit.Minutes; + + /// + /// Converts to . + /// + /// The repository entity to be converted. + /// The converted response. + public static SchedulerDisplayPreferencesResponse ToResponse(this SchedulerDisplayPreferencesEntity repositoryEntity) + { + return new SchedulerDisplayPreferencesResponse( + repositoryEntity.UserId, + repositoryEntity.JobTypeFilter, + repositoryEntity.DisplayTimeSpan, + repositoryEntity.DisplayTimeUnit + ); + } + + /// + /// Converts the lack of stored display preferences to the default of the user identified by . + /// + /// The missing repository entity, which is . + /// The Id of the user that owns the display preferences. + /// The converted response with the default display preferences. + public static SchedulerDisplayPreferencesResponse ToDefaultResponse(this SchedulerDisplayPreferencesEntity? repositoryEntity, Guid userId) + { + return new SchedulerDisplayPreferencesResponse( + userId, + null, + DEFAULT_DISPLAY_TIME_SPAN, + DEFAULT_DISPLAY_TIME_UNIT + ); + } +} diff --git a/src/Lumina.Application/Common/Mapping/Scheduling/UpdateSchedulerDisplayPreferencesRequestMapping.cs b/src/Lumina.Application/Common/Mapping/Scheduling/UpdateSchedulerDisplayPreferencesRequestMapping.cs new file mode 100644 index 00000000..f0e74408 --- /dev/null +++ b/src/Lumina.Application/Common/Mapping/Scheduling/UpdateSchedulerDisplayPreferencesRequestMapping.cs @@ -0,0 +1,26 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Core.Scheduling.Commands.UpdateSchedulerDisplayPreferences; +using Lumina.Contracts.Requests.Scheduling; +#endregion + +namespace Lumina.Application.Common.Mapping.Scheduling; + +/// +/// Extension methods for converting . +/// +public static class UpdateSchedulerDisplayPreferencesRequestMapping +{ + /// + /// Converts to . + /// + /// The request to be converted. + /// The converted command. + public static UpdateSchedulerDisplayPreferencesCommand ToCommand(this UpdateSchedulerDisplayPreferencesRequest request) + { + return new UpdateSchedulerDisplayPreferencesCommand( + request.JobTypeFilter, + request.DisplayTimeSpan, + request.DisplayTimeUnit + ); + } +} diff --git a/src/Lumina.Application/Core/Scheduling/Commands/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesCommand.cs b/src/Lumina.Application/Core/Scheduling/Commands/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesCommand.cs new file mode 100644 index 00000000..2115f817 --- /dev/null +++ b/src/Lumina.Application/Core/Scheduling/Commands/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesCommand.cs @@ -0,0 +1,20 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.CQRS; +using Lumina.Domain.SharedKernel.Common.Enums.Scheduling; +using System.Diagnostics; +#endregion + +namespace Lumina.Application.Core.Scheduling.Commands.UpdateSchedulerDisplayPreferences; + +/// +/// Command for updating the display preferences of the scheduler page of the current user. +/// +/// The type of the scheduled job tasks whose executions are shown on the scheduler page, or when all of them are shown. +/// The time span, expressed in , that the scheduler page shows. +/// The unit in which the displayed time span of the scheduler page is expressed. +[DebuggerDisplay("DisplayTimeSpan: {DisplayTimeSpan} {DisplayTimeUnit}")] +public record UpdateSchedulerDisplayPreferencesCommand( + ScheduledTaskType? JobTypeFilter, + int DisplayTimeSpan, + SchedulerDisplayTimeUnit DisplayTimeUnit +) : ICommand; diff --git a/src/Lumina.Application/Core/Scheduling/Commands/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesCommandHandler.cs b/src/Lumina.Application/Core/Scheduling/Commands/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesCommandHandler.cs new file mode 100644 index 00000000..54c6fa4b --- /dev/null +++ b/src/Lumina.Application/Core/Scheduling/Commands/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesCommandHandler.cs @@ -0,0 +1,86 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.CQRS; +using Lumina.Application.Common.DataAccess.Entities.Scheduling; +using Lumina.Application.Common.DataAccess.UoW; +using Lumina.Application.Common.Infrastructure.Authentication; +using Lumina.Application.Common.Infrastructure.Authorization; +using Lumina.Application.Common.Infrastructure.Validation; +using Lumina.Domain.Common.Primitives; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using ApplicationErrors = Lumina.Application.Common.Errors.Errors; +#endregion + +namespace Lumina.Application.Core.Scheduling.Commands.UpdateSchedulerDisplayPreferences; + +/// +/// Handler for the command to update the display preferences of the scheduler page of the current user. +/// +public class UpdateSchedulerDisplayPreferencesCommandHandler : ICommandHandler> +{ + private readonly ICurrentUserService _currentUserService; + private readonly IAuthorizationService _authorizationService; + private readonly IUnitOfWork _unitOfWork; + private readonly IValidator _validator; + + /// + /// Initializes a new instance of the class. + /// + /// Injected service for authorization related functionality. + /// Injected service to retrieve the current user information. + /// Injected unit of work for interacting with the data access layer repositories. + /// Injected validator for application validation rules. + public UpdateSchedulerDisplayPreferencesCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork, IValidator validator) + { + _authorizationService = authorizationService; + _currentUserService = currentUserService; + _unitOfWork = unitOfWork; + _validator = validator; + } + + /// + /// Handles the command to update the display preferences of the scheduler page of the current user. + /// + /// The command to be handled. + /// Cancellation token that can be used to stop the execution. + /// + /// An representing either a successful update, or an error. + /// + public async Task> HandleAsync(UpdateSchedulerDisplayPreferencesCommand command, CancellationToken cancellationToken) + { + List validationResult = _validator.Validate(command); + if (validationResult.Count > 0) + return validationResult; + + // An authenticated request must always carry a user identity. + Guid? currentUserId = _currentUserService.UserId; + if (currentUserId is null) + return ApplicationErrors.Authorization.NotAuthorized; + Guid userId = currentUserId.Value; + + // Only administrators can use the scheduler page. + if (!await _authorizationService.IsInRoleAsync(userId, "Admin", cancellationToken).ConfigureAwait(false)) + return ApplicationErrors.Authorization.NotAuthorized; + + // Upsert the display preferences of the scheduler page of the current user. + SchedulerDisplayPreferencesEntity displayPreferences = new() + { + Id = Guid.NewGuid(), + UserId = userId, + JobTypeFilter = command.JobTypeFilter, + DisplayTimeSpan = command.DisplayTimeSpan, + DisplayTimeUnit = command.DisplayTimeUnit, + CreatedOnUtc = default, + CreatedBy = default, + UpdatedOnUtc = null, + UpdatedBy = null + }; + Result upsertResult = await _unitOfWork.SchedulerDisplayPreferencesRepository.UpsertAsync(displayPreferences, cancellationToken).ConfigureAwait(false); + if (upsertResult.IsFailure) + return upsertResult.Errors; + await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false); + return Result.Updated; + } +} diff --git a/src/Lumina.Application/Core/Scheduling/Commands/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesCommandValidator.cs b/src/Lumina.Application/Core/Scheduling/Commands/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesCommandValidator.cs new file mode 100644 index 00000000..6dea97e1 --- /dev/null +++ b/src/Lumina.Application/Core/Scheduling/Commands/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesCommandValidator.cs @@ -0,0 +1,23 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.Infrastructure.Validation; +using Lumina.Application.Common.Utilities; +using Lumina.Domain.Common.Errors; +#endregion + +namespace Lumina.Application.Core.Scheduling.Commands.UpdateSchedulerDisplayPreferences; + +/// +/// Validates the needed validation rules for . +/// +public class UpdateSchedulerDisplayPreferencesCommandValidator : AbstractValidator +{ + /// + /// Initializes a new instance of the class. + /// + public UpdateSchedulerDisplayPreferencesCommandValidator() + { + RuleFor(command => command.DisplayTimeSpan) + .GreaterThan(0) + .WithError(Errors.Scheduling.SchedulerDisplayTimeSpanMustBePositive); + } +} diff --git a/src/Lumina.Application/Core/Scheduling/Queries/GetSchedulerDisplayPreferences/GetSchedulerDisplayPreferencesQuery.cs b/src/Lumina.Application/Core/Scheduling/Queries/GetSchedulerDisplayPreferences/GetSchedulerDisplayPreferencesQuery.cs new file mode 100644 index 00000000..6f12960a --- /dev/null +++ b/src/Lumina.Application/Core/Scheduling/Queries/GetSchedulerDisplayPreferences/GetSchedulerDisplayPreferencesQuery.cs @@ -0,0 +1,10 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.CQRS; +#endregion + +namespace Lumina.Application.Core.Scheduling.Queries.GetSchedulerDisplayPreferences; + +/// +/// Query for getting the display preferences of the scheduler page of the current user. +/// +public record GetSchedulerDisplayPreferencesQuery : IQuery; diff --git a/src/Lumina.Application/Core/Scheduling/Queries/GetSchedulerDisplayPreferences/GetSchedulerDisplayPreferencesQueryHandler.cs b/src/Lumina.Application/Core/Scheduling/Queries/GetSchedulerDisplayPreferences/GetSchedulerDisplayPreferencesQueryHandler.cs new file mode 100644 index 00000000..eeaaff89 --- /dev/null +++ b/src/Lumina.Application/Core/Scheduling/Queries/GetSchedulerDisplayPreferences/GetSchedulerDisplayPreferencesQueryHandler.cs @@ -0,0 +1,72 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.CQRS; +using Lumina.Application.Common.DataAccess.Entities.Scheduling; +using Lumina.Application.Common.DataAccess.UoW; +using Lumina.Application.Common.Errors; +using Lumina.Application.Common.Infrastructure.Authentication; +using Lumina.Application.Common.Infrastructure.Authorization; +using Lumina.Application.Common.Mapping.Scheduling; +using Lumina.Contracts.Responses.Scheduling; +using Lumina.Domain.Common.Primitives; +using System; +using System.Threading; +using System.Threading.Tasks; +using ApplicationErrors = Lumina.Application.Common.Errors.Errors; +#endregion + +namespace Lumina.Application.Core.Scheduling.Queries.GetSchedulerDisplayPreferences; + +/// +/// Handler for the query to get the display preferences of the scheduler page of the current user. +/// +public class GetSchedulerDisplayPreferencesQueryHandler : IQueryHandler> +{ + private readonly ICurrentUserService _currentUserService; + private readonly IAuthorizationService _authorizationService; + private readonly IUnitOfWork _unitOfWork; + + /// + /// Initializes a new instance of the class. + /// + /// Injected service for authorization related functionality. + /// Injected service to retrieve the current user information. + /// Injected unit of work for interacting with the data access layer repositories. + public GetSchedulerDisplayPreferencesQueryHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork) + { + _authorizationService = authorizationService; + _currentUserService = currentUserService; + _unitOfWork = unitOfWork; + } + + /// + /// Handles the query to get the display preferences of the scheduler page of the current user. + /// + /// The query to be handled. + /// Cancellation token that can be used to stop the execution. + /// + /// An containing either the display preferences of the scheduler page of the current user, or an error. + /// + public async Task> HandleAsync(GetSchedulerDisplayPreferencesQuery query, CancellationToken cancellationToken) + { + // An authenticated request must always carry a user identity. + Guid? currentUserId = _currentUserService.UserId; + if (currentUserId is null) + return ApplicationErrors.Authorization.NotAuthorized; + Guid userId = currentUserId.Value; + + // Only administrators can view the scheduler page. + if (!await _authorizationService.IsInRoleAsync(userId, "Admin", cancellationToken).ConfigureAwait(false)) + return ApplicationErrors.Authorization.NotAuthorized; + + // Get the display preferences of the scheduler page of the current user from the repository. + Result getDisplayPreferencesResult = await _unitOfWork.SchedulerDisplayPreferencesRepository.GetByUserIdAsync(userId, cancellationToken).ConfigureAwait(false); + if (getDisplayPreferencesResult.IsFailure) + return getDisplayPreferencesResult.Errors; + + // When no display preferences are stored for the current user yet, return the default display preferences. + if (getDisplayPreferencesResult.Value is null) + return getDisplayPreferencesResult.Value.ToDefaultResponse(userId); + + return getDisplayPreferencesResult.Value.ToResponse(); + } +} diff --git a/src/Lumina.Contracts/Requests/Scheduling/UpdateSchedulerDisplayPreferencesRequest.cs b/src/Lumina.Contracts/Requests/Scheduling/UpdateSchedulerDisplayPreferencesRequest.cs new file mode 100644 index 00000000..ff546221 --- /dev/null +++ b/src/Lumina.Contracts/Requests/Scheduling/UpdateSchedulerDisplayPreferencesRequest.cs @@ -0,0 +1,19 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.SharedKernel.Common.Enums.Scheduling; +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Requests.Scheduling; + +/// +/// Represents a request to update the display preferences of the scheduler page of the current user. +/// +/// The type of the scheduled job tasks whose executions are shown on the scheduler page, or when all of them are shown. +/// The time span, expressed in , that the scheduler page shows. Required. +/// The unit in which the displayed time span of the scheduler page is expressed. Required. +[DebuggerDisplay("DisplayTimeSpan: {DisplayTimeSpan} {DisplayTimeUnit}")] +public sealed record UpdateSchedulerDisplayPreferencesRequest( + ScheduledTaskType? JobTypeFilter, + int DisplayTimeSpan, + SchedulerDisplayTimeUnit DisplayTimeUnit +); diff --git a/src/Lumina.Contracts/Responses/Scheduling/SchedulerDisplayPreferencesResponse.cs b/src/Lumina.Contracts/Responses/Scheduling/SchedulerDisplayPreferencesResponse.cs new file mode 100644 index 00000000..d762eccf --- /dev/null +++ b/src/Lumina.Contracts/Responses/Scheduling/SchedulerDisplayPreferencesResponse.cs @@ -0,0 +1,22 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.SharedKernel.Common.Enums.Scheduling; +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Responses.Scheduling; + +/// +/// Represents the display preferences of the scheduler page of a user. +/// +/// The unique identifier of the user that owns the display preferences. +/// The type of the scheduled job tasks whose executions are shown on the scheduler page, or when all of them are shown. +/// The time span, expressed in , that the scheduler page shows. +/// The unit in which the displayed time span of the scheduler page is expressed. +[DebuggerDisplay("UserId: {UserId}, DisplayTimeSpan: {DisplayTimeSpan} {DisplayTimeUnit}")] +public sealed record SchedulerDisplayPreferencesResponse( + Guid UserId, + ScheduledTaskType? JobTypeFilter, + int DisplayTimeSpan, + SchedulerDisplayTimeUnit DisplayTimeUnit +); diff --git a/src/Lumina.DataAccess/Common/Configuration/SchedulerDisplayPreferencesConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/SchedulerDisplayPreferencesConfiguration.cs new file mode 100644 index 00000000..698aaac7 --- /dev/null +++ b/src/Lumina.DataAccess/Common/Configuration/SchedulerDisplayPreferencesConfiguration.cs @@ -0,0 +1,65 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DataAccess.Entities.Scheduling; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using System; +#endregion + +namespace Lumina.DataAccess.Common.Configuration; + +/// +/// Configures the entity mapping for the entity. +/// +public class SchedulerDisplayPreferencesConfiguration : IEntityTypeConfiguration +{ + /// + /// Configures the entity. + /// + /// The builder to be used to configure the entity. + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("SchedulerDisplayPreferences"); + builder.HasKey(preferences => preferences.Id); + builder.Property(preferences => preferences.Id) + .ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it + .HasColumnOrder(0); + + builder.Property(preferences => preferences.UserId) + .IsRequired() + .HasColumnOrder(1); + + builder.Property(preferences => preferences.JobTypeFilter) + .HasConversion() + .HasColumnOrder(2); + + builder.Property(preferences => preferences.DisplayTimeSpan) + .IsRequired() + .HasColumnOrder(3); + + builder.Property(preferences => preferences.DisplayTimeUnit) + .IsRequired() + .HasConversion() + .HasColumnOrder(4); + + // Audit. + builder.Property(preferences => preferences.CreatedOnUtc) + .IsRequired() + .HasColumnOrder(5); + + builder.Property(preferences => preferences.CreatedBy) + .IsRequired() + .HasColumnOrder(6); + + builder.Property(preferences => preferences.UpdatedOnUtc) + .HasDefaultValue(null) + .HasColumnOrder(7); + + builder.Property(preferences => preferences.UpdatedBy) + .HasDefaultValue(null) + .HasColumnOrder(8); + + // One user has at most one set of scheduler page display preferences. + builder.HasIndex(preferences => preferences.UserId) + .IsUnique(); + } +} diff --git a/src/Lumina.DataAccess/Common/Migrations/20260903201036_AddsSchedulerDisplayPreferences.Designer.cs b/src/Lumina.DataAccess/Common/Migrations/20260903201036_AddsSchedulerDisplayPreferences.Designer.cs new file mode 100644 index 00000000..e11987b7 --- /dev/null +++ b/src/Lumina.DataAccess/Common/Migrations/20260903201036_AddsSchedulerDisplayPreferences.Designer.cs @@ -0,0 +1,1788 @@ +// +using System; +using Lumina.DataAccess.Core.UoW; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Lumina.DataAccess.Common.Migrations +{ + [DbContext(typeof(LuminaDbContext))] + [Migration("20260903201036_AddsSchedulerDisplayPreferences")] + partial class AddsSchedulerDisplayPreferences + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "10.0.11"); + + modelBuilder.Entity("BookGenres", b => + { + b.Property("BookId") + .HasColumnType("TEXT"); + + b.Property("GenreId") + .HasColumnType("TEXT"); + + b.HasKey("BookId", "GenreId"); + + b.HasIndex("GenreId"); + + b.ToTable("BookGenres", (string)null); + }); + + modelBuilder.Entity("BookTags", b => + { + b.Property("BookId") + .HasColumnType("TEXT"); + + b.Property("TagId") + .HasColumnType("TEXT"); + + b.HasKey("BookId", "TagId"); + + b.HasIndex("TagId"); + + b.ToTable("BookTags", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.HasKey("Id"); + + b.ToTable("Permissions", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.HasKey("Id"); + + b.ToTable("Roles", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RolePermissionEntity", b => + { + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("PermissionId") + .HasColumnType("TEXT"); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.HasKey("RoleId", "PermissionId"); + + b.HasIndex("PermissionId"); + + b.HasIndex("RoleId", "PermissionId") + .IsUnique(); + + b.ToTable("RolePermissions", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserPermissionEntity", b => + { + b.Property("UserId") + .HasColumnType("TEXT"); + + b.Property("PermissionId") + .HasColumnType("TEXT"); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.HasKey("UserId", "PermissionId"); + + b.HasIndex("PermissionId"); + + b.HasIndex("UserId", "PermissionId") + .IsUnique(); + + b.ToTable("UserPermissions", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", b => + { + b.Property("UserId") + .HasColumnType("TEXT"); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.HasKey("UserId"); + + b.HasIndex("RoleId"); + + b.HasIndex("UserId", "RoleId") + .IsUnique(); + + b.ToTable("UserRoles", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", b => + { + b.Property("Name") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("Genres", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", b => + { + b.Property("Name") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("Tags", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaContributors.BookContributorEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("BookId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("MediaContributorId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("RoleCategory") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.HasKey("Id"); + + b.HasIndex("MediaContributorId"); + + b.HasIndex("BookId", "MediaContributorId"); + + b.ToTable("BookContributors", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaContributors.MediaContributorEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Biography") + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("DateOfBirth") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("DateOfDeath") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("DisplayName") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1) + .UseCollation("NOCASE"); + + b.Property("LegalName") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.HasKey("Id"); + + b.HasIndex("DisplayName") + .IsUnique(); + + b.ToTable("MediaContributors", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.DirectoryScanFingerprintEntity", b => + { + b.Property("LibraryId") + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(1024) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("LastWriteTimeUtc") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.HasKey("LibraryId", "Path"); + + b.HasIndex("LibraryId"); + + b.ToTable("DirectoryScanFingerprints", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ArtworkProvidersConfigurationFingerprint") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("CanDownloadMetadataFromWeb") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasDefaultValue(true) + .HasColumnOrder(6); + + b.Property("CoverImage") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("IsEnabled") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasDefaultValue(true) + .HasColumnOrder(4); + + b.Property("IsLocked") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("LibraryType") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("MetadataProvidersConfigurationFingerprint") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("ShouldSaveMetadataInMediaDirectories") + .HasColumnType("INTEGER") + .HasColumnOrder(7); + + b.Property("ShouldSkipUnchangedDirectoriesDuringScan") + .HasColumnType("INTEGER") + .HasColumnOrder(8); + + b.Property("Title") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("UserId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Libraries", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("LibraryId") + .HasColumnType("TEXT"); + + b.Property("Status") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("UserId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.HasIndex("LibraryId", "Status", "CreatedOnUtc") + .IsDescending(true, false, true); + + b.ToTable("LibraryScans", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanResultEntity", b => + { + b.Property("LibraryScanId") + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(1024) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("ContentHash") + .HasMaxLength(24) + .HasColumnType("INTEGER") + .HasColumnOrder(2); + + b.Property("FileSize") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Status") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("Ticks") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.HasKey("LibraryScanId", "Path"); + + b.HasIndex("Path"); + + b.HasIndex("ContentHash", "FileSize", "Path"); + + b.ToTable("LibraryScanResults", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanSnapshotEntity", b => + { + b.Property("LibraryId") + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(1024) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("ContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(2); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("FileSize") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Ticks") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.HasKey("LibraryId", "Path"); + + b.HasIndex("LibraryId"); + + b.ToTable("LibraryScanSnapshots", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanStagingResultsEntity", b => + { + b.Property("LibraryScanId") + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(1024) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("ContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("IsNew") + .HasColumnType("INTEGER") + .HasColumnOrder(7); + + b.Property("NeedsRehash") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.Property("PreviousContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("Size") + .HasColumnType("INTEGER") + .HasColumnOrder(2); + + b.Property("Ticks") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.HasKey("LibraryScanId", "Path"); + + b.HasIndex("LibraryScanId", "NeedsRehash"); + + b.ToTable("LibraryScanStagingResults", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookArtworkEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ArtworkType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("BookId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("ContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("FileName") + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("LastUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("Ordinal") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("Provider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("Status") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.HasKey("Id"); + + b.HasIndex("Status"); + + b.HasIndex("BookId", "ArtworkType", "Ordinal") + .IsUnique(); + + b.ToTable("BookArtwork", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ASIN") + .HasMaxLength(10) + .HasColumnType("TEXT") + .HasColumnOrder(21); + + b.Property("AppleBooksId") + .HasColumnType("TEXT") + .HasColumnOrder(29); + + b.Property("BarnesAndNobleId") + .HasMaxLength(10) + .HasColumnType("TEXT") + .HasColumnOrder(28); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(33); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(32); + + b.Property("Description") + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("Edition") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(19); + + b.Property("Format") + .HasColumnType("TEXT") + .HasColumnOrder(18); + + b.Property("GoodreadsId") + .HasColumnType("TEXT") + .HasColumnOrder(22); + + b.Property("GoogleBooksId") + .HasMaxLength(12) + .HasColumnType("TEXT") + .HasColumnOrder(27); + + b.Property("LCCN") + .HasColumnType("TEXT") + .HasColumnOrder(23); + + b.Property("LanguageCode") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("LanguageName") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("LanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("LastMetadataUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(39); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(36); + + b.Property("LibraryThingId") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(26); + + b.Property("MetadataProvider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(40); + + b.Property("MetadataStatus") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(38); + + b.Property("OCLCNumber") + .HasColumnType("TEXT") + .HasColumnOrder(24); + + b.Property("OpenLibraryId") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(25); + + b.Property("OriginalLanguageCode") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("OriginalLanguageName") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("OriginalLanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("OriginalReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("OriginalReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("OriginalTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("PageCount") + .HasColumnType("INTEGER") + .HasColumnOrder(17); + + b.Property("Path") + .IsRequired() + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(37); + + b.Property("Publisher") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(16); + + b.Property("ReReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("ReReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(7); + + b.Property("ReleaseCountry") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("ReleaseVersion") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("Title") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(35); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(34); + + b.Property("VolumeNumber") + .HasColumnType("REAL") + .HasColumnOrder(20); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "MetadataStatus"); + + b.HasIndex("LibraryId", "Path"); + + b.ToTable("Books", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Plugins.LibraryArtworkProviderConfigurationEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("IsEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("PluginId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("Rank") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "PluginId"); + + b.ToTable("LibraryArtworkProviderConfigurations", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Plugins.LibraryBookReaderConfigurationEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("IsEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("PluginId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "PluginId") + .IsUnique(); + + b.ToTable("LibraryBookReaderConfigurations", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Plugins.LibraryMetadataProviderConfigurationEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("IsEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("PluginId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("Rank") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "PluginId"); + + b.ToTable("LibraryMetadataProviderConfigurations", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Plugins.PluginEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Author") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("Description") + .IsRequired() + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("LoadError") + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("LoadStatus") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("Name") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("SettingsJson") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("Version") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.HasKey("Id"); + + b.ToTable("Plugins", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Scheduling.ScheduledJobEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("Hour") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("IntervalMinutes") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("LastCompletedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("LastStartedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("Minute") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("OwnerUserId") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("ScheduleType") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("Status") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("TaskType") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.HasKey("Id"); + + b.HasIndex("Status"); + + b.ToTable("ScheduledJobs", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Scheduling.ScheduledJobExecutionEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CompletedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("IsCycleRun") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("ScheduledJobId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("StartedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("TaskType") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.HasKey("Id"); + + b.HasIndex("ScheduledJobId"); + + b.HasIndex("StartedOnUtc", "ScheduledJobId"); + + b.ToTable("ScheduledJobExecutions", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Scheduling.SchedulerDisplayPreferencesEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("DisplayTimeSpan") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("DisplayTimeUnit") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("JobTypeFilter") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UserId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("SchedulerDisplayPreferences", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Themes.ThemeEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Author") + .IsRequired() + .HasMaxLength(80) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("Description") + .IsRequired() + .HasMaxLength(300) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("InstallSource") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("InstalledAtUtc") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("IsCurrent") + .HasColumnType("INTEGER") + .HasColumnOrder(8); + + b.Property("IsDeleted") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasDefaultValue(false) + .HasColumnOrder(9); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("PreviewPath") + .HasMaxLength(240) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("ThemeId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("Version") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.HasKey("Id"); + + b.HasIndex("IsCurrent") + .IsUnique() + .HasFilter("IsCurrent = 1"); + + b.HasIndex("ThemeId") + .IsUnique(); + + b.ToTable("Themes", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("Password") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("TempPassword") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("TempPasswordCreated") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("TotpSecret") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("Username") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.HasKey("Id"); + + b.HasIndex("Username") + .IsUnique(); + + b.ToTable("Users", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserSettingsEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("IsPaginationEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(2); + + b.Property("IsThemeCachingEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(9); + + b.Property("ItemsPerPage") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("ShouldAggregateMetadataWhenMissing") + .HasColumnType("INTEGER") + .HasColumnOrder(10); + + b.Property("ShouldIgnoreThePrefixForAlphaPicker") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("ShouldPreserveBookStyles") + .HasColumnType("INTEGER") + .HasColumnOrder(12); + + b.Property("ShouldRenderPdfAsImages") + .HasColumnType("INTEGER") + .HasColumnOrder(11); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UserId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("UserSettings", (string)null); + }); + + modelBuilder.Entity("BookGenres", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null) + .WithMany() + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", null) + .WithMany() + .HasForeignKey("GenreId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BookTags", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null) + .WithMany() + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", null) + .WithMany() + .HasForeignKey("TagId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RolePermissionEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", "Permission") + .WithMany("RolePermissions") + .HasForeignKey("PermissionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", "Role") + .WithMany("RolePermissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Permission"); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserPermissionEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", "Permission") + .WithMany("UserPermissions") + .HasForeignKey("PermissionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User") + .WithMany("UserPermissions") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Permission"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", "Role") + .WithMany("UserRoles") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User") + .WithOne("UserRole") + .HasForeignKey("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaContributors.BookContributorEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null) + .WithMany("BookContributors") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.DirectoryScanFingerprintEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", null) + .WithMany() + .HasForeignKey("LibraryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User") + .WithMany("Libraries") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryContentLocationEntity", "ContentLocations", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("LibraryId") + .HasColumnType("TEXT"); + + b1.Property("Path") + .IsRequired() + .HasMaxLength(260) + .HasColumnType("TEXT") + .HasColumnName("Path"); + + b1.HasKey("Id"); + + b1.HasIndex("LibraryId"); + + b1.ToTable("LibraryContentLocations", (string)null); + + b1.WithOwner() + .HasForeignKey("LibraryId"); + }); + + b.Navigation("ContentLocations"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", "Library") + .WithMany("LibraryScans") + .HasForeignKey("LibraryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User") + .WithMany("LibraryScans") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Library"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanResultEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", "LibraryScan") + .WithMany("LibraryScanResults") + .HasForeignKey("LibraryScanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("LibraryScan"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanSnapshotEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", "Library") + .WithMany() + .HasForeignKey("LibraryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Library"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanStagingResultsEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", null) + .WithMany() + .HasForeignKey("LibraryScanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookArtworkEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null) + .WithMany("BookArtwork") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b => + { + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookRatingEntity", "Ratings", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("BookId") + .HasColumnType("TEXT"); + + b1.Property("MaxValue") + .HasColumnType("decimal(3,2)"); + + b1.Property("Source") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.Property("Value") + .HasColumnType("decimal(3,2)"); + + b1.Property("VoteCount") + .HasColumnType("INTEGER"); + + b1.HasKey("Id"); + + b1.HasIndex("BookId"); + + b1.ToTable("BookRatings", (string)null); + + b1.WithOwner() + .HasForeignKey("BookId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.IsbnEntity", "ISBNs", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("BookId") + .HasColumnType("TEXT"); + + b1.Property("Format") + .IsRequired() + .HasMaxLength(6) + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(13) + .HasColumnType("TEXT") + .HasColumnName("ISBN"); + + b1.HasKey("Id"); + + b1.HasIndex("BookId"); + + b1.ToTable("BookISBNs", (string)null); + + b1.WithOwner() + .HasForeignKey("BookId"); + }); + + b.Navigation("ISBNs"); + + b.Navigation("Ratings"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserSettingsEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", null) + .WithOne() + .HasForeignKey("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserSettingsEntity", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", b => + { + b.Navigation("RolePermissions"); + + b.Navigation("UserPermissions"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", b => + { + b.Navigation("RolePermissions"); + + b.Navigation("UserRoles"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b => + { + b.Navigation("LibraryScans"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", b => + { + b.Navigation("LibraryScanResults"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b => + { + b.Navigation("BookArtwork"); + + b.Navigation("BookContributors"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", b => + { + b.Navigation("Libraries"); + + b.Navigation("LibraryScans"); + + b.Navigation("UserPermissions"); + + b.Navigation("UserRole"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Lumina.DataAccess/Common/Migrations/20260903201036_AddsSchedulerDisplayPreferences.cs b/src/Lumina.DataAccess/Common/Migrations/20260903201036_AddsSchedulerDisplayPreferences.cs new file mode 100644 index 00000000..80cac03b --- /dev/null +++ b/src/Lumina.DataAccess/Common/Migrations/20260903201036_AddsSchedulerDisplayPreferences.cs @@ -0,0 +1,47 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Lumina.DataAccess.Common.Migrations +{ + /// + public partial class AddsSchedulerDisplayPreferences : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "SchedulerDisplayPreferences", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + UserId = table.Column(type: "TEXT", nullable: false), + JobTypeFilter = table.Column(type: "TEXT", nullable: true), + DisplayTimeSpan = table.Column(type: "INTEGER", nullable: false), + DisplayTimeUnit = table.Column(type: "TEXT", nullable: false), + CreatedOnUtc = table.Column(type: "TEXT", nullable: false), + CreatedBy = table.Column(type: "TEXT", nullable: false), + UpdatedOnUtc = table.Column(type: "TEXT", nullable: true), + UpdatedBy = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_SchedulerDisplayPreferences", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_SchedulerDisplayPreferences_UserId", + table: "SchedulerDisplayPreferences", + column: "UserId", + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "SchedulerDisplayPreferences"); + } + } +} diff --git a/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs b/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs index f918da35..9f148e5f 100644 --- a/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs +++ b/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs @@ -1,4 +1,4 @@ -// . +// using System; using Lumina.DataAccess.Core.UoW; using Microsoft.EntityFrameworkCore; @@ -1207,6 +1207,53 @@ namespace Lumina.DataAccess.Common.Migrations b.ToTable("ScheduledJobExecutions", (string)null); }); + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Scheduling.SchedulerDisplayPreferencesEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("DisplayTimeSpan") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("DisplayTimeUnit") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("JobTypeFilter") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UserId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("SchedulerDisplayPreferences", (string)null); + }); + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Themes.ThemeEntity", b => { b.Property("Id") diff --git a/src/Lumina.DataAccess/Core/Repositories/Scheduling/SchedulerDisplayPreferencesRepository.cs b/src/Lumina.DataAccess/Core/Repositories/Scheduling/SchedulerDisplayPreferencesRepository.cs new file mode 100644 index 00000000..cb7ed707 --- /dev/null +++ b/src/Lumina.DataAccess/Core/Repositories/Scheduling/SchedulerDisplayPreferencesRepository.cs @@ -0,0 +1,63 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DataAccess.Entities.Scheduling; +using Lumina.Application.Common.DataAccess.Repositories.Scheduling; +using Lumina.DataAccess.Core.UoW; +using Lumina.Domain.Common.Primitives; +using Microsoft.EntityFrameworkCore; +using System; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.DataAccess.Core.Repositories.Scheduling; + +/// +/// Repository for the display preferences of the scheduler page. +/// +internal sealed class SchedulerDisplayPreferencesRepository : ISchedulerDisplayPreferencesRepository +{ + private readonly LuminaDbContext _luminaDbContext; + + /// + /// Initializes a new instance of the class. + /// + /// Injected Entity Framework DbContext. + public SchedulerDisplayPreferencesRepository(LuminaDbContext luminaDbContext) + { + _luminaDbContext = luminaDbContext; + } + + /// + /// Gets the display preferences of the scheduler page of the user identified by , if they exist. + /// + /// The Id of the user whose display preferences are retrieved. + /// Cancellation token that can be used to stop the execution. + /// An containing either the display preferences of the user, or an error. + public async Task> GetByUserIdAsync(Guid userId, CancellationToken cancellationToken) + { + return await _luminaDbContext.SchedulerDisplayPreferences + .FirstOrDefaultAsync(preferences => preferences.UserId == userId, cancellationToken).ConfigureAwait(false); + } + + /// + /// Inserts the display preferences of the scheduler page of a user, or updates them when they already exist. + /// + /// The display preferences to insert or update. + /// Cancellation token that can be used to stop the execution. + /// An representing either a successful operation, or an error. + public async Task> UpsertAsync(SchedulerDisplayPreferencesEntity preferences, CancellationToken cancellationToken) + { + SchedulerDisplayPreferencesEntity? existingPreferences = await _luminaDbContext.SchedulerDisplayPreferences + .FirstOrDefaultAsync(repositoryPreferences => repositoryPreferences.UserId == preferences.UserId, cancellationToken).ConfigureAwait(false); + if (existingPreferences is null) + _luminaDbContext.SchedulerDisplayPreferences.Add(preferences); + else + { + // Update only the mutable fields, preserving the Id and the ownership of the existing preferences. + existingPreferences.JobTypeFilter = preferences.JobTypeFilter; + existingPreferences.DisplayTimeSpan = preferences.DisplayTimeSpan; + existingPreferences.DisplayTimeUnit = preferences.DisplayTimeUnit; + } + return Result.Updated; + } +} diff --git a/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs b/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs index 8808e722..eb1f811e 100644 --- a/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs +++ b/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs @@ -42,6 +42,7 @@ public class LuminaDbContext : DbContext public virtual DbSet BookContributors { get; set; } = null!; public virtual DbSet ScheduledJobs { get; set; } = null!; public virtual DbSet ScheduledJobExecutions { get; set; } = null!; + public virtual DbSet SchedulerDisplayPreferences { get; set; } = null!; /// /// Initializes a new instance of the class. diff --git a/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs b/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs index c03c82bb..e432f7be 100644 --- a/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs +++ b/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs @@ -48,6 +48,7 @@ public class UnitOfWork : IUnitOfWork, IDisposable private ILibraryBookReaderConfigurationRepository? _libraryBookReaderConfigurationRepository; private IScheduledJobRepository? _scheduledJobRepository; private IScheduledJobExecutionRepository? _scheduledJobExecutionRepository; + private ISchedulerDisplayPreferencesRepository? _schedulerDisplayPreferencesRepository; private IPluginRepository? _pluginRepository; private IThemeRepository? _themeRepository; private IUserRepository? _userRepository; @@ -242,6 +243,18 @@ public class UnitOfWork : IUnitOfWork, IDisposable } } + /// + /// Gets the scheduler display preferences repository. + /// + public ISchedulerDisplayPreferencesRepository SchedulerDisplayPreferencesRepository + { + get + { + _schedulerDisplayPreferencesRepository ??= new SchedulerDisplayPreferencesRepository(_luminaDbContext); + return _schedulerDisplayPreferencesRepository; + } + } + /// /// Gets the plugin repository. /// diff --git a/src/Lumina.Domain.SharedKernel/Common/Enums/Scheduling/SchedulerDisplayTimeUnit.cs b/src/Lumina.Domain.SharedKernel/Common/Enums/Scheduling/SchedulerDisplayTimeUnit.cs new file mode 100644 index 00000000..d23e525e --- /dev/null +++ b/src/Lumina.Domain.SharedKernel/Common/Enums/Scheduling/SchedulerDisplayTimeUnit.cs @@ -0,0 +1,22 @@ +namespace Lumina.Domain.SharedKernel.Common.Enums.Scheduling; + +/// +/// Enumeration for the units in which the display time span of the scheduler page is expressed. +/// +public enum SchedulerDisplayTimeUnit +{ + /// + /// The display time span is expressed in minutes. + /// + Minutes, + + /// + /// The display time span is expressed in hours. + /// + Hours, + + /// + /// The display time span is expressed in days. + /// + Days +} diff --git a/src/Lumina.Domain/Common/Errors/Errors.Scheduling.cs b/src/Lumina.Domain/Common/Errors/Errors.Scheduling.cs index 1f2c5723..e20fd6f6 100644 --- a/src/Lumina.Domain/Common/Errors/Errors.Scheduling.cs +++ b/src/Lumina.Domain/Common/Errors/Errors.Scheduling.cs @@ -24,5 +24,6 @@ public static partial class Errors public static Error ScheduledJobAlreadyRunning => Error.Forbidden(description: nameof(ScheduledJobAlreadyRunning)); public static Error CanOnlyCompleteRunningScheduledJob => Error.Forbidden(description: nameof(CanOnlyCompleteRunningScheduledJob)); public static Error InvalidScheduleType => Error.Validation(description: nameof(InvalidScheduleType)); + public static Error SchedulerDisplayTimeSpanMustBePositive => Error.Validation(description: nameof(SchedulerDisplayTimeSpanMustBePositive)); } } diff --git a/src/Lumina.Presentation.Api/Common/Routes/Scheduling/ApiRoutes.Scheduling.cs b/src/Lumina.Presentation.Api/Common/Routes/Scheduling/ApiRoutes.Scheduling.cs index cdd746cb..a57c13f9 100644 --- a/src/Lumina.Presentation.Api/Common/Routes/Scheduling/ApiRoutes.Scheduling.cs +++ b/src/Lumina.Presentation.Api/Common/Routes/Scheduling/ApiRoutes.Scheduling.cs @@ -14,5 +14,7 @@ public static partial class ApiRoutes public const string START_SCHEDULED_JOB = "/scheduled-jobs/{scheduledJobId}/start"; public const string STOP_SCHEDULED_JOB = "/scheduled-jobs/{scheduledJobId}/stop"; public const string FIRE_SCHEDULED_JOB = "/scheduled-jobs/{scheduledJobId}/fire"; + public const string GET_DISPLAY_PREFERENCES = "/scheduled-jobs/display-preferences"; + public const string UPDATE_DISPLAY_PREFERENCES = "/scheduled-jobs/display-preferences"; } } diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Scheduling/GetSchedulerDisplayPreferences/GetSchedulerDisplayPreferencesEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Scheduling/GetSchedulerDisplayPreferences/GetSchedulerDisplayPreferencesEndpoint.cs new file mode 100644 index 00000000..82b8cbd7 --- /dev/null +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Scheduling/GetSchedulerDisplayPreferences/GetSchedulerDisplayPreferencesEndpoint.cs @@ -0,0 +1,51 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.CQRS; +using Lumina.Application.Core.Scheduling.Queries.GetSchedulerDisplayPreferences; +using Lumina.Contracts.Responses.Scheduling; +using Lumina.Domain.Common.Primitives; +using Lumina.Presentation.Api.Common.Routes.Scheduling; +using Lumina.Presentation.Api.Core.Endpoints.Common; +using Microsoft.AspNetCore.Http; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Presentation.Api.Core.Endpoints.Scheduling.GetSchedulerDisplayPreferences; + +/// +/// API endpoint for the /scheduled-jobs/display-preferences route. +/// +public class GetSchedulerDisplayPreferencesEndpoint : BaseEndpoint +{ + private readonly IQueryHandler> _getSchedulerDisplayPreferencesQueryHandler; + + /// + /// Initializes a new instance of the class. + /// + /// Injected service for handling get scheduler display preferences queries. + public GetSchedulerDisplayPreferencesEndpoint(IQueryHandler> getSchedulerDisplayPreferencesQueryHandler) + { + _getSchedulerDisplayPreferencesQueryHandler = getSchedulerDisplayPreferencesQueryHandler; + } + + /// + /// Configures the API endpoint. + /// + public override void Configure() + { + Verbs(FastEndpoints.Http.GET); + Routes(ApiRoutes.ScheduledJobs.GET_DISPLAY_PREFERENCES); + Version(1); + DontCatchExceptions(); + } + + /// + /// Gets the display preferences of the scheduler page of the current user. + /// + /// Cancellation token that can be used to stop the execution. + public override async Task ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken) + { + Result result = await _getSchedulerDisplayPreferencesQueryHandler.HandleAsync(new GetSchedulerDisplayPreferencesQuery(), cancellationToken).ConfigureAwait(false); + return result.Match(success => TypedResults.Ok(success), Problem); + } +} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Scheduling/GetSchedulerDisplayPreferences/GetSchedulerDisplayPreferencesEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Scheduling/GetSchedulerDisplayPreferences/GetSchedulerDisplayPreferencesEndpointSummary.cs new file mode 100644 index 00000000..0bc5803c --- /dev/null +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Scheduling/GetSchedulerDisplayPreferences/GetSchedulerDisplayPreferencesEndpointSummary.cs @@ -0,0 +1,75 @@ +#region ========================================================================= USING ===================================================================================== +using FastEndpoints; +using Lumina.Contracts.Responses.Scheduling; +using Lumina.Domain.SharedKernel.Common.Enums.Scheduling; +using System; +using System.Diagnostics.CodeAnalysis; +#endregion + +namespace Lumina.Presentation.Api.Core.Endpoints.Scheduling.GetSchedulerDisplayPreferences; + +/// +/// Class used for providing a textual description for the API endpoint, for OpenAPI. +/// +[ExcludeFromCodeCoverage] +public class GetSchedulerDisplayPreferencesEndpointSummary : Summary +{ + /// + /// Initializes a new instance of the class. + /// + public GetSchedulerDisplayPreferencesEndpointSummary() + { + Summary = "Gets the display preferences of the scheduler page of the current user."; + Description = "Gets the display preferences of the scheduler page of the current user. When no display preferences are stored for the user yet, the default display preferences are returned. Only administrators can use the scheduler page."; + + Response(200, "The display preferences of the scheduler page of the current user are returned.", + example: new SchedulerDisplayPreferencesResponse( + UserId: Guid.NewGuid(), + JobTypeFilter: ScheduledTaskType.ScanMediaLibraries, + DisplayTimeSpan: 10, + DisplayTimeUnit: SchedulerDisplayTimeUnit.Minutes + )); + + Response(401, "Authentication required.", "application/problem+json", + example: new[] + { + new + { + type = "https://tools.ietf.org/html/rfc7235#section-3.1", + status = 401, + title = "Unauthorized", + detail = "You are not authorized", + instance = "/api/v1/scheduled-jobs/display-preferences" + }, + new + { + type = "https://tools.ietf.org/html/rfc7235#section-3.1", + status = 401, + title = "Unauthorized", + detail = "Invalid token: The token expired at '01/01/2024 01:00:00'", + instance = "/api/v1/scheduled-jobs/display-preferences" + }, + new + { + type = "https://tools.ietf.org/html/rfc7235#section-3.1", + status = 401, + title = "Unauthorized", + detail = "The token is invalid", + instance = "/api/v1/scheduled-jobs/display-preferences" + } + } + ); + + Response(403, "The request failed because the user making the request is not an administrator.", "application/problem+json", + example: new + { + type = "https://tools.ietf.org/html/rfc9110#section-15.5.4", + title = "General.Failure", + status = 403, + detail = "NotAuthorized", + instance = "/api/v1/scheduled-jobs/display-preferences", + traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00" + } + ); + } +} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Scheduling/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Scheduling/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesEndpoint.cs new file mode 100644 index 00000000..05b7323c --- /dev/null +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Scheduling/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesEndpoint.cs @@ -0,0 +1,53 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.CQRS; +using Lumina.Application.Common.Mapping.Scheduling; +using Lumina.Application.Core.Scheduling.Commands.UpdateSchedulerDisplayPreferences; +using Lumina.Contracts.Requests.Scheduling; +using Lumina.Domain.Common.Primitives; +using Lumina.Presentation.Api.Common.Routes.Scheduling; +using Lumina.Presentation.Api.Core.Endpoints.Common; +using Microsoft.AspNetCore.Http; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Presentation.Api.Core.Endpoints.Scheduling.UpdateSchedulerDisplayPreferences; + +/// +/// API endpoint for the /scheduled-jobs/display-preferences route. +/// +public class UpdateSchedulerDisplayPreferencesEndpoint : BaseEndpoint +{ + private readonly ICommandHandler> _updateSchedulerDisplayPreferencesCommandHandler; + + /// + /// Initializes a new instance of the class. + /// + /// Injected service for handling update scheduler display preferences commands. + public UpdateSchedulerDisplayPreferencesEndpoint(ICommandHandler> updateSchedulerDisplayPreferencesCommandHandler) + { + _updateSchedulerDisplayPreferencesCommandHandler = updateSchedulerDisplayPreferencesCommandHandler; + } + + /// + /// Configures the API endpoint. + /// + public override void Configure() + { + Verbs(FastEndpoints.Http.PUT); + Routes(ApiRoutes.ScheduledJobs.UPDATE_DISPLAY_PREFERENCES); + Version(1); + DontCatchExceptions(); + } + + /// + /// Updates the display preferences of the scheduler page of the current user. + /// + /// The request containing the display preferences of the scheduler page of the current user. + /// Cancellation token that can be used to stop the execution. + public override async Task ExecuteAsync(UpdateSchedulerDisplayPreferencesRequest request, CancellationToken cancellationToken) + { + Result result = await _updateSchedulerDisplayPreferencesCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false); + return result.Match(success => TypedResults.Ok(success), Problem); + } +} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Scheduling/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Scheduling/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesEndpointSummary.cs new file mode 100644 index 00000000..b3fdf077 --- /dev/null +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Scheduling/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesEndpointSummary.cs @@ -0,0 +1,100 @@ +#region ========================================================================= USING ===================================================================================== +using FastEndpoints; +using Lumina.Contracts.Requests.Scheduling; +using Lumina.Domain.SharedKernel.Common.Enums.Scheduling; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +#endregion + +namespace Lumina.Presentation.Api.Core.Endpoints.Scheduling.UpdateSchedulerDisplayPreferences; + +/// +/// Class used for providing a textual description for the API endpoint, for OpenAPI. +/// +[ExcludeFromCodeCoverage] +public class UpdateSchedulerDisplayPreferencesEndpointSummary : Summary +{ + /// + /// Initializes a new instance of the class. + /// + public UpdateSchedulerDisplayPreferencesEndpointSummary() + { + Summary = "Updates the display preferences of the scheduler page of the current user."; + Description = "Updates the display preferences of the scheduler page of the current user. Only administrators can use the scheduler page."; + + ExampleRequest = new UpdateSchedulerDisplayPreferencesRequest( + JobTypeFilter: ScheduledTaskType.ScanMediaLibraries, + DisplayTimeSpan: 10, + DisplayTimeUnit: SchedulerDisplayTimeUnit.Minutes + ); + + RequestParam(request => request.JobTypeFilter, "The type of the scheduled job tasks whose executions are shown on the scheduler page, or null when all of them are shown."); + RequestParam(request => request.DisplayTimeSpan, "The time span, expressed in the display time unit, that the scheduler page shows. Required."); + RequestParam(request => request.DisplayTimeUnit, "The unit in which the displayed time span of the scheduler page is expressed. Required."); + + Response(200, "The display preferences of the scheduler page of the current user were successfully updated."); + + Response(401, "Authentication required.", "application/problem+json", + example: new[] + { + new + { + type = "https://tools.ietf.org/html/rfc7235#section-3.1", + status = 401, + title = "Unauthorized", + detail = "You are not authorized", + instance = "/api/v1/scheduled-jobs/display-preferences" + }, + new + { + type = "https://tools.ietf.org/html/rfc7235#section-3.1", + status = 401, + title = "Unauthorized", + detail = "Invalid token: The token expired at '01/01/2024 01:00:00'", + instance = "/api/v1/scheduled-jobs/display-preferences" + }, + new + { + type = "https://tools.ietf.org/html/rfc7235#section-3.1", + status = 401, + title = "Unauthorized", + detail = "The token is invalid", + instance = "/api/v1/scheduled-jobs/display-preferences" + } + } + ); + + Response(403, "The request failed because the user making the request is not an administrator.", "application/problem+json", + example: new + { + type = "https://tools.ietf.org/html/rfc9110#section-15.5.4", + title = "General.Failure", + status = 403, + detail = "NotAuthorized", + instance = "/api/v1/scheduled-jobs/display-preferences", + traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00" + } + ); + + Response(422, "The request did not pass validation checks.", "application/problem+json", + example: new + { + type = "https://tools.ietf.org/html/rfc4918#section-11.2", + title = "General.Validation", + status = 422, + detail = "OneOrMoreValidationErrorsOccurred", + instance = "/api/v1/scheduled-jobs/display-preferences", + errors = new Dictionary + { + { + "General.Validation", new[] + { + "SchedulerDisplayTimeSpanMustBePositive" + } + } + }, + traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00" + } + ); + } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Scheduling/SchedulerDisplayPreferencesDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Scheduling/SchedulerDisplayPreferencesDto.cs new file mode 100644 index 00000000..cfc7e759 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Scheduling/SchedulerDisplayPreferencesDto.cs @@ -0,0 +1,22 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Scheduling; +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Scheduling; + +/// +/// Data transfer object for the display preferences of the scheduler page. +/// +/// The unique identifier of the user that owns the display preferences. +/// The type of the scheduled job tasks whose executions are shown on the scheduler page, or when all of them are shown. +/// The time span, expressed in , that the scheduler page shows. +/// The unit in which the displayed time span of the scheduler page is expressed. +[DebuggerDisplay("UserId: {UserId}, DisplayTimeSpan: {DisplayTimeSpan} {DisplayTimeUnit}")] +public record SchedulerDisplayPreferencesDto( + Guid UserId, + ScheduledTaskType? JobTypeFilter, + int DisplayTimeSpan, + SchedulerDisplayTimeUnit DisplayTimeUnit +); diff --git a/src/Lumina.Presentation.Web/Common/Enums/Scheduling/SchedulerDisplayTimeUnit.cs b/src/Lumina.Presentation.Web/Common/Enums/Scheduling/SchedulerDisplayTimeUnit.cs new file mode 100644 index 00000000..1c545952 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Enums/Scheduling/SchedulerDisplayTimeUnit.cs @@ -0,0 +1,22 @@ +namespace Lumina.Presentation.Web.Common.Enums.Scheduling; + +/// +/// Enumeration for the units in which the display time span of the scheduler page is expressed. +/// +public enum SchedulerDisplayTimeUnit +{ + /// + /// The display time span is expressed in minutes. + /// + Minutes, + + /// + /// The display time span is expressed in hours. + /// + Hours, + + /// + /// The display time span is expressed in days. + /// + Days +} diff --git a/src/Lumina.Presentation.Web/Common/Requests/Scheduling/UpdateSchedulerDisplayPreferencesRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Scheduling/UpdateSchedulerDisplayPreferencesRequest.cs new file mode 100644 index 00000000..bfae4a55 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Scheduling/UpdateSchedulerDisplayPreferencesRequest.cs @@ -0,0 +1,19 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Scheduling; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Scheduling; + +/// +/// Request for updating the display preferences of the scheduler page of the current user. +/// +/// The type of the scheduled job tasks whose executions are shown on the scheduler page, or when all of them are shown. +/// The time span, expressed in , that the scheduler page shows. Required. +/// The unit in which the displayed time span of the scheduler page is expressed. Required. +[DebuggerDisplay("DisplayTimeSpan: {DisplayTimeSpan} {DisplayTimeUnit}")] +public record UpdateSchedulerDisplayPreferencesRequest( + ScheduledTaskType? JobTypeFilter, + int DisplayTimeSpan, + SchedulerDisplayTimeUnit DisplayTimeUnit +); diff --git a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Scheduling.cs b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Scheduling.cs index 973de0a4..27b85cac 100644 --- a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Scheduling.cs +++ b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Scheduling.cs @@ -17,5 +17,7 @@ public static partial class ApiRoutes public const string START_SCHEDULED_JOB = "scheduled-jobs/{scheduledJobId}/start"; public const string STOP_SCHEDULED_JOB = "scheduled-jobs/{scheduledJobId}/stop"; public const string FIRE_SCHEDULED_JOB = "scheduled-jobs/{scheduledJobId}/fire"; + public const string GET_DISPLAY_PREFERENCES = "scheduled-jobs/display-preferences"; + public const string UPDATE_DISPLAY_PREFERENCES = "scheduled-jobs/display-preferences"; } } diff --git a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Scheduler.cs b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Scheduler.cs index f92e6ccb..c8694626 100644 --- a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Scheduler.cs +++ b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Scheduler.cs @@ -18,5 +18,7 @@ public static partial class WebRoutes public const string START_SCHEDULED_JOB = "{culture}/admin/api-scheduled-jobs/{scheduledJobId}/start"; public const string STOP_SCHEDULED_JOB = "{culture}/admin/api-scheduled-jobs/{scheduledJobId}/stop"; public const string FIRE_SCHEDULED_JOB = "{culture}/admin/api-scheduled-jobs/{scheduledJobId}/fire"; + public const string GET_DISPLAY_PREFERENCES = "{culture}/admin/api-scheduled-jobs/display-preferences"; + public const string UPDATE_DISPLAY_PREFERENCES = "{culture}/admin/api-scheduled-jobs/display-preferences"; } } diff --git a/src/Lumina.Presentation.Web/Core/Endpoints/Admin/Scheduler/GetSchedulerDisplayPreferences/GetSchedulerDisplayPreferencesEndpoint.cs b/src/Lumina.Presentation.Web/Core/Endpoints/Admin/Scheduler/GetSchedulerDisplayPreferences/GetSchedulerDisplayPreferencesEndpoint.cs new file mode 100644 index 00000000..2f8684fd --- /dev/null +++ b/src/Lumina.Presentation.Web/Core/Endpoints/Admin/Scheduler/GetSchedulerDisplayPreferences/GetSchedulerDisplayPreferencesEndpoint.cs @@ -0,0 +1,55 @@ +#region ========================================================================= USING ===================================================================================== +using FastEndpoints; +using Lumina.Presentation.Web.Common.Api; +using Lumina.Presentation.Web.Common.Authorization; +using Lumina.Presentation.Web.Common.DTO.Scheduling; +using Lumina.Presentation.Web.Common.Routes; +using Lumina.Presentation.Web.Core.Endpoints.Common; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Presentation.Web.Core.Endpoints.Admin.Scheduler.GetSchedulerDisplayPreferences; + +/// +/// API endpoint for the /{culture}/admin/api-scheduled-jobs/display-preferences route. +/// +public class GetSchedulerDisplayPreferencesEndpoint : BaseEndpoint +{ + private readonly IApiHttpClient _apiHttpClient; + + /// + /// Initializes a new instance of the class. + /// + /// Injected service for interactions with the API. + public GetSchedulerDisplayPreferencesEndpoint(IApiHttpClient apiHttpClient) + { + _apiHttpClient = apiHttpClient; + } + + /// + /// Configures the endpoint. + /// + public override void Configure() + { + base.Configure(); + Verbs(Http.GET); + Routes(WebRoutes.Scheduler.GET_DISPLAY_PREFERENCES); + DontAutoTag(); + Options(options => options.WithTags("Admin")); + Policies(AuthorizationPolicies.REQUIRE_ADMIN_ROLE); + } + + /// + /// Gets the display preferences of the scheduler page of the current user. + /// + /// The request object. + /// Cancellation token that can be used to stop the execution. + public override async Task ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken) + { + SchedulerDisplayPreferencesDto displayPreferences = await _apiHttpClient.GetAsync(ApiRoutes.ScheduledJobs.GET_DISPLAY_PREFERENCES, cancellationToken).ConfigureAwait(false); + return JsonSuccess(displayPreferences); + } +} diff --git a/src/Lumina.Presentation.Web/Core/Endpoints/Admin/Scheduler/GetSchedulerDisplayPreferences/GetSchedulerDisplayPreferencesEndpointSummary.cs b/src/Lumina.Presentation.Web/Core/Endpoints/Admin/Scheduler/GetSchedulerDisplayPreferences/GetSchedulerDisplayPreferencesEndpointSummary.cs new file mode 100644 index 00000000..5a4c38e9 --- /dev/null +++ b/src/Lumina.Presentation.Web/Core/Endpoints/Admin/Scheduler/GetSchedulerDisplayPreferences/GetSchedulerDisplayPreferencesEndpointSummary.cs @@ -0,0 +1,33 @@ +#region ========================================================================= USING ===================================================================================== +using FastEndpoints; +using Lumina.Presentation.Web.Common.DTO.Common; +using Lumina.Presentation.Web.Common.DTO.Scheduling; +using Lumina.Presentation.Web.Common.Enums.Scheduling; +using System; +using System.Diagnostics.CodeAnalysis; +#endregion + +namespace Lumina.Presentation.Web.Core.Endpoints.Admin.Scheduler.GetSchedulerDisplayPreferences; + +/// +/// Class used for providing a textual description for the endpoint, for OpenAPI. +/// +[ExcludeFromCodeCoverage] +public class GetSchedulerDisplayPreferencesEndpointSummary : Summary +{ + /// + /// Initializes a new instance of the class. + /// + public GetSchedulerDisplayPreferencesEndpointSummary() + { + Summary = "Gets the display preferences of the scheduler page."; + Description = "Retrieves the display preferences of the scheduler page of the current user, or the default display preferences when none are stored yet."; + + Response(200, "The display preferences of the scheduler page are returned.", example: new SuccessResponse(true, new SchedulerDisplayPreferencesDto( + UserId: Guid.NewGuid(), + JobTypeFilter: ScheduledTaskType.ScanMediaLibraries, + DisplayTimeSpan: 10, + DisplayTimeUnit: SchedulerDisplayTimeUnit.Minutes + ))); + } +} diff --git a/src/Lumina.Presentation.Web/Core/Endpoints/Admin/Scheduler/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesEndpoint.cs b/src/Lumina.Presentation.Web/Core/Endpoints/Admin/Scheduler/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesEndpoint.cs new file mode 100644 index 00000000..3898862a --- /dev/null +++ b/src/Lumina.Presentation.Web/Core/Endpoints/Admin/Scheduler/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesEndpoint.cs @@ -0,0 +1,55 @@ +#region ========================================================================= USING ===================================================================================== +using FastEndpoints; +using Lumina.Presentation.Web.Common.Api; +using Lumina.Presentation.Web.Common.Authorization; +using Lumina.Presentation.Web.Common.Requests.Scheduling; +using Lumina.Presentation.Web.Common.Routes; +using Lumina.Presentation.Web.Core.Endpoints.Common; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Presentation.Web.Core.Endpoints.Admin.Scheduler.UpdateSchedulerDisplayPreferences; + +/// +/// API endpoint for the /{culture}/admin/api-scheduled-jobs/display-preferences route. +/// +public class UpdateSchedulerDisplayPreferencesEndpoint : BaseEndpoint +{ + private readonly IApiHttpClient _apiHttpClient; + + /// + /// Initializes a new instance of the class. + /// + /// Injected service for interactions with the API. + public UpdateSchedulerDisplayPreferencesEndpoint(IApiHttpClient apiHttpClient) + { + _apiHttpClient = apiHttpClient; + } + + /// + /// Configures the endpoint. + /// + public override void Configure() + { + base.Configure(); + Verbs(Http.PUT); + Routes(WebRoutes.Scheduler.UPDATE_DISPLAY_PREFERENCES); + DontAutoTag(); + Options(options => options.WithTags("Admin")); + Policies(AuthorizationPolicies.REQUIRE_ADMIN_ROLE); + } + + /// + /// Updates the display preferences of the scheduler page of the current user. + /// + /// The request containing the display preferences of the scheduler page of the current user. + /// Cancellation token that can be used to stop the execution. + public override async Task ExecuteAsync(UpdateSchedulerDisplayPreferencesRequest request, CancellationToken cancellationToken) + { + await _apiHttpClient.PutAsync(ApiRoutes.ScheduledJobs.UPDATE_DISPLAY_PREFERENCES, request, cancellationToken).ConfigureAwait(false); + return JsonSuccess(); + } +} diff --git a/src/Lumina.Presentation.Web/Core/Endpoints/Admin/Scheduler/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesEndpointSummary.cs b/src/Lumina.Presentation.Web/Core/Endpoints/Admin/Scheduler/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesEndpointSummary.cs new file mode 100644 index 00000000..1a6e7038 --- /dev/null +++ b/src/Lumina.Presentation.Web/Core/Endpoints/Admin/Scheduler/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesEndpointSummary.cs @@ -0,0 +1,38 @@ +#region ========================================================================= USING ===================================================================================== +using FastEndpoints; +using Lumina.Presentation.Web.Common.DTO.Common; +using Lumina.Presentation.Web.Common.Enums.Scheduling; +using Lumina.Presentation.Web.Common.Requests.Scheduling; +using System; +using System.Diagnostics.CodeAnalysis; +#endregion + +namespace Lumina.Presentation.Web.Core.Endpoints.Admin.Scheduler.UpdateSchedulerDisplayPreferences; + +/// +/// Class used for providing a textual description for the endpoint, for OpenAPI. +/// +[ExcludeFromCodeCoverage] +public class UpdateSchedulerDisplayPreferencesEndpointSummary : Summary +{ + /// + /// Initializes a new instance of the class. + /// + public UpdateSchedulerDisplayPreferencesEndpointSummary() + { + Summary = "Updates the display preferences of the scheduler page."; + Description = "Stores the display preferences of the scheduler page of the current user, so that they are restored on every client the user signs in from."; + + RequestParam(r => r.JobTypeFilter, "The type of the scheduled job tasks whose executions are shown on the scheduler page, or null when all of them are shown."); + RequestParam(r => r.DisplayTimeSpan, "The time span, expressed in the display time unit, that the scheduler page shows. Required."); + RequestParam(r => r.DisplayTimeUnit, "The unit in which the displayed time span of the scheduler page is expressed. Required."); + + ExampleRequest = new UpdateSchedulerDisplayPreferencesRequest( + JobTypeFilter: ScheduledTaskType.ScanMediaLibraries, + DisplayTimeSpan: 10, + DisplayTimeUnit: SchedulerDisplayTimeUnit.Minutes + ); + + Response(200, "The display preferences of the scheduler page were successfully updated.", example: new SuccessResponse(true)); + } +} diff --git a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.ar-SA.resx b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.ar-SA.resx index 2ee6bd43..d97d0d13 100644 --- a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.ar-SA.resx +++ b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.ar-SA.resx @@ -757,7 +757,7 @@ المهمة المجدولة بهذا الاسم موجودة بالفعل! - The execution of the scheduled job already exists! + تنفيذ المهمة المجدولة موجود بالفعل! لم يتم العثور على تنفيذ المهمة المجدولة! @@ -774,6 +774,9 @@ يمكن إكمال المهمة المجدولة قيد التشغيل فقط! + + يجب أن تكون الفترة الزمنية للعرض في صفحة الجدولة رقمًا موجبًا! + نوع الجدول غير صالح! diff --git a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.de-DE.resx b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.de-DE.resx index 72749401..8f3f3fb6 100644 --- a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.de-DE.resx +++ b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.de-DE.resx @@ -757,7 +757,7 @@ Ein geplanter Auftrag mit diesem Namen ist bereits vorhanden! - The execution of the scheduled job already exists! + Die Ausführung des geplanten Auftrags existiert bereits! Die Ausführung des geplanten Auftrags wurde nicht gefunden! @@ -774,6 +774,9 @@ Nur ein laufender geplanter Auftrag kann abgeschlossen werden! + + Der Anzeigezeitraum der Scheduler-Seite muss eine positive Zahl sein! + Der Zeitplantyp ist ungültig! diff --git a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.en-US.resx b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.en-US.resx index 6e2ec0e2..326d2996 100644 --- a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.en-US.resx +++ b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.en-US.resx @@ -774,6 +774,9 @@ Only a running scheduled job can be completed! + + The display time span of the scheduler page must be a positive number! + The schedule type is invalid! diff --git a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.es-ES.resx b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.es-ES.resx index f6fe91c0..a6e0c2e8 100644 --- a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.es-ES.resx +++ b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.es-ES.resx @@ -757,7 +757,7 @@ Ya existe una tarea programada con este nombre! - The execution of the scheduled job already exists! + La ejecución de la tarea programada ya existe! No se encontró la ejecución de la tarea programada! @@ -774,6 +774,9 @@ Solo se puede completar una tarea programada en ejecución! + + El intervalo de visualización de la página de tareas programadas debe ser un número positivo! + El tipo de programación no es válido! diff --git a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.fr-FR.resx b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.fr-FR.resx index b20c58cc..734e8420 100644 --- a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.fr-FR.resx +++ b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.fr-FR.resx @@ -757,7 +757,7 @@ Un travail planifié portant ce nom existe déjà ! - The execution of the scheduled job already exists! + L'exécution du travail planifié existe déjà ! L'exécution du travail planifié est introuvable ! @@ -774,6 +774,9 @@ Seul un travail planifié en cours d'exécution peut être terminé ! + + La durée d'affichage de la page des travaux planifiés doit être un nombre positif ! + Le type de planification n'est pas valide ! diff --git a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.it-IT.resx b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.it-IT.resx index 784da52e..d29f703f 100644 --- a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.it-IT.resx +++ b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.it-IT.resx @@ -757,7 +757,7 @@ Esiste già un processo pianificato con questo nome! - The execution of the scheduled job already exists! + L'esecuzione del processo pianificato esiste già! L'esecuzione del processo pianificato non è stata trovata! @@ -774,6 +774,9 @@ Solo un processo pianificato in esecuzione può essere completato! + + L'intervallo di visualizzazione della pagina dei processi pianificati deve essere un numero positivo! + Il tipo di pianificazione non è valido! diff --git a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.ja-JP.resx b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.ja-JP.resx index 99305b2a..811c5865 100644 --- a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.ja-JP.resx +++ b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.ja-JP.resx @@ -757,7 +757,7 @@ この名前のスケジュールされたジョブは既に存在します! - The execution of the scheduled job already exists! + スケジュールされたジョブの実行は既に存在します! スケジュールされたジョブの実行が見つかりません! @@ -774,6 +774,9 @@ 実行中のスケジュールされたジョブのみ完了できます! + + スケジューラーページの表示期間は正の数である必要があります! + スケジュールタイプが無効です! diff --git a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.resx b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.resx index 6170f941..7dc35049 100644 --- a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.resx +++ b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.resx @@ -774,6 +774,9 @@ Only a running scheduled job can be completed! + + The display time span of the scheduler page must be a positive number! + The schedule type is invalid! diff --git a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.ro-RO.resx b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.ro-RO.resx index e1e005a5..c4dd1bc3 100644 --- a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.ro-RO.resx +++ b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.ro-RO.resx @@ -757,7 +757,7 @@ Există deja un job programat cu acest nume! - The execution of the scheduled job already exists! + Execuția jobului programat există deja! Execuția jobului programat nu a fost găsită! @@ -774,6 +774,9 @@ Doar un job programat în execuție poate fi finalizat! + + Durata de afișare a paginii joburilor programate trebuie să fie un număr pozitiv! + Tipul de programare este invalid! diff --git a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.uk-UA.resx b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.uk-UA.resx index a113f2de..20b6d57d 100644 --- a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.uk-UA.resx +++ b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.uk-UA.resx @@ -757,7 +757,7 @@ Плановане завдання з таким ім'ям вже існує! - The execution of the scheduled job already exists! + Виконання планованого завдання вже існує! Виконання планованого завдання не знайдено! @@ -774,6 +774,9 @@ Завершити можна лише плановане завдання, що виконується! + + Період відображення сторінки планувальника має бути додатним числом! + Тип розкладу недійсний! diff --git a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.zh-CN.resx b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.zh-CN.resx index b1a3d522..818ffca4 100644 --- a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.zh-CN.resx +++ b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.zh-CN.resx @@ -757,7 +757,7 @@ 已存在同名计划任务! - The execution of the scheduled job already exists! + 计划任务的执行记录已存在! 未找到计划任务的执行记录! @@ -774,6 +774,9 @@ 只有运行中的计划任务才能完成! + + 计划任务页面的显示时长必须是正数! + 调度类型无效! diff --git a/src/Lumina.Presentation.Web/Core/Views/Admin/Scheduler.cshtml b/src/Lumina.Presentation.Web/Core/Views/Admin/Scheduler.cshtml index 29ede005..86ec8bea 100644 --- a/src/Lumina.Presentation.Web/Core/Views/Admin/Scheduler.cshtml +++ b/src/Lumina.Presentation.Web/Core/Views/Admin/Scheduler.cshtml @@ -214,6 +214,8 @@ const removeJobUrlTemplate = '@_urlService.GetAbsoluteUrl(WebRoutes.Scheduler.REMOVE_SCHEDULED_JOB, new { scheduledJobId = default(Guid) })'; const accessTokenUrl = '@_urlService.GetAbsoluteUrl(WebRoutes.Authentication.GET_API_ACCESS_TOKEN)'; const schedulerHubUrl = '@scheduledJobsHubUrl'; + const getDisplayPreferencesUrl = '@_urlService.GetAbsoluteUrl(WebRoutes.Scheduler.GET_DISPLAY_PREFERENCES)'; + const updateDisplayPreferencesUrl = '@_urlService.GetAbsoluteUrl(WebRoutes.Scheduler.UPDATE_DISPLAY_PREFERENCES)'; function getComboboxValue(combobox) { const selected = combobox.querySelector('.enlightenment-selected-text'); @@ -238,26 +240,33 @@ return () => combobox.removeEventListener('click', handler); } - // Persists the display preferences of the scheduler page (the job type filter, the time span and its unit) in the - // browser, so that they are restored when the page is reloaded, and the graph and the jobs list respect them. - const schedulerSettingsKey = 'luminaSchedulerSettings'; - - function readSchedulerSettings() { - try { - const storedSettings = localStorage.getItem(schedulerSettingsKey); - return storedSettings ? JSON.parse(storedSettings) : {}; - } catch (error) { - console.error('Failed to read the scheduler settings:', error); - return {}; - } + // Reads the display preferences of the scheduler page from its controls, as the payload sent to the update endpoint. + function getDisplayPreferencesPayload() { + const selectedJobType = getComboboxValue(jobTypeFilter) || 'All'; + return { + jobTypeFilter: selectedJobType === 'All' ? null : selectedJobType, + displayTimeSpan: Number(timespanInput.value), + displayTimeUnit: getComboboxValue(timeunitSelect) + }; } - function writeSchedulerSettings(settings) { - try { - localStorage.setItem(schedulerSettingsKey, JSON.stringify(settings)); - } catch (error) { - console.error('Failed to store the scheduler settings:', error); - } + // Persists the display preferences of the scheduler page (the job type filter, the time span and its unit) on the + // server, so that they are shared by every client the current user signs in from, not only by the browser that changed them. + async function persistDisplayPreferences() { + await callApiPutAsync(updateDisplayPreferencesUrl, getDisplayPreferencesPayload()); + } + + // Loads the display preferences of the current user from the server, and applies them to the controls, before the graph and + // the jobs list are loaded; the server returns the default display preferences when none are stored for the user yet. + async function applyDisplayPreferences() { + const displayPreferences = await callApiGetAsync(getDisplayPreferencesUrl); + if (!displayPreferences) + return; + setComboboxValue(jobTypeFilter, displayPreferences.jobTypeFilter || 'All'); + setComboboxValue(timeunitSelect, displayPreferences.displayTimeUnit || 'Minutes'); + const storedTimeSpan = Number(displayPreferences.displayTimeSpan); + if (Number.isFinite(storedTimeSpan) && storedTimeSpan >= 1) + timespanInput.value = storedTimeSpan; } function setComboboxValue(combobox, value) { @@ -271,27 +280,6 @@ } } - function persistDisplayPreferences() { - const settings = { - jobType: getComboboxValue(jobTypeFilter) || 'All', - timespan: timespanInput.value, - timeUnit: getComboboxValue(timeunitSelect) - }; - writeSchedulerSettings(settings); - } - - // Restores the stored display preferences on the controls, before the graph and the jobs list are loaded. - function applyDisplayPreferences() { - const settings = readSchedulerSettings(); - if (settings.jobType) - setComboboxValue(jobTypeFilter, settings.jobType); - if (settings.timeUnit) - setComboboxValue(timeunitSelect, settings.timeUnit); - const storedTimespan = Number(settings.timespan); - if (Number.isFinite(storedTimespan) && storedTimespan >= 1) - timespanInput.value = storedTimespan; - } - // Graph state. const taskTypeOrder = ['ScanMediaLibraries', 'CleanTemporaryFiles']; const graphState = { @@ -640,7 +628,7 @@ async function updateTimeSpanAsync() { adjustTimeScale(); graphState.dataPoints = []; - persistDisplayPreferences(); + await persistDisplayPreferences(); await loadHistoryAsync(); } @@ -744,7 +732,7 @@ //+----------------------------------------------------------------------------------------+ async function initialize() { - applyDisplayPreferences(); + await applyDisplayPreferences(); renderLegend(); graphState.startTime = new Date(); graphState.startTime.setMinutes(0, 0, 0); @@ -767,16 +755,19 @@ toggleScheduleFields(); // Persist the display preferences when they change, and reload the history when the job type filter changes, - // so that the graph and the jobs list always respect the selected filter. - const handleJobTypeFilterChange = () => { - persistDisplayPreferences(); + // so that the graph and the jobs list always respect the selected filter, on every client of the current user. + const handleJobTypeFilterChange = async () => { renderJobsTable(); - updateTimeSpanAsync(); + await updateTimeSpanAsync(); }; const unbindJobTypeFilterChange = bindComboboxChange(jobTypeFilter, handleJobTypeFilterChange); - const unbindTimeUnitChange = bindComboboxChange(timeunitSelect, persistDisplayPreferences); - const handleTimespanChange = () => persistDisplayPreferences(); - timespanInput.addEventListener('input', handleTimespanChange); + const handleTimeUnitChange = async () => { + await persistDisplayPreferences(); + }; + const unbindTimeUnitChange = bindComboboxChange(timeunitSelect, handleTimeUnitChange); + const handleTimespanChange = async () => { + await persistDisplayPreferences(); + }; timespanInput.addEventListener('change', handleTimespanChange); updateTimespanButton.addEventListener('click', updateTimeSpanAsync); addJobButton.addEventListener('click', addJobAsync); @@ -790,7 +781,6 @@ unbindScheduleTypeChange(); unbindJobTypeFilterChange(); unbindTimeUnitChange(); - timespanInput.removeEventListener('input', handleTimespanChange); timespanInput.removeEventListener('change', handleTimespanChange); updateTimespanButton.removeEventListener('click', updateTimeSpanAsync); addJobButton.removeEventListener('click', addJobAsync);