improving tagging with digital sources

This commit is contained in:
Hamid Reza Mohammadi 2025-03-20 10:14:04 +03:30
parent 88d4b81d28
commit 580ea1ef34
4 changed files with 54 additions and 19 deletions

View File

@ -4248,16 +4248,15 @@ namespace RMuseum.Controllers
/// tag category with source
/// </summary>
/// <param name="catId"></param>
/// <param name="sourceUrlSlug"></param>
/// <param name="source"></param>
/// <returns></returns>
[HttpPut("source/{catId}/{sourceUrlSlug}")]
[HttpPut("source/{catId}")]
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public IActionResult TagCategoryWithSource(int catId, string sourceUrlSlug)
public IActionResult TagCategoryWithSource(int catId, [FromBody]DigitalSource source)
{
_ganjoorService.TagCategoryWithSource(catId, sourceUrlSlug);
_ganjoorService.TagCategoryWithSource(catId, source);
return Ok();
}

View File

@ -2295,12 +2295,12 @@
<param name="sourceUrlSlug"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.TagCategoryWithSource(System.Int32,System.String)">
<member name="M:RMuseum.Controllers.GanjoorController.TagCategoryWithSource(System.Int32,RMuseum.Models.Ganjoor.DigitalSource)">
<summary>
tag category with source
</summary>
<param name="catId"></param>
<param name="sourceUrlSlug"></param>
<param name="source"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.UpdateDigitalSourcesStats">
@ -17447,12 +17447,12 @@
<param name="sourceUrlSlug"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.TagCategoryWithSource(System.Int32,System.String)">
<member name="M:RMuseum.Services.IGanjoorService.TagCategoryWithSource(System.Int32,RMuseum.Models.Ganjoor.DigitalSource)">
<summary>
tag with sources
</summary>
<param name="catId"></param>
<param name="sourceUrlSlug"></param>
<param name="source"></param>
</member>
<member name="M:RMuseum.Services.IGanjoorService.UpdateDigitalSourcesStats(System.Guid)">
<summary>
@ -19413,12 +19413,12 @@
<param name="sourceUrlSlug"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.TagCategoryWithSource(System.Int32,System.String)">
<member name="M:RMuseum.Services.Implementation.GanjoorService.TagCategoryWithSource(System.Int32,RMuseum.Models.Ganjoor.DigitalSource)">
<summary>
tag with sources
</summary>
<param name="catId"></param>
<param name="sourceUrlSlug"></param>
<param name="source"></param>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.UpdateDigitalSourcesStats(System.Guid)">
<summary>

View File

@ -1459,8 +1459,8 @@ namespace RMuseum.Services
/// tag with sources
/// </summary>
/// <param name="catId"></param>
/// <param name="sourceUrlSlug"></param>
void TagCategoryWithSource(int catId, string sourceUrlSlug);
/// <param name="source"></param>
void TagCategoryWithSource(int catId, DigitalSource source);
/// <summary>
/// update digital sources stats

View File

@ -10,6 +10,7 @@ using DNTPersianUtils.Core;
using System.Globalization;
using System.Threading.Tasks;
using RSecurityBackend.Models.Generic;
using System.Security.Cryptography.X509Certificates;
namespace RMuseum.Services.Implementation
{
@ -38,8 +39,8 @@ namespace RMuseum.Services.Implementation
/// tag with sources
/// </summary>
/// <param name="catId"></param>
/// <param name="sourceUrlSlug"></param>
public void TagCategoryWithSource(int catId, string sourceUrlSlug)
/// <param name="source"></param>
public void TagCategoryWithSource(int catId, DigitalSource source)
{
_backgroundTaskQueue.QueueBackgroundWorkItem
(
@ -48,7 +49,7 @@ namespace RMuseum.Services.Implementation
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($"TagCategoryWithSource(catId: {catId} - source:{sourceUrlSlug})", "Query data")).Result;
var job = (await jobProgressServiceEF.NewJob($"TagCategoryWithSource(catId: {catId} - source:{source.UrlSlug})", "Query data")).Result;
try
{
var pages = await context.GanjoorPages.AsNoTracking().Where(p => p.FullUrl.StartsWith("/sources/")).ToListAsync();
@ -87,10 +88,45 @@ namespace RMuseum.Services.Implementation
}
}
var digitalSource = await context.DigitalSources.Where(p => p.UrlSlug == sourceUrlSlug).SingleOrDefaultAsync();
var digitalSource = await context.DigitalSources.Where(p => p.UrlSlug == source.UrlSlug).SingleOrDefaultAsync();
if (digitalSource == null)
{
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, $"Digital source not found: {sourceUrlSlug}");
context.DigitalSources.Add
(
new DigitalSource()
{
UrlSlug = source.UrlSlug,
ShortName = source.ShortName,
FullName = source.FullName,
SourceType = source.SourceType,
CoupletsCount = 0,
}
);
var parentPage = await context.GanjoorPages.AsNoTracking().Where(p => p.UrlSlug == "sources").SingleAsync();
var newPageId = 1 + await context.GanjoorPages.MaxAsync(p => p.Id);
while (await context.GanjoorPoems.Where(p => p.Id == newPageId).AnyAsync())
newPageId++;
context.GanjoorPages.Add
(
new GanjoorPage()
{
Id = newPageId,
GanjoorPageType = GanjoorPageType.None,
Published = true,
PageOrder = -1,
Title = source.FullName,
FullTitle = $"{parentPage.FullTitle} » {source.FullName}",
FullUrl = $"{parentPage.FullUrl}/{source.UrlSlug}",
UrlSlug = source.UrlSlug,
HtmlText = $"<p>{source.FullName}</p>",
PostDate = DateTime.Now,
ParentId = parentPage.Id,
}
);
await context.SaveChangesAsync();
digitalSource = await context.DigitalSources.Where(p => p.UrlSlug == source.UrlSlug).SingleAsync();
}
List<int> catIdList = new List<int>
@ -107,7 +143,7 @@ namespace RMuseum.Services.Implementation
foreach (var poem in poems)
{
poem.SourceName = digitalSource.ShortName;
poem.SourceUrlSlug = sourceUrlSlug;
poem.SourceUrlSlug = source.UrlSlug;
context.Update(poem);
int coupletCount = await context.GanjoorVerses.AsNoTracking()