docs: API method for regenerating a category related sections

This commit is contained in:
Hamid Reza Mohammadi 2022-06-02 22:11:48 +04:30
parent e14543e1d3
commit 77cf61ff92
5 changed files with 98 additions and 9 deletions

View File

@ -2814,6 +2814,27 @@ namespace RMuseum.Controllers
return Ok();
}
/// <summary>
/// regenerate category related sections
/// </summary>
/// <param name="id">category id</param>
/// <returns></returns>
[HttpPut]
[Route("cat/{id}/regenrelatedsections")]
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public IActionResult StartRegeneratingCateoryRelatedSections(int id)
{
RServiceResult<bool> res =
_ganjoorService.StartRegeneratingCateoryRelatedSections(id);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
return Ok(res.Result);
}
/// <summary>
/// get a specific poem section
/// </summary>
@ -3098,6 +3119,8 @@ namespace RMuseum.Controllers
return Ok(res.Result.Items);
}
/// <summary>
/// readonly mode

View File

@ -1715,6 +1715,13 @@
<param name="rhyme"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.StartRegeneratingCateoryRelatedSections(System.Int32)">
<summary>
regenerate category related sections
</summary>
<param name="id">category id</param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.GetPoemSectionByIdAsync(System.Int32)">
<summary>
get a specific poem section
@ -12699,6 +12706,13 @@
<param name="paging"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.StartRegeneratingCateoryRelatedSections(System.Int32)">
<summary>
regenerate category related sections
</summary>
<param name="catId"></param>
<returns></returns>
</member>
<member name="T:RMuseum.Services.IGanjoorTranslationService">
<summary>
translation service implementation
@ -14459,6 +14473,13 @@
<param name="itemsCount">if sent 0 or less returns all items</param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.StartRegeneratingCateoryRelatedSections(System.Int32)">
<summary>
regenerate category related sections
</summary>
<param name="catId"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService._UpdateRelatedSections(RMuseum.DbContext.RMuseumDbContext,System.Int32,System.String)">
<summary>
update related sections info (after metreId or rhyme for one of these sections changes)

View File

@ -1023,5 +1023,13 @@ namespace RMuseum.Services
/// <param name="paging"></param>
/// <returns></returns>
Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorPoemSectionCorrectionViewModel[] Items)>> GetSectionEffectiveCorrections(int sectionId, PagingParameterModel paging);
/// <summary>
/// regenerate category related sections
/// </summary>
/// <param name="catId"></param>
/// <returns></returns>
RServiceResult<bool> StartRegeneratingCateoryRelatedSections(int catId);
}
}

View File

@ -376,15 +376,7 @@ namespace RMuseum.Services.Implementation
await context.SaveChangesAsync();
var updatePoemListId = await context.GanjoorPoems.AsNoTracking().Where(p => p.CatId == dbMainPoem.CatId && p.Id >= dbMainPoem.Id).Select(p => p.Id).ToListAsync();
foreach (var updatePoemId in updatePoemListId)
{
var sections = await context.GanjoorPoemSections.AsNoTracking().Where(s => s.PoemId == updatePoemId && s.GanjoorMetreId != null && !string.IsNullOrEmpty(s.RhymeLetters)).ToListAsync();
foreach (var section in sections)
{
await _UpdateRelatedSections(context, (int)section.GanjoorMetreId, section.RhymeLetters);
}
}
return new RServiceResult<int>(targetPoemId);

View File

@ -40,6 +40,51 @@ namespace RMuseum.Services.Implementation
);
}
/// <summary>
/// regenerate category related sections
/// </summary>
/// <param name="catId"></param>
/// <returns></returns>
public RServiceResult<bool> StartRegeneratingCateoryRelatedSections(int catId)
{
try
{
_backgroundTaskQueue.QueueBackgroundWorkItem
(
async token =>
{
using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions<RMuseumDbContext>())) //this is long running job, so _context might be already been freed/collected by GC
{
LongRunningJobProgressServiceEF jobProgressServiceEF = new LongRunningJobProgressServiceEF(context);
var job = (await jobProgressServiceEF.NewJob("StartRegeneratingCateoryRelatedSections", "Query data")).Result;
try
{
var updatePoemListId = await context.GanjoorPoems.AsNoTracking().Where(p => p.CatId == catId).Select(p => p.Id).ToListAsync();
foreach (var updatePoemId in updatePoemListId)
{
var sections = await context.GanjoorPoemSections.AsNoTracking().Where(s => s.PoemId == updatePoemId && s.GanjoorMetreId != null && !string.IsNullOrEmpty(s.RhymeLetters)).ToListAsync();
foreach (var section in sections)
{
await _UpdateRelatedSections(context, (int)section.GanjoorMetreId, section.RhymeLetters);
}
}
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
}
catch (Exception exp)
{
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, exp.ToString());
}
}
});
return new RServiceResult<bool>(true);
}
catch (Exception exp)
{
return new RServiceResult<bool>(false, exp.ToString());
}
}
/// <summary>