Implements first stage library management system

This commit is contained in:
BinaryAlley committed 2024-11-03 19:43:46 +02:00
1 parent 5e0f94cd82
commit 36352ea9e8
291 files changed
+3733 -1384

No files matched your search

@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Presentation.Api.Common.Routes.Library.WrittenContentLibrary.BookLibrary;
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.WrittenContentLibrary.BookLibrary.Books.AddBook;
/// <summary>
/// API endpoint for the <c>/books</c> route.
/// </summary>
public class AddBookEndpoint : BaseEndpoint<AddBookRequest, IResult>
{
private readonly ISender _sender;
/// <summary>
/// Initializes a new instance of the <see cref="AddBookEndpoint"/> class.
/// </summary>
/// <param name="sender">Injected service for mediating commands and queries.</param>
public AddBookEndpoint(ISender sender)
{
_sender = sender;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.POST);
Routes(ApiRoutes.Books.ADD_BOOK);
Version(1);
AllowAnonymous();
DontCatchExceptions();
}
/// <summary>
/// Adds a book stored in <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the book to be added.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(AddBookRequest request, CancellationToken cancellationToken)
{
ErrorOr<BookResponse> result = await _sender.Send(request.ToCommand(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Created($"{BaseURL}api/v1{ApiRoutes.Books.ADD_BOOK}/{result.Value.Id}", result.Value), Problem);
}
}
@@ -0,0 +1,51 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.AddBook;
/// <summary>
/// Class used for providing a textual description for the <see cref="AddBookEndpoint"/> API endpoint, for Swagger.
/// </summary>
public class AddLibraryEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="AddLibraryEndpointSummary"/> class.
/// </summary>
public AddLibraryEndpointSummary()
{
Summary = "Adds a new book.";
Description = "Creates a new book and returns its details, including the location of the newly created resource.";
RequestParam(r => r.Metadata, "Written content metadata of the book.");
RequestParam(r => r.Metadata!.Title, "The title of the written content.");
RequestParam(r => r.Format, "The format of the book (e.g., Hardcover, Paperback), if applicable.");
RequestParam(r => r.Edition, "The edition of the book, if applicable.");
RequestParam(r => r.VolumeNumber, "The volume or book number in the series, if applicable.");
RequestParam(r => r.Series, "The series name, if the book is part of a series.");
RequestParam(r => r.ASIN, "The ASIN (Amazon Standard Identification Number) of the book, if applicable.");
RequestParam(r => r.GoodreadsId, "The Goodreads ID of the book, if applicable.");
RequestParam(r => r.LCCN, "The Library of Congress Control Number (LCCN) of the book, if applicable.");
RequestParam(r => r.OCLCNumber, "The OCLC Number (WorldCat identifier) of the book, if applicable.");
RequestParam(r => r.OpenLibraryId, "The Open Library ID of the book, if applicable.");
RequestParam(r => r.LibraryThingId, "The LibraryThing ID of the book, if applicable.");
RequestParam(r => r.GoogleBooksId, "The Google Books ID of the book, if applicable.");
RequestParam(r => r.BarnesAndNobleId, "The Barnes & Noble ID of the book, if applicable.");
RequestParam(r => r.AppleBooksId, "The Apple Books ID of the book, if applicable.");
RequestParam(r => r.ISBNs, "The list of ISBN (International Standard Book Number) of the book.");
RequestParam(r => r.Contributors, "The list of media contributors (actors, directors, etc) starring in this book.");
RequestParam(r => r.Ratings, "The list of ratings for this book.");
ResponseParam<BookResponse>(r => r.Id, "The unique identifier of the entity.");
ResponseParam<BookResponse>(r => r.Created, "The date and time when the entity was created.");
ResponseParam<BookResponse>(r => r.Updated, "The date and time when the entity was last updated.");
ResponseParam<BookResponse>(r => r.Metadata, "The written content metadata of the book.");
ResponseParam<BookResponse>(r => r.Metadata.Title, "The title of the media item.");
ResponseParam<BookResponse>(r => r.Metadata.OriginalTitle, "The original title of the media item.");
Response<BookResponse>(201, "The book was successfully created.", "The location of the created resource is provided in the Location header.");
Response<ProblemDetails>(422, "The request did not pass validation checks.", "application/problem+json");
}
}
@@ -0,0 +1,54 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooks;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Presentation.Api.Common.Routes.Library.WrittenContentLibrary.BookLibrary;
using Lumina.Presentation.Api.Core.Endpoints.Common;
using Mediator;
using Microsoft.AspNetCore.Http;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetBooks;
/// <summary>
/// API endpoint for the <c>/books</c> route.
/// </summary>
public class GetBooksEndpoint : BaseEndpoint<EmptyRequest, IResult>
{
private readonly ISender _sender;
/// <summary>
/// Initializes a new instance of the <see cref="GetBooksEndpoint"/> class.
/// </summary>
/// <param name="sender">Injected service for mediating commands and queries.</param>
public GetBooksEndpoint(ISender sender)
{
_sender = sender;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Routes(ApiRoutes.Books.GET_BOOKS);
Version(1);
AllowAnonymous();
DontCatchExceptions();
}
/// <summary>
/// Gets the list of all books.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(EmptyRequest _, CancellationToken cancellationToken)
{
ErrorOr<IEnumerable<BookResponse>> result = await _sender.Send(new GetBooksQuery(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,24 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using System.Collections.Generic;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetBooks;
/// <summary>
/// Class used for providing a textual description for the <see cref="GetBooksEndpoint"/> API endpoint, for Swagger.
/// </summary>
public class GetBooksEndpointSummary : Summary<GetBooksEndpoint>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetBooksEndpointSummary"/> class.
/// </summary>
public GetBooksEndpointSummary()
{
Summary = "Retrieves the list of books.";
Description = "Returns the entire list of books.";
Response<IEnumerable<BookResponse>>(200, "The list of books is returned.");
}
}
@@ -0,0 +1,53 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Presentation.Api.Common.Routes.Library.WrittenContentLibrary.BookLibrary;
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.WrittenContentLibrary.BookLibrary.GetBook;
/// <summary>
/// API endpoint for the <c>/books</c> route.
/// </summary>
public class GetBookEndpoint : BaseEndpoint<GetBookRequest, IResult>
{
private readonly ISender _sender;
/// <summary>
/// Initializes a new instance of the <see cref="GetBookEndpoint"/> class.
/// </summary>
/// <param name="sender">Injected service for mediating commands and queries.</param>
public GetBookEndpoint(ISender sender)
{
_sender = sender;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Routes(ApiRoutes.Books.GET_BOOK_BY_ID);
Version(1);
AllowAnonymous();
DontCatchExceptions();
}
/// <summary>
/// Adds a book stored in <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the book to be added.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetBookRequest request, CancellationToken cancellationToken)
{
//ErrorOr<Book> result = await _sender.Send(request.ToCommand(), cancellationToken).ConfigureAwait(false);
//return result.Match(success => TypedResults.CreatedAtRoute($"/api/v1/books/{success.Id}", success), Problem);
return await Task.FromResult(TypedResults.Ok());
}
}
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Contracts.Requests.MediaLibrary.Management;
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.WrittenContentLibrary.Management.AddLibrary;
/// <summary>
/// API endpoint for the <c>/library</c> route.
/// </summary>
public class AddLibraryEndpoint : BaseEndpoint<AddLibraryRequest, IResult>
{
private readonly ISender _sender;
/// <summary>
/// Initializes a new instance of the <see cref="AddLibraryEndpoint"/> class.
/// </summary>
/// <param name="sender">Injected service for mediating commands and queries.</param>
public AddLibraryEndpoint(ISender sender)
{
_sender = sender;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.POST);
Routes(ApiRoutes.Libraries.ADD_LIBRARY);
Version(1);
AllowAnonymous();
DontCatchExceptions();
}
/// <summary>
/// Adds a media library stored in <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the media library to be added.</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)
{
ErrorOr<LibraryResponse> result = await _sender.Send(request.ToCommand(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Created($"{BaseURL}api/v1{ApiRoutes.Libraries.ADD_LIBRARY}/{result.Value.Id}", result.Value), Problem);
}
}
@@ -0,0 +1,39 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using Lumina.Contracts.Responses.MediaLibrary.Management;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.Management.AddLibrary;
/// <summary>
/// Class used for providing a textual description for the <see cref="AddLibraryEndpoint"/> API endpoint, for Swagger.
/// </summary>
public class AddLibraryEndpointSummary : Summary<AddLibraryEndpoint, AddLibraryRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="AddLibraryEndpointSummary"/> class.
/// </summary>
public AddLibraryEndpointSummary()
{
Summary = "Adds a new media library.";
Description = "Creates a new media library and returns its details, including the location of the newly created resource.";
RequestParam(r => r.UserId, "The Id of the user owning the media library.");
RequestParam(r => r.Title, "The title of the media library.");
RequestParam(r => r.LibraryType, "The type of the media library.");
RequestParam(r => r.ContentLocations, ">The file system paths of the directories where the media library elements are located.");
ResponseParam<LibraryResponse>(r => r.Id, "The unique identifier of the entity.");
ResponseParam<LibraryResponse>(r => r.UserId, "The Id of the user owning the media library.");
ResponseParam<LibraryResponse>(r => r.Title, "The title of the media library.");
ResponseParam<LibraryResponse>(r => r.LibraryType, "The type of the media library.");
ResponseParam<LibraryResponse>(r => r.ContentLocations, "The file system paths of the directories where the media library elements are located.");
ResponseParam<LibraryResponse>(r => r.Created, "The date and time when the entity was created.");
ResponseParam<LibraryResponse>(r => r.Updated, "The date and time when the entity was last updated.");
Response<LibraryResponse>(201, "The media library was successfully created.", "The location of the created resource is provided in the Location header.");
Response<ProblemDetails>(422, "The request did not pass validation checks.", "application/problem+json");
}
}