mirror of
https://github.com/C9Glax/tranga.git
synced 2025-09-10 03:48:19 +02:00
Add FileLibrary DTO and CreateLibraryRecord
This commit is contained in:
@@ -6,7 +6,7 @@ namespace API.Controllers.DTOs;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The <see cref="API.Schema.MangaContext.Author"/> DTO
|
/// The <see cref="API.Schema.MangaContext.Author"/> DTO
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public record Author(string Key, string Name) : Identifiable(Key)
|
public sealed record Author(string Key, string Name) : Identifiable(Key)
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Name of the Author.
|
/// Name of the Author.
|
||||||
|
@@ -6,7 +6,7 @@ namespace API.Controllers.DTOs;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="API.Schema.MangaContext.Chapter"/> DTO
|
/// <see cref="API.Schema.MangaContext.Chapter"/> DTO
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public record Chapter(string Key, string MangaId, int? Volume, string ChapterNumber, string? Title, IEnumerable<MangaConnectorId> MangaConnectorIds, bool Downloaded) : Identifiable(Key)
|
public sealed record Chapter(string Key, string MangaId, int? Volume, string ChapterNumber, string? Title, IEnumerable<MangaConnectorId> MangaConnectorIds, bool Downloaded) : Identifiable(Key)
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Identifier of the Manga this Chapter belongs to
|
/// Identifier of the Manga this Chapter belongs to
|
||||||
|
14
API/Controllers/DTOs/FileLibrary.cs
Normal file
14
API/Controllers/DTOs/FileLibrary.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace API.Controllers.DTOs;
|
||||||
|
|
||||||
|
public sealed record FileLibrary(string Key, string BasePath, string LibraryName) : Identifiable(Key)
|
||||||
|
{
|
||||||
|
[StringLength(256)]
|
||||||
|
[Required]
|
||||||
|
public string BasePath { get; internal set; } = BasePath;
|
||||||
|
|
||||||
|
[StringLength(512)]
|
||||||
|
[Required]
|
||||||
|
public string LibraryName { get; internal set; } = LibraryName;
|
||||||
|
}
|
@@ -7,7 +7,7 @@ namespace API.Controllers.DTOs;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="Schema.MangaContext.Manga"/> DTO
|
/// <see cref="Schema.MangaContext.Manga"/> DTO
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public record Manga(string Key, string Name, string Description, MangaReleaseStatus ReleaseStatus, IEnumerable<MangaConnectorId> MangaConnectorIds, float IgnoreChaptersBefore, uint? Year, string? OriginalLanguage, IEnumerable<string> ChapterIds, IEnumerable<Author> Authors, IEnumerable<string> Tags, IEnumerable<Link> Links, IEnumerable<AltTitle> AltTitles, string? FileLibraryId)
|
public sealed record Manga(string Key, string Name, string Description, MangaReleaseStatus ReleaseStatus, IEnumerable<MangaConnectorId> MangaConnectorIds, float IgnoreChaptersBefore, uint? Year, string? OriginalLanguage, IEnumerable<string> ChapterIds, IEnumerable<Author> Authors, IEnumerable<string> Tags, IEnumerable<Link> Links, IEnumerable<AltTitle> AltTitles, string? FileLibraryId)
|
||||||
: MinimalManga(Key, Name, Description, ReleaseStatus, MangaConnectorIds)
|
: MinimalManga(Key, Name, Description, ReleaseStatus, MangaConnectorIds)
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@@ -4,6 +4,8 @@ using Microsoft.AspNetCore.Http.HttpResults;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
using FileLibrary = API.Controllers.DTOs.FileLibrary;
|
||||||
|
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
namespace API.Controllers;
|
namespace API.Controllers;
|
||||||
@@ -14,18 +16,21 @@ namespace API.Controllers;
|
|||||||
public class FileLibraryController(MangaContext context) : Controller
|
public class FileLibraryController(MangaContext context) : Controller
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns all <see cref="FileLibrary"/>
|
/// Returns all <see cref="DTOs.FileLibrary"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
/// <response code="500">Error during Database Operation</response>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType<FileLibrary[]>(Status200OK, "application/json")]
|
[ProducesResponseType<List<FileLibrary>>(Status200OK, "application/json")]
|
||||||
[ProducesResponseType(Status500InternalServerError)]
|
[ProducesResponseType(Status500InternalServerError)]
|
||||||
public async Task<Results<Ok<List<FileLibrary>>, InternalServerError>> GetFileLibraries ()
|
public async Task<Results<Ok<List<FileLibrary>>, InternalServerError>> GetFileLibraries ()
|
||||||
{
|
{
|
||||||
if (await context.FileLibraries.ToListAsync(HttpContext.RequestAborted) is not { } result)
|
if (await context.FileLibraries.ToListAsync(HttpContext.RequestAborted) is not { } result)
|
||||||
return TypedResults.InternalServerError();
|
return TypedResults.InternalServerError();
|
||||||
return TypedResults.Ok(result);
|
|
||||||
|
List<FileLibrary> fileLibraries = result.Select(f => new FileLibrary(f.Key, f.BasePath, f.LibraryName)).ToList();
|
||||||
|
|
||||||
|
return TypedResults.Ok(fileLibraries);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -42,7 +47,7 @@ public class FileLibraryController(MangaContext context) : Controller
|
|||||||
if(await context.FileLibraries.FirstOrDefaultAsync(l => l.Key == FileLibraryId, HttpContext.RequestAborted) is not { } library)
|
if(await context.FileLibraries.FirstOrDefaultAsync(l => l.Key == FileLibraryId, HttpContext.RequestAborted) is not { } library)
|
||||||
return TypedResults.NotFound(nameof(FileLibraryId));
|
return TypedResults.NotFound(nameof(FileLibraryId));
|
||||||
|
|
||||||
return TypedResults.Ok(library);
|
return TypedResults.Ok(new FileLibrary(library.Key, library.BasePath, library.LibraryName));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -98,15 +103,16 @@ public class FileLibraryController(MangaContext context) : Controller
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates new <see cref="FileLibrary"/>
|
/// Creates new <see cref="FileLibrary"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="library">New <see cref="FileLibrary"/> to add</param>
|
/// <param name="requestData">New <see cref="FileLibrary"/> to add</param>
|
||||||
/// <response code="200">Key of new Library</response>
|
/// <response code="200">Key of new Library</response>
|
||||||
/// <response code="500">Error during Database Operation</response>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpPut]
|
[HttpPut]
|
||||||
[ProducesResponseType<string>(Status201Created, "text/plain")]
|
[ProducesResponseType<string>(Status201Created, "text/plain")]
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
public async Task<Results<Created<string>, InternalServerError<string>>> CreateNewLibrary ([FromBody]FileLibrary library)
|
public async Task<Results<Created<string>, InternalServerError<string>>> CreateNewLibrary ([FromBody]CreateLibraryRecord requestData)
|
||||||
{
|
{
|
||||||
//TODO Parameter check
|
//TODO Parameter check
|
||||||
|
Schema.MangaContext.FileLibrary library = new Schema.MangaContext.FileLibrary(requestData.BasePath, requestData.LibraryName);
|
||||||
context.FileLibraries.Add(library);
|
context.FileLibraries.Add(library);
|
||||||
|
|
||||||
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
|
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
|
||||||
@@ -114,6 +120,7 @@ public class FileLibraryController(MangaContext context) : Controller
|
|||||||
|
|
||||||
return TypedResults.Created(string.Empty, library.Key);
|
return TypedResults.Created(string.Empty, library.Key);
|
||||||
}
|
}
|
||||||
|
public sealed record CreateLibraryRecord(string BasePath, string LibraryName);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes the <see cref="FileLibraryId"/>.LibraryName with <paramref name="FileLibraryId"/>
|
/// Deletes the <see cref="FileLibraryId"/>.LibraryName with <paramref name="FileLibraryId"/>
|
||||||
|
Reference in New Issue
Block a user