mirror of
https://github.com/C9Glax/tranga.git
synced 2025-02-23 07:40:13 +01:00
Fix redundant keys, MangaSearch
This commit is contained in:
parent
87274aca19
commit
3b58e0498b
@ -43,19 +43,14 @@ public class ConnectorController(PgsqlContext context) : Controller
|
||||
{
|
||||
try
|
||||
{
|
||||
context.Tags.AddRange(tags);
|
||||
context.Authors.AddRange(authors);
|
||||
context.Link.AddRange(links);
|
||||
context.AltTitles.AddRange(altTitles);
|
||||
context.Manga.AddRange(manga);
|
||||
context.SaveChanges();
|
||||
AddMangaToContext(manga, authors, tags, links, altTitles);
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
return StatusCode(500, new ProblemResponse("An error occurred while processing your request."));
|
||||
}
|
||||
}
|
||||
return Ok(allManga.Select(m => m.Item1).ToArray());
|
||||
return Ok(allManga.Select(m => context.Manga.Find(m.Item1.MangaId)).ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -78,18 +73,49 @@ public class ConnectorController(PgsqlContext context) : Controller
|
||||
{
|
||||
try
|
||||
{
|
||||
context.Tags.AddRange(tags);
|
||||
context.Authors.AddRange(authors);
|
||||
context.Link.AddRange(links);
|
||||
context.AltTitles.AddRange(altTitles);
|
||||
context.Manga.AddRange(manga);
|
||||
context.SaveChanges();
|
||||
AddMangaToContext(manga, authors, tags, links, altTitles);
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
return StatusCode(500, new ProblemResponse("An error occurred while processing your request."));
|
||||
}
|
||||
}
|
||||
return Ok(mangas.Select(m => m.Item1).ToArray());
|
||||
|
||||
return Ok(mangas.Select(m => context.Manga.Find(m.Item1.MangaId)).ToArray());
|
||||
}
|
||||
|
||||
private void AddMangaToContext(Manga? manga, Author[]? authors, MangaTag[]? tags, Link[]? links,
|
||||
MangaAltTitle[]? altTitles)
|
||||
{
|
||||
if (manga is null)
|
||||
return;
|
||||
|
||||
if (tags is not null)
|
||||
{
|
||||
IEnumerable<MangaTag> newTags = tags.Where(mt => context.Tags.All(t => !t.Tag.Equals(mt.Tag)));
|
||||
context.Tags.AddRange(newTags);
|
||||
}
|
||||
|
||||
if (authors is not null)
|
||||
{
|
||||
IEnumerable<Author> mergedAuthors = authors.Select(ma =>
|
||||
{
|
||||
Author? inDb = context.Authors.FirstOrDefault(a => a.Equals(ma));
|
||||
return inDb ?? ma;
|
||||
});
|
||||
manga.Authors = mergedAuthors.ToArray();
|
||||
IEnumerable<Author> newAuthors = authors.Where(ma => context.Authors.All(a => !a.Equals(ma)));
|
||||
context.Authors.AddRange(newAuthors);
|
||||
}
|
||||
|
||||
if (links is not null)
|
||||
context.Link.AddRange(links);
|
||||
|
||||
if(altTitles is not null)
|
||||
context.AltTitles.AddRange(altTitles);
|
||||
|
||||
context.Manga.Add(manga);
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
@ -149,7 +149,7 @@ public class MangaController(PgsqlContext context) : Controller
|
||||
Manga? m = context.Manga.Find(id);
|
||||
if (m is null)
|
||||
return NotFound("Manga could not be found");
|
||||
Chapter[] ret = context.Chapters.Where(c => c.ParentMangaId == m.MangaId).ToArray();
|
||||
Chapter[] ret = context.Chapters.Where(c => c.ParentManga.MangaId == m.MangaId).ToArray();
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ public class MangaController(PgsqlContext context) : Controller
|
||||
Manga? ret = context.Manga.Find(id);
|
||||
if(ret is null)
|
||||
return NotFound("Manga could not be found");
|
||||
if(chapters.All(c => c.ParentMangaId == ret.MangaId))
|
||||
if(chapters.All(c => c.ParentManga.MangaId == ret.MangaId))
|
||||
return BadRequest("Chapters belong to different Manga.");
|
||||
|
||||
context.Chapters.AddRange(chapters);
|
||||
@ -197,10 +197,9 @@ public class MangaController(PgsqlContext context) : Controller
|
||||
Manga? m = context.Manga.Find(id);
|
||||
if (m is null)
|
||||
return NotFound("Manga could not be found");
|
||||
Chapter? c = context.Chapters.Find(m.LatestChapterAvailableId);
|
||||
if (c is null)
|
||||
if (m.LatestChapterAvailable is null)
|
||||
return NotFound("Chapter could not be found");
|
||||
return Ok(c);
|
||||
return Ok(m.LatestChapterAvailable);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -10,6 +10,10 @@ public class Author(string authorName)
|
||||
public string AuthorId { get; init; } = TokenGen.CreateToken(typeof(Author), 64);
|
||||
public string AuthorName { get; init; } = authorName;
|
||||
|
||||
[ForeignKey("MangaIds")]
|
||||
public virtual Manga[] Mangas { get; internal set; } = [];
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is not Author other)
|
||||
return false;
|
||||
return other.AuthorName == AuthorName;
|
||||
}
|
||||
}
|
@ -18,15 +18,13 @@ public class Chapter : IComparable<Chapter>
|
||||
public string ArchiveFileName { get; private set; }
|
||||
public bool Downloaded { get; internal set; } = false;
|
||||
|
||||
[MaxLength(64)]
|
||||
public string ParentMangaId { get; init; }
|
||||
[ForeignKey("ParentMangaId")]
|
||||
public virtual Manga ParentManga { get; init; }
|
||||
[ForeignKey("MangaId")]
|
||||
public Manga ParentManga { get; init; }
|
||||
|
||||
public Chapter(string parentMangaId, string url, float chapterNumber,
|
||||
public Chapter(Manga parentManga, string url, float chapterNumber,
|
||||
float? volumeNumber = null, string? title = null)
|
||||
{
|
||||
this.ParentMangaId = parentMangaId;
|
||||
this.ParentManga = parentManga;
|
||||
this.Url = url;
|
||||
this.ChapterNumber = chapterNumber;
|
||||
this.VolumeNumber = volumeNumber;
|
||||
@ -34,10 +32,8 @@ public class Chapter : IComparable<Chapter>
|
||||
this.ArchiveFileName = BuildArchiveFileName();
|
||||
}
|
||||
|
||||
public Chapter(Manga parentManga, string url, float chapterNumber,
|
||||
float? volumeNumber = null, string? title = null) : this(parentManga.MangaId, url, chapterNumber, volumeNumber, title)
|
||||
{
|
||||
}
|
||||
public Chapter(string url, float chapterNumber, float? volumeNumber = null, string? title = null)
|
||||
: this(null, url, chapterNumber, volumeNumber, title){}
|
||||
|
||||
public MoveFileOrFolderJob? UpdateChapterNumber(float chapterNumber)
|
||||
{
|
||||
|
@ -22,13 +22,13 @@ public class Manga(
|
||||
string? originalLanguage,
|
||||
MangaReleaseStatus releaseStatus,
|
||||
float ignoreChapterBefore,
|
||||
string? latestChapterDownloadedId,
|
||||
string? latestChapterAvailableId,
|
||||
string mangaConnectorName,
|
||||
string[] authorIds,
|
||||
string[] tagIds,
|
||||
string[] linkIds,
|
||||
string[] altTitleIds)
|
||||
Chapter? latestChapterDownloaded,
|
||||
Chapter? latestChapterAvailable,
|
||||
MangaConnector mangaConnector,
|
||||
Author[] authors,
|
||||
MangaTag[] tags,
|
||||
Link[] links,
|
||||
MangaAltTitle[] altTitles)
|
||||
{
|
||||
[MaxLength(64)]
|
||||
public string MangaId { get; init; } = TokenGen.CreateToken(typeof(Manga), 64);
|
||||
@ -46,30 +46,33 @@ public class Manga(
|
||||
public string FolderName { get; private set; } = BuildFolderName(name);
|
||||
public float IgnoreChapterBefore { get; internal set; } = ignoreChapterBefore;
|
||||
|
||||
public string? LatestChapterDownloadedId { get; internal set; } = latestChapterDownloadedId;
|
||||
public virtual Chapter? LatestChapterDownloaded { get; }
|
||||
public Chapter? LatestChapterDownloaded { get; private set; } = latestChapterDownloaded;
|
||||
|
||||
public string? LatestChapterAvailableId { get; internal set; } = latestChapterAvailableId;
|
||||
public virtual Chapter? LatestChapterAvailable { get; }
|
||||
public Chapter? LatestChapterAvailable { get; private set; } = latestChapterAvailable;
|
||||
|
||||
public string MangaConnectorName { get; init; } = mangaConnectorName;
|
||||
public virtual MangaConnector MangaConnector { get; }
|
||||
public MangaConnector MangaConnector { get; private set; } = mangaConnector;
|
||||
|
||||
public string[] AuthorIds { get; internal set; } = authorIds;
|
||||
[ForeignKey("AuthorIds")]
|
||||
public virtual Author[] Authors { get; }
|
||||
public ICollection<Author> Authors { get; internal set; } = authors;
|
||||
|
||||
public string[] TagIds { get; internal set; } = tagIds;
|
||||
[ForeignKey("TagIds")]
|
||||
public virtual MangaTag[] Tags { get; }
|
||||
public ICollection<MangaTag> Tags { get; private set; } = tags;
|
||||
|
||||
public string[] LinkIds { get; internal set; } = linkIds;
|
||||
[ForeignKey("LinkIds")]
|
||||
public virtual Link[] Links { get; }
|
||||
public ICollection<Link> Links { get; private set; } = links;
|
||||
|
||||
public string[] AltTitleIds { get; internal set; } = altTitleIds;
|
||||
[ForeignKey("AltTitleIds")]
|
||||
public virtual MangaAltTitle[] AltTitles { get; }
|
||||
public ICollection<MangaAltTitle> AltTitles { get; private set; } = altTitles;
|
||||
|
||||
public Manga(string connectorId, string name, string description, string websiteUrl, string coverUrl,
|
||||
string? coverFileNameInCache,
|
||||
uint year, string? originalLanguage, MangaReleaseStatus releaseStatus, float ignoreChapterBefore)
|
||||
: this(connectorId, name, description, websiteUrl, coverUrl, coverFileNameInCache, year, originalLanguage,
|
||||
releaseStatus,
|
||||
ignoreChapterBefore, null, null, null, null, null, null, null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public MoveFileOrFolderJob UpdateFolderName(string downloadLocation, string newName)
|
||||
{
|
||||
@ -85,11 +88,11 @@ public class Manga(
|
||||
this.Description = other.Description;
|
||||
this.CoverUrl = other.CoverUrl;
|
||||
this.OriginalLanguage = other.OriginalLanguage;
|
||||
this.AuthorIds = other.AuthorIds;
|
||||
this.LinkIds = other.LinkIds;
|
||||
this.TagIds = other.TagIds;
|
||||
this.AltTitleIds = other.AltTitleIds;
|
||||
this.LatestChapterAvailableId = other.LatestChapterAvailableId;
|
||||
this.Authors = other.Authors;
|
||||
this.Links = other.Links;
|
||||
this.Tags = other.Tags;
|
||||
this.AltTitles = other.AltTitles;
|
||||
this.LatestChapterAvailable = other.LatestChapterAvailable;
|
||||
this.ReleaseStatus = other.ReleaseStatus;
|
||||
}
|
||||
|
||||
|
@ -111,9 +111,9 @@ public class AsuraToon : MangaConnector
|
||||
|
||||
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, year,
|
||||
originalLanguage, releaseStatus, -1, null, null,
|
||||
this.Name,
|
||||
authors.Select(a => a.AuthorId).ToArray(),
|
||||
mangaTags.Select(t => t.Tag).ToArray(),
|
||||
this,
|
||||
authors,
|
||||
mangaTags,
|
||||
[],
|
||||
[]);
|
||||
|
||||
|
@ -113,11 +113,11 @@ public class Bato : MangaConnector
|
||||
|
||||
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, year,
|
||||
originalLanguage, releaseStatus, -1, null, null,
|
||||
this.Name,
|
||||
authors.Select(a => a.AuthorId).ToArray(),
|
||||
mangaTags.Select(t => t.Tag).ToArray(),
|
||||
this,
|
||||
authors,
|
||||
mangaTags,
|
||||
[],
|
||||
altTitles.Select(a => a.AltTitleId).ToArray());
|
||||
altTitles);
|
||||
|
||||
return (manga, authors, mangaTags, [], altTitles);
|
||||
}
|
||||
|
@ -176,11 +176,11 @@ public class MangaDex : MangaConnector
|
||||
|
||||
Manga pub = new (publicationId, sortName, description, $"https://mangadex.org/title/{publicationId}", coverUrl, null, year,
|
||||
originalLanguage, releaseStatus, -1, null, null,
|
||||
this.Name,
|
||||
authors.Select(a => a.AuthorId).ToArray(),
|
||||
mangaTags.Select(t => t.Tag).ToArray(),
|
||||
links.Select(l => l.LinkId).ToArray(),
|
||||
altTitles.Select(a => a.AltTitleId).ToArray());
|
||||
this,
|
||||
authors,
|
||||
mangaTags,
|
||||
links,
|
||||
altTitles);
|
||||
|
||||
return (pub, authors, mangaTags, links, altTitles);
|
||||
}
|
||||
|
@ -101,9 +101,9 @@ public class MangaHere : MangaConnector
|
||||
|
||||
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, 0,
|
||||
originalLanguage, releaseStatus, -1, null, null,
|
||||
this.Name,
|
||||
authors.Select(a => a.AuthorId).ToArray(),
|
||||
mangaTags.Select(t => t.Tag).ToArray(),
|
||||
this,
|
||||
authors,
|
||||
mangaTags,
|
||||
[],
|
||||
[]);
|
||||
|
||||
|
@ -141,11 +141,11 @@ public class MangaKatana : MangaConnector
|
||||
|
||||
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, year,
|
||||
originalLanguage, releaseStatus, -1, null, null,
|
||||
this.Name,
|
||||
authors.Select(a => a.AuthorId).ToArray(),
|
||||
mangaTags.Select(t => t.Tag).ToArray(),
|
||||
this,
|
||||
authors,
|
||||
mangaTags,
|
||||
[],
|
||||
altTitles.Select(a => a.AltTitleId).ToArray());
|
||||
altTitles);
|
||||
|
||||
return (manga, authors, mangaTags, [], altTitles);
|
||||
}
|
||||
|
@ -120,9 +120,9 @@ public class MangaLife : MangaConnector
|
||||
|
||||
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, year,
|
||||
originalLanguage, releaseStatus, -1, null, null,
|
||||
this.Name,
|
||||
authors.Select(a => a.AuthorId).ToArray(),
|
||||
mangaTags.Select(t => t.Tag).ToArray(),
|
||||
this,
|
||||
authors,
|
||||
mangaTags,
|
||||
[],
|
||||
[]);
|
||||
|
||||
|
@ -136,11 +136,11 @@ public class Manganato : MangaConnector
|
||||
|
||||
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, year,
|
||||
originalLanguage, releaseStatus, -1, null, null,
|
||||
this.Name,
|
||||
authors.Select(a => a.AuthorId).ToArray(),
|
||||
mangaTags.Select(t => t.Tag).ToArray(),
|
||||
this,
|
||||
authors,
|
||||
mangaTags,
|
||||
[],
|
||||
mangaAltTitles.Select(a => a.AltTitleId).ToArray());
|
||||
mangaAltTitles);
|
||||
|
||||
return (manga, authors, mangaTags, [], mangaAltTitles);
|
||||
}
|
||||
|
@ -150,9 +150,9 @@ public class Mangasee : MangaConnector
|
||||
|
||||
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, year,
|
||||
originalLanguage, releaseStatus, -1, null, null,
|
||||
this.Name,
|
||||
authors.Select(a => a.AuthorId).ToArray(),
|
||||
mangaTags.Select(t => t.Tag).ToArray(),
|
||||
this,
|
||||
authors,
|
||||
mangaTags,
|
||||
[],
|
||||
[]);
|
||||
|
||||
|
@ -118,11 +118,11 @@ public class Mangaworld : MangaConnector
|
||||
|
||||
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, year,
|
||||
originalLanguage, releaseStatus, -1, null, null,
|
||||
this.Name,
|
||||
authors.Select(a => a.AuthorId).ToArray(),
|
||||
mangaTags.Select(t => t.Tag).ToArray(),
|
||||
this,
|
||||
authors,
|
||||
mangaTags,
|
||||
[],
|
||||
altTitles.Select(a => a.AltTitleId).ToArray());
|
||||
altTitles);
|
||||
|
||||
return (manga, authors, mangaTags, [], altTitles);
|
||||
}
|
||||
|
@ -123,9 +123,9 @@ public class ManhuaPlus : MangaConnector
|
||||
|
||||
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, year,
|
||||
originalLanguage, releaseStatus, -1, null, null,
|
||||
this.Name,
|
||||
authors.Select(a => a.AuthorId).ToArray(),
|
||||
mangaTags.Select(t => t.Tag).ToArray(),
|
||||
this,
|
||||
authors,
|
||||
mangaTags,
|
||||
[],
|
||||
[]);
|
||||
|
||||
|
@ -114,11 +114,11 @@ public class Weebcentral : MangaConnector
|
||||
|
||||
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, year,
|
||||
originalLanguage, releaseStatus, -1, null, null,
|
||||
this.Name,
|
||||
authors.Select(a => a.AuthorId).ToArray(),
|
||||
mangaTags.Select(t => t.Tag).ToArray(),
|
||||
this,
|
||||
authors,
|
||||
mangaTags,
|
||||
[],
|
||||
altTitles.Select(a => a.AltTitleId).ToArray());
|
||||
altTitles);
|
||||
|
||||
return (manga, authors, mangaTags, [], altTitles);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user