mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 21:01:10 +00:00
Adds missing controller modifications
This commit is contained in:
1 parent
1a1383a7f6
commit
cf567bd094
4 files changed
+16
-13
No files matched your search
+4
-2
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
@@ -15,11 +16,12 @@ public static class AddMediaLibraryRequestMapping
|
||||
/// Converts <paramref name="request"/> to <see cref="AddLibraryCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <param name="userId">The Id of the user owning the media library. Required.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static AddLibraryCommand ToCommand(this AddLibraryRequest request)
|
||||
public static AddLibraryCommand ToCommand(this AddLibraryRequest request, Guid userId)
|
||||
{
|
||||
return new AddLibraryCommand(
|
||||
request.UserId,
|
||||
userId,
|
||||
request.Title,
|
||||
request.LibraryType,
|
||||
request.ContentLocations
|
||||
|
||||
+4
-1
@@ -8,6 +8,8 @@ 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
|
||||
@@ -48,7 +50,8 @@ public class AddLibraryEndpoint : BaseEndpoint<AddLibraryRequest, IResult>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(AddLibraryRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<LibraryResponse> result = await _sender.Send(request.ToCommand(), cancellationToken).ConfigureAwait(false);
|
||||
string? user = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
ErrorOr<LibraryResponse> result = await _sender.Send(request.ToCommand(Guid.Parse(user!)), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Created($"{BaseURL}api/v1{ApiRoutes.Libraries.ADD_LIBRARY}/{result.Value.Id}", result.Value), Problem);
|
||||
}
|
||||
}
|
||||
-2
@@ -27,7 +27,6 @@ public class AddLibraryEndpointSummary : Summary<AddLibraryEndpoint, AddLibraryR
|
||||
Description = "Creates a new media library and returns its details, including the location of the newly created resource.";
|
||||
|
||||
ExampleRequest = new AddLibraryRequest(
|
||||
UserId: Guid.NewGuid(),
|
||||
Title: "TV Shows",
|
||||
LibraryType: LibraryType.TvShow,
|
||||
ContentLocations: [
|
||||
@@ -36,7 +35,6 @@ public class AddLibraryEndpointSummary : Summary<AddLibraryEndpoint, AddLibraryR
|
||||
]
|
||||
);
|
||||
|
||||
RequestParam(r => r.UserId, "The Id of the user owning the media library. Required.");
|
||||
RequestParam(r => r.Title, "The title of the media library. Required.");
|
||||
RequestParam(r => r.LibraryType, "The type of the media library. Required.");
|
||||
RequestParam(r => r.ContentLocations, ">The file system paths of the directories where the media library elements are located. Required.");
|
||||
|
||||
+8
-8
@@ -20,19 +20,19 @@ public class AddMediaLibraryRequestMappingTests
|
||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
AddLibraryRequest request = new(
|
||||
Guid.NewGuid(),
|
||||
"My Library",
|
||||
LibraryType.Book,
|
||||
["C:/Books", "D:/Media/Books"]
|
||||
);
|
||||
|
||||
// Act
|
||||
AddLibraryCommand result = request.ToCommand();
|
||||
AddLibraryCommand result = request.ToCommand(userId);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.UserId.Should().Be(request.UserId);
|
||||
result.UserId.Should().Be(userId);
|
||||
result.Title.Should().Be(request.Title);
|
||||
result.LibraryType.Should().Be(request.LibraryType);
|
||||
result.ContentLocations.Should().BeEquivalentTo(request.ContentLocations);
|
||||
@@ -46,19 +46,19 @@ public class AddMediaLibraryRequestMappingTests
|
||||
public void ToCommand_WhenMappingDifferentLibraryTypes_ShouldMapCorrectly(LibraryType libraryType)
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
AddLibraryRequest request = new(
|
||||
Guid.NewGuid(),
|
||||
"My Library",
|
||||
libraryType,
|
||||
["C:/Media"]
|
||||
);
|
||||
|
||||
// Act
|
||||
AddLibraryCommand result = request.ToCommand();
|
||||
AddLibraryCommand result = request.ToCommand(userId);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.UserId.Should().Be(request.UserId);
|
||||
result.UserId.Should().Be(userId);
|
||||
result.Title.Should().Be(request.Title);
|
||||
result.LibraryType.Should().Be(libraryType);
|
||||
result.ContentLocations.Should().BeEquivalentTo(request.ContentLocations);
|
||||
@@ -76,15 +76,15 @@ public class AddMediaLibraryRequestMappingTests
|
||||
"F:/Reading Material"
|
||||
];
|
||||
|
||||
Guid userId = Guid.NewGuid();
|
||||
AddLibraryRequest request = new(
|
||||
Guid.NewGuid(),
|
||||
"My Library",
|
||||
LibraryType.Book,
|
||||
contentLocations
|
||||
);
|
||||
|
||||
// Act
|
||||
AddLibraryCommand result = request.ToCommand();
|
||||
AddLibraryCommand result = request.ToCommand(userId);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
|
||||
Reference in new issue
Block a user