Adds missing controller modifications

This commit is contained in:
BinaryAlley committed 2024-11-16 21:58:13 +02:00
1 parent 1a1383a7f6
commit cf567bd094
4 files changed
+16 -13

No files matched your search

@@ -2,6 +2,7 @@
using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary; using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook; using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
using Lumina.Contracts.Requests.MediaLibrary.Management; using Lumina.Contracts.Requests.MediaLibrary.Management;
using System;
#endregion #endregion
namespace Lumina.Application.Common.Mapping.MediaLibrary.Management; namespace Lumina.Application.Common.Mapping.MediaLibrary.Management;
@@ -15,11 +16,12 @@ public static class AddMediaLibraryRequestMapping
/// Converts <paramref name="request"/> to <see cref="AddLibraryCommand"/>. /// Converts <paramref name="request"/> to <see cref="AddLibraryCommand"/>.
/// </summary> /// </summary>
/// <param name="request">The request to be converted.</param> /// <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> /// <returns>The converted command.</returns>
public static AddLibraryCommand ToCommand(this AddLibraryRequest request) public static AddLibraryCommand ToCommand(this AddLibraryRequest request, Guid userId)
{ {
return new AddLibraryCommand( return new AddLibraryCommand(
request.UserId, userId,
request.Title, request.Title,
request.LibraryType, request.LibraryType,
request.ContentLocations request.ContentLocations
@@ -8,6 +8,8 @@ using Lumina.Presentation.Api.Common.Routes.Library.Management;
using Lumina.Presentation.Api.Core.Endpoints.Common; using Lumina.Presentation.Api.Core.Endpoints.Common;
using Mediator; using Mediator;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using System;
using System.Security.Claims;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #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> /// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(AddLibraryRequest request, CancellationToken cancellationToken) 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); return result.Match(success => TypedResults.Created($"{BaseURL}api/v1{ApiRoutes.Libraries.ADD_LIBRARY}/{result.Value.Id}", result.Value), Problem);
} }
} }
@@ -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."; Description = "Creates a new media library and returns its details, including the location of the newly created resource.";
ExampleRequest = new AddLibraryRequest( ExampleRequest = new AddLibraryRequest(
UserId: Guid.NewGuid(),
Title: "TV Shows", Title: "TV Shows",
LibraryType: LibraryType.TvShow, LibraryType: LibraryType.TvShow,
ContentLocations: [ 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.Title, "The title of the media library. Required.");
RequestParam(r => r.LibraryType, "The type 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."); RequestParam(r => r.ContentLocations, ">The file system paths of the directories where the media library elements are located. Required.");
@@ -20,19 +20,19 @@ public class AddMediaLibraryRequestMappingTests
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly() public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
{ {
// Arrange // Arrange
Guid userId = Guid.NewGuid();
AddLibraryRequest request = new( AddLibraryRequest request = new(
Guid.NewGuid(),
"My Library", "My Library",
LibraryType.Book, LibraryType.Book,
["C:/Books", "D:/Media/Books"] ["C:/Books", "D:/Media/Books"]
); );
// Act // Act
AddLibraryCommand result = request.ToCommand(); AddLibraryCommand result = request.ToCommand(userId);
// Assert // Assert
result.Should().NotBeNull(); result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId); result.UserId.Should().Be(userId);
result.Title.Should().Be(request.Title); result.Title.Should().Be(request.Title);
result.LibraryType.Should().Be(request.LibraryType); result.LibraryType.Should().Be(request.LibraryType);
result.ContentLocations.Should().BeEquivalentTo(request.ContentLocations); result.ContentLocations.Should().BeEquivalentTo(request.ContentLocations);
@@ -46,19 +46,19 @@ public class AddMediaLibraryRequestMappingTests
public void ToCommand_WhenMappingDifferentLibraryTypes_ShouldMapCorrectly(LibraryType libraryType) public void ToCommand_WhenMappingDifferentLibraryTypes_ShouldMapCorrectly(LibraryType libraryType)
{ {
// Arrange // Arrange
Guid userId = Guid.NewGuid();
AddLibraryRequest request = new( AddLibraryRequest request = new(
Guid.NewGuid(),
"My Library", "My Library",
libraryType, libraryType,
["C:/Media"] ["C:/Media"]
); );
// Act // Act
AddLibraryCommand result = request.ToCommand(); AddLibraryCommand result = request.ToCommand(userId);
// Assert // Assert
result.Should().NotBeNull(); result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId); result.UserId.Should().Be(userId);
result.Title.Should().Be(request.Title); result.Title.Should().Be(request.Title);
result.LibraryType.Should().Be(libraryType); result.LibraryType.Should().Be(libraryType);
result.ContentLocations.Should().BeEquivalentTo(request.ContentLocations); result.ContentLocations.Should().BeEquivalentTo(request.ContentLocations);
@@ -76,15 +76,15 @@ public class AddMediaLibraryRequestMappingTests
"F:/Reading Material" "F:/Reading Material"
]; ];
Guid userId = Guid.NewGuid();
AddLibraryRequest request = new( AddLibraryRequest request = new(
Guid.NewGuid(),
"My Library", "My Library",
LibraryType.Book, LibraryType.Book,
contentLocations contentLocations
); );
// Act // Act
AddLibraryCommand result = request.ToCommand(); AddLibraryCommand result = request.ToCommand(userId);
// Assert // Assert
result.Should().NotBeNull(); result.Should().NotBeNull();