mirror of
https://github.com/C9Glax/tranga.git
synced 2025-09-10 03:48:19 +02:00
Search use MinimalManga
This commit is contained in:
@@ -1,5 +1,21 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using API.Schema.MangaContext;
|
using API.Schema.MangaContext;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace API.Controllers.DTOs;
|
namespace API.Controllers.DTOs;
|
||||||
|
|
||||||
public sealed record MinimalManga(string Key, string Name, string Description, MangaReleaseStatus ReleaseStatus);
|
public sealed record MinimalManga(string Key, string Name, string Description, MangaReleaseStatus ReleaseStatus, IEnumerable<MangaConnectorId<Manga>>? MangaConnectorIds = null)
|
||||||
|
{
|
||||||
|
[Required] [StringLength(TokenGen.MaximumLength, MinimumLength = TokenGen.MinimumLength)]
|
||||||
|
public string Key { get; init; } = Key;
|
||||||
|
[Required]
|
||||||
|
[JsonRequired]
|
||||||
|
public string Name { get; init; } = Name;
|
||||||
|
[Required]
|
||||||
|
[JsonRequired]
|
||||||
|
public string Description { get; init; } = Description;
|
||||||
|
[Required]
|
||||||
|
[JsonRequired]
|
||||||
|
public MangaReleaseStatus ReleaseStatus { get; init; } = ReleaseStatus;
|
||||||
|
public IEnumerable<MangaConnectorId<Manga>>? MangaConnectorIds { get; init; } = MangaConnectorIds;
|
||||||
|
}
|
@@ -67,7 +67,7 @@ public class MangaController(MangaContext context) : Controller
|
|||||||
.ToArrayAsync(HttpContext.RequestAborted) is not { } result)
|
.ToArrayAsync(HttpContext.RequestAborted) is not { } result)
|
||||||
return StatusCode(Status500InternalServerError);
|
return StatusCode(Status500InternalServerError);
|
||||||
|
|
||||||
return Ok(result.Select(m => new MinimalManga(m.Key, m.Name, m.Description, m.ReleaseStatus)));
|
return Ok(result.Select(m => new MinimalManga(m.Key, m.Name, m.Description, m.ReleaseStatus, m.MangaConnectorIds)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
using API.Controllers.DTOs;
|
||||||
using API.MangaConnectors;
|
using API.MangaConnectors;
|
||||||
using API.Schema.MangaContext;
|
using API.Schema.MangaContext;
|
||||||
using Asp.Versioning;
|
using Asp.Versioning;
|
||||||
@@ -17,11 +18,11 @@ public class SearchController(MangaContext context) : Controller
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="MangaConnectorName"><see cref="MangaConnector"/>.Name</param>
|
/// <param name="MangaConnectorName"><see cref="MangaConnector"/>.Name</param>
|
||||||
/// <param name="Query">searchTerm</param>
|
/// <param name="Query">searchTerm</param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"><see cref="MinimalManga"/> exert of <see cref="Manga"/>. Use <see cref="GetManga"/> for more information</response>
|
||||||
/// <response code="404"><see cref="MangaConnector"/> with Name not found</response>
|
/// <response code="404"><see cref="MangaConnector"/> with Name not found</response>
|
||||||
/// <response code="412"><see cref="MangaConnector"/> with Name is disabled</response>
|
/// <response code="412"><see cref="MangaConnector"/> with Name is disabled</response>
|
||||||
[HttpGet("{MangaConnectorName}/{Query}")]
|
[HttpGet("{MangaConnectorName}/{Query}")]
|
||||||
[ProducesResponseType<Manga[]>(Status200OK, "application/json")]
|
[ProducesResponseType<MinimalManga[]>(Status200OK, "application/json")]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType(Status404NotFound)]
|
||||||
[ProducesResponseType(Status406NotAcceptable)]
|
[ProducesResponseType(Status406NotAcceptable)]
|
||||||
public IActionResult SearchManga (string MangaConnectorName, string Query)
|
public IActionResult SearchManga (string MangaConnectorName, string Query)
|
||||||
@@ -39,19 +40,19 @@ public class SearchController(MangaContext context) : Controller
|
|||||||
retMangas.Add(add);
|
retMangas.Add(add);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(retMangas.ToArray());
|
return Ok(retMangas.Select(m => new MinimalManga(m.Key, m.Name, m.Description, m.ReleaseStatus, m.MangaConnectorIds)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns <see cref="Manga"/> from the <see cref="MangaConnector"/> associated with <paramref name="url"/>
|
/// Returns <see cref="Manga"/> from the <see cref="MangaConnector"/> associated with <paramref name="url"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"><see cref="MinimalManga"/> exert of <see cref="Manga"/>. Use <see cref="GetManga"/> for more information</response>
|
||||||
/// <response code="300">Multiple <see cref="MangaConnector"/> found for URL</response>
|
/// <response code="300">Multiple <see cref="MangaConnector"/> found for URL</response>
|
||||||
/// <response code="404"><see cref="Manga"/> not found</response>
|
/// <response code="404"><see cref="Manga"/> not found</response>
|
||||||
/// <response code="500">Error during Database Operation</response>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpPost("Url")]
|
[HttpPost("Url")]
|
||||||
[ProducesResponseType<Manga>(Status200OK, "application/json")]
|
[ProducesResponseType<MinimalManga>(Status200OK, "application/json")]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType(Status404NotFound)]
|
||||||
[ProducesResponseType(Status500InternalServerError)]
|
[ProducesResponseType(Status500InternalServerError)]
|
||||||
public IActionResult GetMangaFromUrl ([FromBody]string url)
|
public IActionResult GetMangaFromUrl ([FromBody]string url)
|
||||||
@@ -65,6 +66,6 @@ public class SearchController(MangaContext context) : Controller
|
|||||||
if(Tranga.AddMangaToContext(manga, context, out Manga? add, HttpContext.RequestAborted) == false)
|
if(Tranga.AddMangaToContext(manga, context, out Manga? add, HttpContext.RequestAborted) == false)
|
||||||
return StatusCode(Status500InternalServerError);
|
return StatusCode(Status500InternalServerError);
|
||||||
|
|
||||||
return Ok(add);
|
return Ok(new MinimalManga(add.Key, add.Name, add.Description, add.ReleaseStatus, add.MangaConnectorIds));
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user