#413 extending similar api to cover language + poem format
This commit is contained in:
parent
0f7f91e776
commit
09348a8e02
@ -2385,6 +2385,8 @@ namespace RMuseum.Controllers
|
||||
/// <param name="metre">cannot be empty</param>
|
||||
/// <param name="rhyme">can be empty</param>
|
||||
/// <param name="poetId">send 0 for all</param>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="format"></param>
|
||||
/// <returns>return value is not complete or valid for some parts, you should use only the valid parts!</returns>
|
||||
|
||||
[HttpGet]
|
||||
@ -2393,9 +2395,9 @@ namespace RMuseum.Controllers
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable<GanjoorPoemCompleteViewModel>))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
|
||||
public async Task<IActionResult> GetSimilarPoems([FromQuery]PagingParameterModel paging, string metre, string rhyme, int poetId = 0)
|
||||
public async Task<IActionResult> GetSimilarPoems([FromQuery]PagingParameterModel paging, string metre, string rhyme, int poetId = 0, string language = "fa-IR", GanjoorPoemFormat format = GanjoorPoemFormat.Unknown)
|
||||
{
|
||||
var pagedResult = await _ganjoorService.GetSimilarPoems(paging, metre, rhyme, poetId == 0 ? (int?) null : poetId);
|
||||
var pagedResult = await _ganjoorService.GetSimilarPoems(paging, metre, rhyme, poetId == 0 ? (int?) null : poetId, language, format);
|
||||
if (!string.IsNullOrEmpty(pagedResult.ExceptionString))
|
||||
return BadRequest(pagedResult.ExceptionString);
|
||||
|
||||
@ -2430,29 +2432,6 @@ namespace RMuseum.Controllers
|
||||
return Ok(pagedResult.Result.Items);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Poem sections based on poem format
|
||||
/// </summary>
|
||||
/// <param name="paging"></param>
|
||||
/// <param name="format"></param>
|
||||
/// <param name="poetId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("sections/tagged/format")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable<GanjoorPoemCompleteViewModel>))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public async Task<IActionResult> GetPoemSectionsByPoemFormat([FromQuery] PagingParameterModel paging, GanjoorPoemFormat format, int poetId = 0)
|
||||
{
|
||||
var pagedResult = await _ganjoorService.GetPoemSectionsByPoemFormat(paging, format, poetId == 0 ? (int?)null : poetId);
|
||||
if (!string.IsNullOrEmpty(pagedResult.ExceptionString))
|
||||
return BadRequest(pagedResult.ExceptionString);
|
||||
|
||||
// Paging Header
|
||||
HttpContext.Response.Headers.Append("paging-headers", JsonConvert.SerializeObject(pagedResult.Result.PagingMeta));
|
||||
|
||||
return Ok(pagedResult.Result.Items);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// search
|
||||
|
||||
@ -1595,7 +1595,7 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetSimilarPoems(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.String,System.Int32)">
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetSimilarPoems(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.String,System.Int32,System.String,RMuseum.Models.Ganjoor.GanjoorPoemFormat)">
|
||||
<summary>
|
||||
Get Similar Poems accroding to prosody and rhyme informations
|
||||
</summary>
|
||||
@ -1603,6 +1603,8 @@
|
||||
<param name="metre">cannot be empty</param>
|
||||
<param name="rhyme">can be empty</param>
|
||||
<param name="poetId">send 0 for all</param>
|
||||
<param name="language"></param>
|
||||
<param name="format"></param>
|
||||
<returns>return value is not complete or valid for some parts, you should use only the valid parts!</returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetLanguageTaggedPoemSections(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.Int32)">
|
||||
@ -1614,15 +1616,6 @@
|
||||
<param name="poetId">0 means all poets</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetPoemSectionsByPoemFormat(RSecurityBackend.Models.Generic.PagingParameterModel,RMuseum.Models.Ganjoor.GanjoorPoemFormat,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.Controllers.GanjoorController.Search(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.Int32,System.Int32)">
|
||||
<summary>
|
||||
search
|
||||
@ -14408,7 +14401,7 @@
|
||||
<param name="paging"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.GetSimilarPoems(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.String,System.Nullable{System.Int32})">
|
||||
<member name="M:RMuseum.Services.IGanjoorService.GetSimilarPoems(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.String,System.Nullable{System.Int32},System.String,RMuseum.Models.Ganjoor.GanjoorPoemFormat)">
|
||||
<summary>
|
||||
Get Similar Poems accroding to prosody and rhyme informations
|
||||
</summary>
|
||||
@ -14416,15 +14409,8 @@
|
||||
<param name="metre"></param>
|
||||
<param name="rhyme"></param>
|
||||
<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="language"></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})">
|
||||
@ -17653,7 +17639,7 @@
|
||||
<param name="recitation"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetSimilarPoems(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.String,System.Nullable{System.Int32})">
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetSimilarPoems(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.String,System.Nullable{System.Int32},System.String,RMuseum.Models.Ganjoor.GanjoorPoemFormat)">
|
||||
<summary>
|
||||
Get Similar Poems accroding to prosody and rhyme informations
|
||||
</summary>
|
||||
@ -17661,15 +17647,8 @@
|
||||
<param name="metre"></param>
|
||||
<param name="rhyme"></param>
|
||||
<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="language"></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})">
|
||||
|
||||
@ -479,17 +479,10 @@ namespace RMuseum.Services
|
||||
/// <param name="metre"></param>
|
||||
/// <param name="rhyme"></param>
|
||||
/// <param name="poetId"></param>
|
||||
/// <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="language"></param>
|
||||
/// <param name="format"></param>
|
||||
/// <param name="poetId"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorPoemCompleteViewModel[] Items)>> GetPoemSectionsByPoemFormat(PagingParameterModel paging, GanjoorPoemFormat format, int? poetId);
|
||||
Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorPoemCompleteViewModel[] Items)>> GetSimilarPoems(PagingParameterModel paging, string metre, string rhyme, int? poetId, string language = "fa-IR", GanjoorPoemFormat format = GanjoorPoemFormat.Unknown);
|
||||
|
||||
/// <summary>
|
||||
/// language tagged poem sections
|
||||
|
||||
@ -2467,90 +2467,23 @@ namespace RMuseum.Services.Implementation
|
||||
/// <param name="metre"></param>
|
||||
/// <param name="rhyme"></param>
|
||||
/// <param name="poetId"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="format"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorPoemCompleteViewModel[] Items)>> GetSimilarPoems(PagingParameterModel paging, string metre, string rhyme, int? poetId)
|
||||
public async Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorPoemCompleteViewModel[] Items)>> GetSimilarPoems(PagingParameterModel paging, string metre, string rhyme, int? poetId, string language = "fa-IR", GanjoorPoemFormat format = GanjoorPoemFormat.Unknown)
|
||||
{
|
||||
var source =
|
||||
_context.GanjoorPoemSections.Include(s => s.Poem).Include(s => s.Poet).Include(s => s.GanjoorMetre)
|
||||
.Where(s =>
|
||||
(poetId == null || s.PoetId == poetId)
|
||||
&&
|
||||
(string.IsNullOrEmpty(s.Language) || s.Language == "fa-IR")
|
||||
((language == "fa-IR" && string.IsNullOrEmpty(s.Language)) || s.Language == language)
|
||||
&&
|
||||
(string.IsNullOrEmpty(metre) || (metre == "null" && s.GanjoorMetreId == null) || (!string.IsNullOrEmpty(metre) && s.GanjoorMetre.Rhythm == metre))
|
||||
&&
|
||||
((string.IsNullOrEmpty(rhyme) && s.SectionType == PoemSectionType.WholePoem) || (!string.IsNullOrEmpty(rhyme) && s.RhymeLetters == rhyme))
|
||||
)
|
||||
.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)
|
||||
{
|
||||
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
|
||||
(format == GanjoorPoemFormat.Unknown || s.PoemFormat == format)
|
||||
)
|
||||
.OrderBy(p => p.Poet.BirthYearInLHijri).ThenBy(p => p.Poet.Nickname).ThenBy(p => p.SectionType).ThenBy(p => p.Poem.Id)
|
||||
.Select
|
||||
@ -2606,6 +2539,7 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
return new RServiceResult<(PaginationMetadata PagingMeta, GanjoorPoemCompleteViewModel[] Items)>(paginatedResult);
|
||||
}
|
||||
|
||||
private async Task _populateCategoryChildren(int catId, List<int> catListId)
|
||||
{
|
||||
var catRes = await GetCatById(catId, false);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user