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.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
@@ -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);
}
}
@@ -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.");