Skip to content

Commit

Permalink
refactor!: update data structures to have more data available to fron…
Browse files Browse the repository at this point in the history
…tend
  • Loading branch information
Thundernerd committed Jan 1, 2024
1 parent e9d23df commit 739dcfe
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class ChapterProgressDocument : DocumentBase<ChapterProgressDocument>
public string MangaId { get; set; } = null!;
public string ChapterId { get; set; } = null!;
public string MangaTitle { get; set; } = null!;
public string ChapterTitle { get; set; } = null!;
public double ChapterNumber { get; set; }
public bool IsActive { get; set; }
public int Progress { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ public class RequestedChapterDocument : DocumentBase<RequestedChapterDocument>
{
public required string RequestedMangaId { get; set; }
public required string ChapterId { get; set; } = null!;
public required string ChapterName { get; set; } = null!;
public required double ChapterNumber { get; set; }
public required DateTime ReleaseDate { get; set; }
public required bool MarkedForDownload { get; set; }
public bool Downloaded { get; set; }
public required DateTime CreationDate { get; set; } = DateTime.UtcNow;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public class RequestedMangaDocument : DocumentBase<RequestedMangaDocument>
public required string CoverUrl { get; set; } = null!;
public required bool NewChaptersOnly { get; set; }
public DateTime? LastScanDate { get; set; }
public required DateTime CreationDate { get; set; } = DateTime.UtcNow;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public override async Task HandleAsync(MangaChaptersRequest req, CancellationTok

await SendOkAsync(new MangaChaptersResponse
{
Data = documents.Select(x => _mapper.Map<MangaChapterModel>(x)).ToList()
Data = documents
.OrderByDescending(x => x.ChapterNumber)
.Select(x => _mapper.Map<MangaChapterModel>(x))
.ToList()
},
ct);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ namespace Mangarr.Backend.Endpoints.Manga.Details;
public class MangaDetailsEndpoint : Endpoint<MangaDetailsRequest, MangaDetailsResponse>
{
private readonly AniListService _aniListService;
private readonly IMongoCollection<RequestedMangaDocument> _collection;
private readonly IMongoCollection<RequestedMangaDocument> _mangaCollection;
private readonly IMongoCollection<SourceDocument> _sourceCollection;

public MangaDetailsEndpoint(IMongoCollection<RequestedMangaDocument> collection, AniListService aniListService)
public MangaDetailsEndpoint(
IMongoCollection<RequestedMangaDocument> mangaCollection,
AniListService aniListService,
IMongoCollection<SourceDocument> sourceCollection
)
{
_collection = collection;
_mangaCollection = mangaCollection;
_aniListService = aniListService;
_sourceCollection = sourceCollection;
}

public override void Configure()
Expand All @@ -28,7 +34,7 @@ public override void Configure()

public override async Task HandleAsync(MangaDetailsRequest req, CancellationToken ct)
{
RequestedMangaDocument? document = await _collection
RequestedMangaDocument? document = await _mangaCollection
.Find(x => x.Id == req.Id)
.FirstOrDefaultAsync(ct);

Expand All @@ -38,6 +44,16 @@ public override async Task HandleAsync(MangaDetailsRequest req, CancellationToke
return;
}

SourceDocument? source = await _sourceCollection
.Find(x => x.Identifier == document.SourceId)
.FirstOrDefaultAsync(ct);

if (source == null)
{
await SendNotFoundAsync(ct);
return;
}

Result<Media?> result = await _aniListService.GetMedia(document.SearchId);

if (result.IsFailed)
Expand All @@ -58,6 +74,7 @@ await SendOkAsync(new MangaDetailsResponse
Data = new MangaDetailsModel
{
Title = result.Value.Title.English,
SourceName = source.Name,
Description = result.Value.DescriptionHtml,
CoverImage = result.Value.CoverImage.Large,
BannerImage = result.Value.BannerImage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public override async Task HandleAsync(MangaRequestRequest req, CancellationToke
SearchId = req.SearchId,
Title = title,
CoverUrl = media.CoverImage.ExtraLarge,
NewChaptersOnly = req.NewChaptersOnly
NewChaptersOnly = req.NewChaptersOnly,
CreationDate = DateTime.UtcNow
};

await _collection.InsertOneAsync(requestedMangaDocument, null, ct);
Expand Down
1 change: 1 addition & 0 deletions src/Mangarr.Backend/Jobs/DownloadChapterSchedulerJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public async Task Execute(IJobExecutionContext context)
MangaId = manga.Id,
MangaTitle = manga.Title,
ChapterId = chapter.Id,
ChapterTitle = chapter.ChapterName,
ChapterNumber = chapter.ChapterNumber,
Progress = 0
};
Expand Down
9 changes: 6 additions & 3 deletions src/Mangarr.Backend/Jobs/IndexMangaJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ private async Task ProcessManga(RequestedMangaDocument manga, CancellationToken
.ToListAsync(ct);

List<RequestedChapterDocument> newChapters = new();

foreach (ChapterListItem chapterListItem in chapterListResult.Value.Items)
List<ChapterListItem> chapterListItems = chapterListResult.Value.Items.OrderBy(x => x.Number).ToList();
foreach (ChapterListItem chapterListItem in chapterListItems)
{
RequestedChapterDocument? existingChapter = requestedChapterDocuments
.FirstOrDefault(x => x.ChapterId == chapterListItem.Id);
Expand All @@ -100,9 +100,12 @@ private async Task ProcessManga(RequestedMangaDocument manga, CancellationToken
{
RequestedMangaId = manga.Id,
ChapterId = chapterListItem.Id,
ChapterName = chapterListItem.Name,
ChapterNumber = chapterListItem.Number,
ReleaseDate = chapterListItem.Date,
MarkedForDownload = markedForDownload,
Downloaded = false
Downloaded = false,
CreationDate = DateTime.UtcNow
};

await _chapterCollection.InsertOneAsync(requestedChapterDocument, null, ct);
Expand Down
2 changes: 1 addition & 1 deletion src/Mangarr.Frontend/Pages/Activity/ContentItem.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<td>
<a href="manga/@MangaId">@MangaTitle</a>
</td>
<td>Chapter - @ChapterNumber</td>
<td>@ChapterTitle</td>
<td class="align-middle">
@if (IsActive)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Mangarr.Frontend/Pages/Activity/ContentItem.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public partial class ContentItem
private bool IsActive => Item!.IsActive;
private string MangaId => Item!.MangaId;
private string MangaTitle => Item!.MangaTitle;
private string ChapterId => Item!.ChapterId;
private string ChapterTitle => Item!.ChapterTitle;
private double ChapterNumber => Item!.ChapterNumber;
private int Progress => Item!.Progress;
}
3 changes: 3 additions & 0 deletions src/Mangarr.Frontend/Pages/Manga/Item/ContentHeader.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<img class="flex-shrink-0" src="@CoverImage" alt="cover">
<div class="h-100 flex-grow-1 ps-4 overflow-hidden">
<h1>@Title</h1>
<p>
<span class="badge bg-primary">@SourceName</span>
</p>
<p>@((MarkupString)Description)</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public partial class ContentHeader
[Parameter] public MangaDetailsModel? Item { get; set; }

private string Title => Item!.Title;
private string SourceName => Item!.SourceName;
private string Description => Item!.Description;
private string CoverImage => Item!.CoverImage;
private string BannerImage => Item!.BannerImage;
Expand Down
7 changes: 3 additions & 4 deletions src/Mangarr.Frontend/Pages/Manga/Item/ContentList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ else
</tr>
</thead>
<tbody>
@for (int i = Items.Count - 1; i >= 0; i--)
@for (int i = 0; i < Items.Count; i++)
{
int index = i;
MangaChapterModel item = Items[index];
<ContentListItem Item="@item" Index="@(index + 1)"/>
MangaChapterModel item = Items[i];
<ContentListItem Item="@item" Index="@(Items.Count - i)"/>
}
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
</td>
<td>@Index</td>
<td>Chapter - @ChapterNumber</td>
<td>@ChapterName</td>
<td>
@if (Downloaded)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public partial class ContentListItem
[Parameter] public MangaChapterModel? Item { get; set; }
[Parameter] public int Index { get; set; }

private string ChapterName => Item!.ChapterName;
private double ChapterNumber => Item!.ChapterNumber;
private bool MarkedForDownload => Item!.MarkedForDownload;
private bool Downloaded => Item!.Downloaded;
Expand Down
3 changes: 3 additions & 0 deletions src/Mangarr.Frontend/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Backend": {
"Host": "https://localhost:7030"
}
}
1 change: 1 addition & 0 deletions src/Mangarr.Shared/Models/ChapterProgressModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class ChapterProgressModel
public string MangaId { get; set; } = null!;
public string ChapterId { get; set; } = null!;
public string MangaTitle { get; set; } = string.Empty;
public string ChapterTitle { get; set; } = string.Empty;
public double ChapterNumber { get; set; }
public bool IsActive { get; set; } = false;
public int Progress { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions src/Mangarr.Shared/Models/MangaChapterModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
public class MangaChapterModel
{
public string Id { get; set; } = null!;
public string ChapterName { get; set; } = null!;
public double ChapterNumber { get; set; }
public DateTime ReleaseDate { get; set; }
public bool MarkedForDownload { get; set; }
public bool Downloaded { get; set; }
}
9 changes: 5 additions & 4 deletions src/Mangarr.Shared/Models/MangaDetailsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

public class MangaDetailsModel
{
public string Title { get; set; }
public string Description { get; set; }
public string CoverImage { get; set; }
public string BannerImage { get; set; }
public required string Title { get; set; }
public required string SourceName { get; set; }
public required string Description { get; set; }
public required string CoverImage { get; set; }
public required string BannerImage { get; set; }
}

0 comments on commit 739dcfe

Please sign in to comment.