Skip to content

Commit

Permalink
feat: making more info available to the frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
Thundernerd committed Jan 1, 2024
1 parent 739dcfe commit 7575ccc
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
using Mangarr.Shared.Models;
using Mangarr.Backend.Sources;
using Mangarr.Shared.Models;
using Mangarr.Shared.Requests;
using Mangarr.Shared.Responses;
using MongoDB.Driver;
using IMapper = AutoMapper.IMapper;
using RequestedChapterDocument = Mangarr.Backend.Database.Documents.RequestedChapterDocument;

namespace Mangarr.Backend.Endpoints.Manga.Chapters;

public class MangaChaptersEndpoint : Endpoint<MangaChaptersRequest, MangaChaptersResponse>
{
private readonly IMongoCollection<RequestedChapterDocument> _chapterCollection;
private readonly IMapper _mapper;

public MangaChaptersEndpoint(IMongoCollection<RequestedChapterDocument> chapterCollection, IMapper mapper)
{
public MangaChaptersEndpoint(IMongoCollection<RequestedChapterDocument> chapterCollection) =>
_chapterCollection = chapterCollection;
_mapper = mapper;
}

public override void Configure()
{
Expand All @@ -34,9 +30,25 @@ await SendOkAsync(new MangaChaptersResponse
{
Data = documents
.OrderByDescending(x => x.ChapterNumber)
.Select(x => _mapper.Map<MangaChapterModel>(x))
.Select(Map)
.ToList()
},
ct);
}

private MangaChapterModel Map(RequestedChapterDocument document)
{
SourceBase.DeconstructId(document.ChapterId, out string url, out _);

return new MangaChapterModel
{
Id = document.Id,
ChapterUrl = url,
ChapterName = document.ChapterName,
ChapterNumber = document.ChapterNumber,
ReleaseDate = document.ReleaseDate,
MarkedForDownload = document.MarkedForDownload,
Downloaded = document.Downloaded
};
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Anilist4Net;
using FluentResults;
using Mangarr.Backend.Services;
using Mangarr.Backend.Sources;
using Mangarr.Shared.Models;
using Mangarr.Shared.Requests;
using Mangarr.Shared.Responses;
Expand Down Expand Up @@ -69,12 +70,15 @@ public override async Task HandleAsync(MangaDetailsRequest req, CancellationToke
return;
}

SourceBase.DeconstructId(document.MangaId, out string url, out _);

await SendOkAsync(new MangaDetailsResponse
{
Data = new MangaDetailsModel
{
Title = result.Value.Title.English,
SourceName = source.Name,
SourceUrl = url,
Description = result.Value.DescriptionHtml,
CoverImage = result.Value.CoverImage.Large,
BannerImage = result.Value.BannerImage
Expand Down
1 change: 0 additions & 1 deletion src/Mangarr.Backend/Profiles/MandarrProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ public MangarrProfile()
CreateMap<ChapterProgressDocument, ChapterProgressModel>();
CreateMap<SourceDocument, ProviderModel>();
CreateMap<SearchResultItem, ProviderMangaModel>();
CreateMap<RequestedChapterDocument, MangaChapterModel>();
}
}
8 changes: 4 additions & 4 deletions src/Mangarr.Backend/Sources/SourceBase.Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Mangarr.Backend.Sources;

internal abstract partial class SourceBase
{
protected IDocument CreateDocument(string html) => new HtmlParser().ParseDocument(html);
protected static IDocument CreateDocument(string html) => new HtmlParser().ParseDocument(html);

protected bool TryParseRelativeDate(string input, out DateTime result)
protected static bool TryParseRelativeDate(string input, out DateTime result)
{
string[] parts = input.Split(' ');

Expand Down Expand Up @@ -58,7 +58,7 @@ protected bool TryParseRelativeDate(string input, out DateTime result)
return true;
}

protected string ConstructId(string url, params string[] args)
internal static string ConstructId(string url, params string[] args)
{
if (args.Length == 0)
{
Expand All @@ -69,7 +69,7 @@ protected string ConstructId(string url, params string[] args)
return string.Join("|", segments).ToBase64();
}

protected void DeconstructId(string id, out string url, out string[] args)
internal static void DeconstructId(string id, out string url, out string[] args)
{
string[] splits = id.FromBase64().Split('|', StringSplitOptions.RemoveEmptyEntries);
url = splits[0];
Expand Down
2 changes: 1 addition & 1 deletion src/Mangarr.Frontend/Pages/Manga/Item/ContentHeader.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="h-100 flex-grow-1 ps-4 overflow-hidden">
<h1>@Title</h1>
<p>
<span class="badge bg-primary">@SourceName</span>
<a href="@SourceUrl" target="_blank" class="btn btn-primary btn-sm">@SourceName</a>
</p>
<p>@((MarkupString)Description)</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public partial class ContentHeader

private string Title => Item!.Title;
private string SourceName => Item!.SourceName;
private string SourceUrl => Item!.SourceUrl;
private string Description => Item!.Description;
private string CoverImage => Item!.CoverImage;
private string BannerImage => Item!.BannerImage;
Expand Down
1 change: 1 addition & 0 deletions src/Mangarr.Frontend/Pages/Manga/Item/ContentList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ else
<th></th>
<th>#</th>
<th>Chapter</th>
<th>Released</th>
<th>Status</th>
</tr>
</thead>
Expand Down
5 changes: 4 additions & 1 deletion src/Mangarr.Frontend/Pages/Manga/Item/ContentListItem.razor
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
}
</td>
<td>@Index</td>
<td>@ChapterName</td>
<td>
<a href="@ChapterUrl">@ChapterName</a>
</td>
<td>@ReleaseDate.ToShortDateString()</td>
<td>
@if (Downloaded)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ public partial class ContentListItem
[Parameter] public MangaChapterModel? Item { get; set; }
[Parameter] public int Index { get; set; }

private string ChapterUrl => Item!.ChapterUrl;
private string ChapterName => Item!.ChapterName;
private double ChapterNumber => Item!.ChapterNumber;
private DateTime ReleaseDate => Item!.ReleaseDate;
private bool MarkedForDownload => Item!.MarkedForDownload;
private bool Downloaded => Item!.Downloaded;
}
1 change: 1 addition & 0 deletions src/Mangarr.Shared/Models/MangaChapterModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class MangaChapterModel
{
public string Id { get; set; } = null!;
public string ChapterUrl { get; set; } = null!;
public string ChapterName { get; set; } = null!;
public double ChapterNumber { get; set; }
public DateTime ReleaseDate { get; set; }
Expand Down
1 change: 1 addition & 0 deletions src/Mangarr.Shared/Models/MangaDetailsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class MangaDetailsModel
{
public required string Title { get; set; }
public required string SourceName { get; set; }
public required string SourceUrl { get; set; }
public required string Description { get; set; }
public required string CoverImage { get; set; }
public required string BannerImage { get; set; }
Expand Down

0 comments on commit 7575ccc

Please sign in to comment.