#413 GetPoemSectionsByPoemFormat
This commit is contained in:
parent
0c5d4d5bad
commit
bba5980051
@ -14409,6 +14409,15 @@
|
||||
<param name="poetId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.GetPoemSectionsByPoemFormat(RSecurityBackend.Models.Generic.PagingParameterModel,RMuseum.Models.Ganjoor.GanjoorPoemFormat,System.Nullable{System.Int32})">
|
||||
<summary>
|
||||
Get Poem sections based on poem format
|
||||
</summary>
|
||||
<param name="paging"></param>
|
||||
<param name="format"></param>
|
||||
<param name="poetId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.GetLanguageTaggedPoemSections(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.Nullable{System.Int32})">
|
||||
<summary>
|
||||
language tagged poem sections
|
||||
@ -17645,6 +17654,15 @@
|
||||
<param name="poetId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetPoemSectionsByPoemFormat(RSecurityBackend.Models.Generic.PagingParameterModel,RMuseum.Models.Ganjoor.GanjoorPoemFormat,System.Nullable{System.Int32})">
|
||||
<summary>
|
||||
Get Poem sections based on poem format
|
||||
</summary>
|
||||
<param name="paging"></param>
|
||||
<param name="format"></param>
|
||||
<param name="poetId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetLanguageTaggedPoemSections(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.Nullable{System.Int32})">
|
||||
<summary>
|
||||
language tagged poem sections
|
||||
|
||||
@ -482,6 +482,15 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorPoemCompleteViewModel[] Items)>> GetSimilarPoems(PagingParameterModel paging, string metre, string rhyme, int? poetId);
|
||||
|
||||
/// <summary>
|
||||
/// Get Poem sections based on poem format
|
||||
/// </summary>
|
||||
/// <param name="paging"></param>
|
||||
/// <param name="format"></param>
|
||||
/// <param name="poetId"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorPoemCompleteViewModel[] Items)>> GetPoemSectionsByPoemFormat(PagingParameterModel paging, GanjoorPoemFormat format, int? poetId);
|
||||
|
||||
/// <summary>
|
||||
/// language tagged poem sections
|
||||
/// </summary>
|
||||
|
||||
@ -2515,6 +2515,77 @@ namespace RMuseum.Services.Implementation
|
||||
await QueryablePaginator<GanjoorPoemCompleteViewModel>.Paginate(source, paging);
|
||||
|
||||
|
||||
Dictionary<int, GanjoorPoetCompleteViewModel> cachedPoets = new Dictionary<int, GanjoorPoetCompleteViewModel>();
|
||||
|
||||
foreach (var item in paginatedResult.Items)
|
||||
{
|
||||
if (cachedPoets.TryGetValue(item.Category.Poet.Id, out GanjoorPoetCompleteViewModel poet))
|
||||
{
|
||||
item.Category = poet;
|
||||
}
|
||||
else
|
||||
{
|
||||
poet = (await GetPoetById(item.Category.Poet.Id)).Result;
|
||||
|
||||
cachedPoets.Add(item.Category.Poet.Id, poet);
|
||||
|
||||
item.Category = poet;
|
||||
}
|
||||
}
|
||||
|
||||
return new RServiceResult<(PaginationMetadata PagingMeta, GanjoorPoemCompleteViewModel[] Items)>(paginatedResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Poem sections based on poem format
|
||||
/// </summary>
|
||||
/// <param name="paging"></param>
|
||||
/// <param name="format"></param>
|
||||
/// <param name="poetId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorPoemCompleteViewModel[] Items)>> GetPoemSectionsByPoemFormat(PagingParameterModel paging, GanjoorPoemFormat format, int? poetId)
|
||||
{
|
||||
var source =
|
||||
_context.GanjoorPoemSections.Include(s => s.Poem).Include(s => s.Poet).Include(s => s.GanjoorMetre)
|
||||
.Where(s =>
|
||||
(poetId == null || s.PoetId == poetId)
|
||||
&&
|
||||
s.PoemFormat == format
|
||||
)
|
||||
.OrderBy(p => p.Poet.BirthYearInLHijri).ThenBy(p => p.Poet.Nickname).ThenBy(p => p.SectionType).ThenBy(p => p.Poem.Id)
|
||||
.Select
|
||||
(
|
||||
section =>
|
||||
new GanjoorPoemCompleteViewModel()
|
||||
{
|
||||
Id = section.Poem.Id,
|
||||
Title = section.Poem.Title,
|
||||
FullTitle = section.Poem.FullTitle,
|
||||
FullUrl = section.CachedFirstCoupletIndex == 0 ? section.Poem.FullUrl : section.Poem.FullUrl + "#bn" + (section.CachedFirstCoupletIndex + 1).ToString(),
|
||||
UrlSlug = section.Poem.UrlSlug,
|
||||
HtmlText = section.HtmlText,
|
||||
PlainText = section.PlainText,
|
||||
MixedModeOrder = section.Poem.MixedModeOrder,
|
||||
Published = section.Poem.Published,
|
||||
Language = section.Poem.Language,
|
||||
PoemSummary = section.Poem.PoemSummary,
|
||||
Category = new GanjoorPoetCompleteViewModel()
|
||||
{
|
||||
Poet = new GanjoorPoetViewModel()
|
||||
{
|
||||
Id = section.Poet.Id,
|
||||
}
|
||||
},
|
||||
SectionIndex = section.Index
|
||||
|
||||
}
|
||||
).AsNoTracking();
|
||||
|
||||
|
||||
(PaginationMetadata PagingMeta, GanjoorPoemCompleteViewModel[] Items) paginatedResult =
|
||||
await QueryablePaginator<GanjoorPoemCompleteViewModel>.Paginate(source, paging);
|
||||
|
||||
|
||||
Dictionary<int, GanjoorPoetCompleteViewModel> cachedPoets = new Dictionary<int, GanjoorPoetCompleteViewModel>();
|
||||
|
||||
foreach (var item in paginatedResult.Items)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user