mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Adds media libraries management view
This commit is contained in:
1 parent
b593cbce93
commit
d7c8478101
162 files changed
+3741
-171
No files matched your search
@@ -13,7 +13,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.Common.Middlewares;
|
||||
|
||||
/// <summary>
|
||||
/// Middleware that ensures eventual consistency by handling domain events and publishing them after the request has completed successfully.
|
||||
/// Middleware that ensures eventual consistency by handling domain events and publishing them after the request has completed successfuly.
|
||||
/// </summary>
|
||||
public class EventualConsistencyMiddleware
|
||||
{
|
||||
@@ -24,6 +24,7 @@ public class EventualConsistencyMiddleware
|
||||
/// Initializes a new instance of the <see cref="EventualConsistencyMiddleware"/> class.
|
||||
/// </summary>
|
||||
/// <param name="next">The next middleware in the HTTP request pipeline.</param>
|
||||
/// <param name="logger">Injected service for logging.</param>
|
||||
public EventualConsistencyMiddleware(RequestDelegate next, ILogger<EventualConsistencyMiddleware> logger)
|
||||
{
|
||||
_next = next;
|
||||
|
||||
@@ -14,5 +14,6 @@ public static partial class ApiRoutes
|
||||
public const string GET_LIBRARIES = "/libraries";
|
||||
public const string ADD_LIBRARY = "/libraries";
|
||||
public const string UPDATE_LIBRARY = "/libraries/{id}";
|
||||
public const string DELETE_LIBRARY = "/libraries/{id}";
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -40,7 +40,7 @@ public class AddRoleEndpointSummary : Summary<AddRoleEndpoint, AddRoleRequest>
|
||||
ResponseParam<RolePermissionsResponse>(r => r.Permissions, "The list of permissions of the role entity.");
|
||||
|
||||
|
||||
Response(200, "The authorization role was successfully created.", example:
|
||||
Response(200, "The authorization role was successfuly created.", example:
|
||||
new RolePermissionsResponse(
|
||||
Role: new RoleDto(Id: Guid.NewGuid(), "Editor"),
|
||||
Permissions: [new PermissionDto(Guid.NewGuid(), AuthorizationPermission.CanDeleteUsers), new PermissionDto(Guid.NewGuid(), AuthorizationPermission.CanViewUsers)]
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ public class DeleteRoleEndpointSummary : Summary<DeleteRoleEndpoint, DeleteRoleR
|
||||
|
||||
RequestParam(r => r.RoleId, "The Id of the role. Required.");
|
||||
|
||||
Response(204, "The authorization role was successfully deleted.");
|
||||
Response(204, "The authorization role was successfuly deleted.");
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new[]
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ public class UpdateRoleEndpointSummary : Summary<UpdateRoleEndpoint, UpdateRoleR
|
||||
ResponseParam<RolePermissionsResponse>(r => r.Permissions, "The list of permissions of the role entity.");
|
||||
|
||||
|
||||
Response(200, "The authorization role was successfully updated.", example:
|
||||
Response(200, "The authorization role was successfuly updated.", example:
|
||||
new RolePermissionsResponse(
|
||||
Role: new RoleDto(Id: Guid.NewGuid(), "Editor"),
|
||||
Permissions: [new PermissionDto(Guid.NewGuid(), AuthorizationPermission.CanDeleteUsers), new PermissionDto(Guid.NewGuid(), AuthorizationPermission.CanViewUsers)]
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ public class SplitPathEndpointSummary : Summary<SplitPathEndpoint, SplitPathRequ
|
||||
|
||||
RequestParam(r => r.Path, "The file system path for which to get the path segments. Required.");
|
||||
|
||||
Response(200, "Successfully split the path into segments.",
|
||||
Response(200, "successfuly split the path into segments.",
|
||||
example: new PathSegmentResponse[2] {
|
||||
new(Path: "media"),
|
||||
new(Path: "movies")
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ public class AddLibraryEndpointSummary : Summary<AddLibraryEndpoint, AddLibraryR
|
||||
ResponseParam<LibraryResponse>(r => r.UpdatedOnUtc, "The date and time when the entity was last updated.");
|
||||
|
||||
|
||||
Response(201, "The media library was successfully created.", example:
|
||||
Response(201, "The media library was successfuly created.", example:
|
||||
new LibraryResponse(
|
||||
Id: Guid.NewGuid(),
|
||||
UserId: Guid.NewGuid(),
|
||||
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using Lumina.Presentation.Api.Common.Routes.Library.Management;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.Management.DeleteLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>//libraries/{id}</c> route.
|
||||
/// </summary>
|
||||
public class DeleteLibraryEndpoint : BaseEndpoint<DeleteLibraryRequest, IResult>
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteLibraryEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="sender">Injected service for mediating commands and queries.</param>
|
||||
public DeleteLibraryEndpoint(ISender sender)
|
||||
{
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.DELETE);
|
||||
Routes(ApiRoutes.Libraries.DELETE_LIBRARY);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a library by Id.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the id of the library to be deleted.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(DeleteLibraryRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<Deleted> result = await _sender.Send(request.ToCommand(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibraries;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Presentation.Api.Common.Routes.Library.Management;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.Management.GetLibraries;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/libraries</c> route.
|
||||
/// </summary>
|
||||
public class GetLibrariesEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetLibrariesEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="sender">Injected service for mediating commands and queries.</param>
|
||||
public GetLibrariesEndpoint(ISender sender)
|
||||
{
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Libraries.GET_LIBRARIES);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of libraries.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the id of the library to be retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest _, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<LibraryResponse[]> result = await _sender.Send(new GetLibrariesQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.Management.GetLibraries;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetLibrariesEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetLibrariesEndpointSummary : Summary<GetLibrariesEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetLibrariesEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetLibrariesEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the list of media libraries.";
|
||||
Description = "Retrieves the entire list of media libraries, if the user making the request is an Admin, or just the library owned by them, for regular users.";
|
||||
|
||||
Response(200, "The media libraries are returned.",
|
||||
example: new LibraryResponse[] {
|
||||
new (
|
||||
Id: Guid.NewGuid(),
|
||||
UserId: Guid.NewGuid(),
|
||||
Title: "TV Shows",
|
||||
LibraryType: LibraryType.TvShow,
|
||||
ContentLocations: ["/media/tv shows/drama/", "/media/tv shows/SCI-FI/"],
|
||||
CoverImage: "/media/myTvShowPoster.jpg",
|
||||
CreatedOnUtc: DateTime.UtcNow,
|
||||
UpdatedOnUtc: default
|
||||
),
|
||||
new (
|
||||
Id: Guid.NewGuid(),
|
||||
UserId: Guid.NewGuid(),
|
||||
Title: "Movies",
|
||||
LibraryType: LibraryType.TvShow,
|
||||
ContentLocations: ["/media/movies/"],
|
||||
CoverImage: "/media/myMoviePoster.jpg",
|
||||
CreatedOnUtc: DateTime.UtcNow,
|
||||
UpdatedOnUtc: default
|
||||
)
|
||||
});
|
||||
|
||||
|
||||
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/libraries"
|
||||
},
|
||||
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/libraries"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/libraries"
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+1
-5
@@ -8,8 +8,6 @@ using Lumina.Presentation.Api.Common.Routes.Library.Management;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Security.Claims;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
@@ -50,9 +48,7 @@ public class GetLibraryEndpoint : BaseEndpoint<GetLibraryRequest, IResult>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetLibraryRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// retrieve the currently authenticated user, and send it with the request
|
||||
string? user = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
ErrorOr<LibraryResponse> result = await _sender.Send(request.ToQuery(Guid.Parse(user!)), cancellationToken).ConfigureAwait(false);
|
||||
ErrorOr<LibraryResponse> result = await _sender.Send(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -53,7 +53,7 @@ public class UpdateLibraryEndpointSummary : Summary<UpdateLibraryEndpoint, Updat
|
||||
ResponseParam<LibraryResponse>(r => r.UpdatedOnUtc, "The date and time when the entity was last updated.");
|
||||
|
||||
|
||||
Response(200, "The media library was successfully updated.", example:
|
||||
Response(200, "The media library was successfuly updated.", example:
|
||||
new LibraryResponse(
|
||||
Id: Guid.NewGuid(),
|
||||
UserId: Guid.NewGuid(),
|
||||
|
||||
-1
@@ -265,6 +265,5 @@ public class GetBooksEndpointSummary : Summary<GetBooksEndpoint>
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -43,7 +43,7 @@ public class UpdateUserRoleAndPermissionsEndpointSummary : Summary<UpdateUserRol
|
||||
ResponseParam<AuthorizationResponse>(r => r.Permissions, "The list of permissions of the user.");
|
||||
|
||||
|
||||
Response(200, "The authorization role and permissions of the user were successfully updated.", example:
|
||||
Response(200, "The authorization role and permissions of the user were successfuly updated.", example:
|
||||
new AuthorizationResponse(
|
||||
UserId: Guid.NewGuid(),
|
||||
Role: "Editor",
|
||||
|
||||
Reference in new issue
Block a user