mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18:21:10 +00:00
Stores scheduler page display preferences per user
This commit is contained in:
1 parent
ab8ab51397
commit
237be9e2c8
50 files changed
+3144
-60
No files matched your search
+51
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/scheduled-jobs/display-preferences</c> route.
|
||||
/// </summary>
|
||||
public class GetSchedulerDisplayPreferencesEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetSchedulerDisplayPreferencesQuery, Result<SchedulerDisplayPreferencesResponse>> _getSchedulerDisplayPreferencesQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetSchedulerDisplayPreferencesEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getSchedulerDisplayPreferencesQueryHandler">Injected service for handling get scheduler display preferences queries.</param>
|
||||
public GetSchedulerDisplayPreferencesEndpoint(IQueryHandler<GetSchedulerDisplayPreferencesQuery, Result<SchedulerDisplayPreferencesResponse>> getSchedulerDisplayPreferencesQueryHandler)
|
||||
{
|
||||
_getSchedulerDisplayPreferencesQueryHandler = getSchedulerDisplayPreferencesQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.GET);
|
||||
Routes(ApiRoutes.ScheduledJobs.GET_DISPLAY_PREFERENCES);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the display preferences of the scheduler page of the current user.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<SchedulerDisplayPreferencesResponse> result = await _getSchedulerDisplayPreferencesQueryHandler.HandleAsync(new GetSchedulerDisplayPreferencesQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+75
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetSchedulerDisplayPreferencesEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetSchedulerDisplayPreferencesEndpointSummary : Summary<GetSchedulerDisplayPreferencesEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetSchedulerDisplayPreferencesEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
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"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+53
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/scheduled-jobs/display-preferences</c> route.
|
||||
/// </summary>
|
||||
public class UpdateSchedulerDisplayPreferencesEndpoint : BaseEndpoint<UpdateSchedulerDisplayPreferencesRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<UpdateSchedulerDisplayPreferencesCommand, Result<Updated>> _updateSchedulerDisplayPreferencesCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateSchedulerDisplayPreferencesEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="updateSchedulerDisplayPreferencesCommandHandler">Injected service for handling update scheduler display preferences commands.</param>
|
||||
public UpdateSchedulerDisplayPreferencesEndpoint(ICommandHandler<UpdateSchedulerDisplayPreferencesCommand, Result<Updated>> updateSchedulerDisplayPreferencesCommandHandler)
|
||||
{
|
||||
_updateSchedulerDisplayPreferencesCommandHandler = updateSchedulerDisplayPreferencesCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.PUT);
|
||||
Routes(ApiRoutes.ScheduledJobs.UPDATE_DISPLAY_PREFERENCES);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the display preferences of the scheduler page of the current user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the display preferences of the scheduler page of the current user.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(UpdateSchedulerDisplayPreferencesRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<Updated> result = await _updateSchedulerDisplayPreferencesCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+100
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="UpdateSchedulerDisplayPreferencesEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateSchedulerDisplayPreferencesEndpointSummary : Summary<UpdateSchedulerDisplayPreferencesEndpoint, UpdateSchedulerDisplayPreferencesRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateSchedulerDisplayPreferencesEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
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<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"SchedulerDisplayTimeSpanMustBePositive"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user