#217 api for retrieving couplet numbers
This commit is contained in:
parent
8600b0be94
commit
7d19980fe0
@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using RMuseum.Models.Auth.Memory;
|
||||
using RMuseum.Models.Ganjoor;
|
||||
using RMuseum.Models.Ganjoor.ViewModels;
|
||||
using RMuseum.Services;
|
||||
using RSecurityBackend.Models.Auth.Memory;
|
||||
using System.Collections.Generic;
|
||||
@ -82,6 +83,24 @@ namespace RMuseum.Controllers
|
||||
return Ok(combined);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get all numbering patterns for a couplet
|
||||
/// </summary>
|
||||
/// <param name="poemId"></param>
|
||||
/// <param name="coupletIndex"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("couplet/{poemId}/{coupletId}")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorCoupletNumberViewModel[]))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public async Task<IActionResult> GetNumberingsForCouplet(int poemId, int coupletIndex)
|
||||
{
|
||||
var res = await _numberingService.GetNumberingsForCouplet(poemId, coupletIndex);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// add new numbering
|
||||
/// </summary>
|
||||
|
||||
@ -0,0 +1,23 @@
|
||||
namespace RMuseum.Models.Ganjoor.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// Ganjoor Couplet Number View Model
|
||||
/// </summary>
|
||||
public class GanjoorCoupletNumberViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// name
|
||||
/// </summary>
|
||||
public string NumberingName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// number
|
||||
/// </summary>
|
||||
public int CoupletNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// total couplets
|
||||
/// </summary>
|
||||
public int TotalCouplets { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1401,6 +1401,14 @@
|
||||
<param name="id">category id</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.NumberingController.GetNumberingsForCouplet(System.Int32,System.Int32)">
|
||||
<summary>
|
||||
get all numbering patterns for a couplet
|
||||
</summary>
|
||||
<param name="poemId"></param>
|
||||
<param name="coupletIndex"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.NumberingController.AddNumberingAsync(RMuseum.Models.Ganjoor.GanjoorNumbering)">
|
||||
<summary>
|
||||
add new numbering
|
||||
@ -6082,6 +6090,26 @@
|
||||
couplet summary
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RMuseum.Models.Ganjoor.ViewModels.GanjoorCoupletNumberViewModel">
|
||||
<summary>
|
||||
Ganjoor Couplet Number View Model
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorCoupletNumberViewModel.NumberingName">
|
||||
<summary>
|
||||
name
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorCoupletNumberViewModel.CoupletNumber">
|
||||
<summary>
|
||||
number
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorCoupletNumberViewModel.TotalCouplets">
|
||||
<summary>
|
||||
total couplets
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RMuseum.Models.Ganjoor.ViewModels.GanjooRhymeAnalysisResult">
|
||||
<summary>
|
||||
Rhyme Analysis Result
|
||||
@ -8343,6 +8371,14 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorNumberingService.GetNumberingsForCouplet(System.Int32,System.Int32)">
|
||||
<summary>
|
||||
get all numbering patterns for a couplet
|
||||
</summary>
|
||||
<param name="poemId"></param>
|
||||
<param name="coupletIndex"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorNumberingService.Recount(System.Int32)">
|
||||
<summary>
|
||||
start counting
|
||||
@ -10030,6 +10066,14 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorNumberingService.GetNumberingsForCouplet(System.Int32,System.Int32)">
|
||||
<summary>
|
||||
get all numbering patterns for a couplet
|
||||
</summary>
|
||||
<param name="poemId"></param>
|
||||
<param name="coupletIndex"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorNumberingService.Recount(System.Int32)">
|
||||
<summary>
|
||||
start counting
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using RMuseum.Models.Ganjoor;
|
||||
using RMuseum.Models.Ganjoor.ViewModels;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -55,6 +56,14 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorNumbering[]>> GetNumberingsForDirectSubCatsAsync(int parentCatId);
|
||||
|
||||
/// <summary>
|
||||
/// get all numbering patterns for a couplet
|
||||
/// </summary>
|
||||
/// <param name="poemId"></param>
|
||||
/// <param name="coupletIndex"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorCoupletNumberViewModel[]>> GetNumberingsForCouplet(int poemId, int coupletIndex);
|
||||
|
||||
/// <summary>
|
||||
/// start counting
|
||||
/// </summary>
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using RMuseum.DbContext;
|
||||
using RMuseum.Models.Ganjoor;
|
||||
using RMuseum.Models.Ganjoor.ViewModels;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using RSecurityBackend.Services;
|
||||
using RSecurityBackend.Services.Implementation;
|
||||
@ -157,6 +158,32 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get all numbering patterns for a couplet
|
||||
/// </summary>
|
||||
/// <param name="poemId"></param>
|
||||
/// <param name="coupletIndex"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<GanjoorCoupletNumberViewModel[]>> GetNumberingsForCouplet(int poemId, int coupletIndex)
|
||||
{
|
||||
return new RServiceResult<GanjoorCoupletNumberViewModel[]>
|
||||
(
|
||||
await _context.GanjoorVerseNumbers.Include(n => n.Numbering)
|
||||
.Where(n => n.PoemId == poemId && n.CoupletIndex == coupletIndex)
|
||||
.OrderBy(n => n.NumberingId)
|
||||
.Select
|
||||
(
|
||||
n =>
|
||||
new GanjoorCoupletNumberViewModel()
|
||||
{
|
||||
NumberingName = n.Numbering.Name,
|
||||
CoupletNumber = n.Number,
|
||||
TotalCouplets = n.Numbering.TotalCouplets
|
||||
}
|
||||
).ToArrayAsync()
|
||||
);
|
||||
}
|
||||
|
||||
private async Task<List<GanjoorCat>> _FindAllSubCategories(RMuseumDbContext context, int catId)
|
||||
{
|
||||
List<GanjoorCat> cats = new List<GanjoorCat>();
|
||||
@ -167,7 +194,7 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
var subCats = await _FindAllSubCategories(context, cat.Id);
|
||||
|
||||
if(subCats.Count > 0)
|
||||
if (subCats.Count > 0)
|
||||
{
|
||||
cats.AddRange(subCats);
|
||||
}
|
||||
@ -179,11 +206,11 @@ namespace RMuseum.Services.Implementation
|
||||
{
|
||||
var parents = await context.GanjoorCategories.AsNoTracking().Where(c => c.ParentId == startCat.ParentId && c.Id >= startCat.Id && c.Id <= endCatId).OrderBy(c => c.Id).ToListAsync();
|
||||
List<GanjoorCat> cats = new List<GanjoorCat>();
|
||||
foreach(GanjoorCat parentCat in parents)
|
||||
foreach (GanjoorCat parentCat in parents)
|
||||
{
|
||||
cats.Add(parentCat);
|
||||
var subCats = await _FindAllSubCategories(context, parentCat.Id);
|
||||
if(subCats.Count > 0)
|
||||
if (subCats.Count > 0)
|
||||
{
|
||||
cats.AddRange(subCats);
|
||||
}
|
||||
@ -194,7 +221,7 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
private async Task<List<GanjoorCat>> _FindTargetCategories(RMuseumDbContext context, GanjoorCat startCat, int? endCatId)
|
||||
{
|
||||
if(endCatId == null || startCat.Id == endCatId)
|
||||
if (endCatId == null || startCat.Id == endCatId)
|
||||
{
|
||||
List<GanjoorCat> cats = new List<GanjoorCat>();
|
||||
cats.Add(startCat);
|
||||
@ -244,7 +271,7 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 0, $"Counting:: {cat.Title}");
|
||||
|
||||
foreach(var poem in poems)
|
||||
foreach (var poem in poems)
|
||||
{
|
||||
totalVerseCount += await context.GanjoorVerses.Where(v => v.PoemId == poem.Id).CountAsync();
|
||||
var verses = await context.GanjoorVerses.AsNoTracking()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user