Added more UI logic. Added a manga pipeline test.
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
using MangaReader.Core.Metadata;
|
||||
|
||||
namespace MangaReader.Core.Pipeline;
|
||||
namespace MangaReader.Core.Pipeline;
|
||||
|
||||
public interface IMangaPipeline
|
||||
{
|
||||
Task RunAsync(SourceManga mangaDto);
|
||||
Task RunAsync(MangaPipelineRequest request);
|
||||
}
|
||||
@@ -7,8 +7,12 @@ namespace MangaReader.Core.Pipeline;
|
||||
|
||||
public partial class MangaPipeline(MangaContext context) : IMangaPipeline
|
||||
{
|
||||
public async Task RunAsync(SourceManga sourceManga)
|
||||
public async Task RunAsync(MangaPipelineRequest request)
|
||||
{
|
||||
string sourceName = request.SourceName;
|
||||
SourceManga sourceManga = request.SourceManga;
|
||||
|
||||
Source source = await GetOrAddSourceAsync(sourceName);
|
||||
Manga manga = await GetOrAddMangaAsync(sourceManga);
|
||||
|
||||
foreach (SourceMangaTitle alternateTitle in sourceManga.AlternateTitles)
|
||||
@@ -29,6 +33,23 @@ public partial class MangaPipeline(MangaContext context) : IMangaPipeline
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
private async Task<Source> GetOrAddSourceAsync(string sourceName)
|
||||
{
|
||||
Source? source = await context.Sources.FirstOrDefaultAsync(s => s.Name == sourceName);
|
||||
|
||||
if (source != null)
|
||||
return source;
|
||||
|
||||
source = new()
|
||||
{
|
||||
Name = sourceName
|
||||
};
|
||||
|
||||
context.Sources.Add(source);
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
private async Task<Manga> GetOrAddMangaAsync(SourceManga sourceManga)
|
||||
{
|
||||
Manga? manga = await context.Mangas.FirstOrDefaultAsync(manga => manga.Title == sourceManga.Title);
|
||||
@@ -65,7 +86,7 @@ public partial class MangaPipeline(MangaContext context) : IMangaPipeline
|
||||
private async Task AddTitleAsync(Manga manga, SourceMangaTitle sourceMangaTitle)
|
||||
{
|
||||
MangaTitle? mangaTitle = await context.MangaTitles.FirstOrDefaultAsync(mt =>
|
||||
mt.Manga == manga && mt.TitleEntry == sourceMangaTitle.Title);
|
||||
mt.Manga == manga && mt.Name == sourceMangaTitle.Title);
|
||||
|
||||
if (mangaTitle != null)
|
||||
return;
|
||||
@@ -73,7 +94,7 @@ public partial class MangaPipeline(MangaContext context) : IMangaPipeline
|
||||
mangaTitle = new()
|
||||
{
|
||||
Manga = manga,
|
||||
TitleEntry = sourceMangaTitle.Title,
|
||||
Name = sourceMangaTitle.Title,
|
||||
};
|
||||
|
||||
context.MangaTitles.Add(mangaTitle);
|
||||
|
||||
9
MangaReader.Core/Pipeline/MangaPipelineRequest.cs
Normal file
9
MangaReader.Core/Pipeline/MangaPipelineRequest.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using MangaReader.Core.Metadata;
|
||||
|
||||
namespace MangaReader.Core.Pipeline;
|
||||
|
||||
public class MangaPipelineRequest
|
||||
{
|
||||
public required string SourceName { get; init; }
|
||||
public required SourceManga SourceManga { get; init; }
|
||||
}
|
||||
Reference in New Issue
Block a user