#437 mark naskban links a text original for a category

Related Work Items: #43
This commit is contained in:
Hamid Reza Mohammadi 2024-05-02 16:48:57 +03:30
parent 36f6435773
commit 74e69b4072
4 changed files with 102 additions and 0 deletions

View File

@ -3685,6 +3685,24 @@ namespace RMuseum.Controllers
return Ok();
}
/// <summary>
/// mark naskban links a text original for a category
/// </summary>
/// <param name="naskbanBookId"></param>
/// <param name="catId"></param>
/// <param name="textOriginal"></param>
/// <returns></returns>
[HttpPut("naskban/textoriginal/{naskbanBookId}/{catId}/{textOriginal}")]
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + RMuseumSecurableItem.ModerateOperationShortName)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public IActionResult MarkNaskbanLinksAsTextOriginal(int naskbanBookId, int catId, bool textOriginal)
{
_ganjoorService.MarkNaskbanLinksAsTextOriginal(naskbanBookId, catId, textOriginal);
return Ok();
}
/// <summary>
/// delete poem related naskban images by url
/// </summary>

View File

@ -2024,6 +2024,15 @@
<param name="humanReviewed"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.MarkNaskbanLinksAsTextOriginal(System.Int32,System.Int32,System.Boolean)">
<summary>
mark naskban links a text original for a category
</summary>
<param name="naskbanBookId"></param>
<param name="catId"></param>
<param name="textOriginal"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.DeletePoemRelatedNaskbanImagesByNaskbanUrlAsync(System.String)">
<summary>
delete poem related naskban images by url
@ -15982,6 +15991,14 @@
<param name="parentCatId"></param>
<param name="humanReviewed"></param>
</member>
<member name="M:RMuseum.Services.IGanjoorService.MarkNaskbanLinksAsTextOriginal(System.Int32,System.Int32,System.Boolean)">
<summary>
mark naskban links a text original for a category
</summary>
<param name="bookId"></param>
<param name="parentCatId"></param>
<param name="textOriginal"></param>
</member>
<member name="M:RMuseum.Services.IGanjoorService.DeletePoemRelatedNaskbanImagesByNaskbanUrlAsync(System.String)">
<summary>
delete poem related naskban images by url
@ -17954,6 +17971,14 @@
<param name="parentCatId"></param>
<param name="humanReviewed"></param>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.MarkNaskbanLinksAsTextOriginal(System.Int32,System.Int32,System.Boolean)">
<summary>
mark naskban links a text original for a category
</summary>
<param name="bookId"></param>
<param name="parentCatId"></param>
<param name="textOriginal"></param>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.DeletePoemRelatedNaskbanImagesByNaskbanUrlAsync(System.String)">
<summary>
delete poem related naskban images by url

View File

@ -1228,6 +1228,14 @@ namespace RMuseum.Services
/// <param name="humanReviewed"></param>
void MarkNaskbanLinksAsHumanReviewed(int bookId, int parentCatId, bool humanReviewed);
/// <summary>
/// mark naskban links a text original for a category
/// </summary>
/// <param name="bookId"></param>
/// <param name="parentCatId"></param>
/// <param name="textOriginal"></param>
void MarkNaskbanLinksAsTextOriginal(int bookId, int parentCatId, bool textOriginal);
/// <summary>
/// delete poem related naskban images by url
/// </summary>

View File

@ -197,6 +197,57 @@ namespace RMuseum.Services.Implementation
});
}
/// <summary>
/// mark naskban links a text original for a category
/// </summary>
/// <param name="bookId"></param>
/// <param name="parentCatId"></param>
/// <param name="textOriginal"></param>
public void MarkNaskbanLinksAsTextOriginal(int bookId, int parentCatId, bool textOriginal)
{
_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($"MarkNaskbanLinksAsTextOriginal(bookId: {bookId} - cat:{parentCatId})", "Query data")).Result;
try
{
List<int> catIdList = new List<int>
{
parentCatId
};
await _populateCategoryChildren(context, parentCatId, catIdList);
int poemCount = 0;
int progress = 0;
foreach (int catId in catIdList)
{
var poems = await context.GanjoorPoems.AsNoTracking().Where(p => p.CatId == catId).ToListAsync();
poemCount += poems.Count;
foreach (var poem in poems)
{
var naskbanLinks = await context.PinterestLinks.Where(l => l.GanjoorPostId == poem.Id && l.PDFBookId == bookId).ToListAsync();
foreach (var link in naskbanLinks)
{
link.IsTextOriginalSource = textOriginal;
context.Update(link);
}
await jobProgressServiceEF.UpdateJob(job.Id, progress, $"{progress} از {poemCount}");
}
}
}
catch (Exception exp)
{
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, exp.ToString());
}
}
});
}
/// <summary>
/// delete poem related naskban images by url
/// </summary>