docs: #305 API for tagging GanjoorLinks as IsTextOriginalSource
This commit is contained in:
parent
97f44328f3
commit
35112666b0
@ -2048,6 +2048,33 @@ namespace RMuseum.Controllers
|
||||
return Ok(pagedResult.Result.Items);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// start setting an artifact items as a category poems text original source
|
||||
/// </summary>
|
||||
/// <param name="ganjoorCatId"></param>
|
||||
/// <param name="artifactId"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpPut("ganjoorlink/settextorigin/{ganjoorCatId}/{artifactId}")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.ArtifactEntityShortName + ":" + RMuseumSecurableItem.ReviewGanjoorLinksOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.Unauthorized)]
|
||||
public IActionResult StartSettingArtifactAsTextOriginalSource(int ganjoorCatId, Guid artifactId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var res = _artifactService.StartSettingArtifactAsTextOriginalSource(ganjoorCatId, artifactId);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return BadRequest(exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// readonly mode
|
||||
/// </summary>
|
||||
|
||||
@ -618,6 +618,14 @@
|
||||
<param name="term"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.ArtifactController.StartSettingArtifactAsTextOriginalSource(System.Int32,System.Guid)">
|
||||
<summary>
|
||||
start setting an artifact items as a category poems text original source
|
||||
</summary>
|
||||
<param name="ganjoorCatId"></param>
|
||||
<param name="artifactId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:RMuseum.Controllers.ArtifactController.ReadOnlyMode">
|
||||
<summary>
|
||||
readonly mode
|
||||
@ -10346,6 +10354,14 @@
|
||||
<param name="term"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IArtifactService.StartSettingArtifactAsTextOriginalSource(System.Int32,System.Guid)">
|
||||
<summary>
|
||||
start setting an artifact items as text original source
|
||||
</summary>
|
||||
<param name="ganjoorCatId"></param>
|
||||
<param name="artifactId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:RMuseum.Services.IDonationService">
|
||||
<summary>
|
||||
donation service
|
||||
@ -11633,6 +11649,9 @@
|
||||
<summary>
|
||||
IArtifactService implementation
|
||||
</summary>
|
||||
<summary>
|
||||
IArtifactService implementation
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.ArtifactService.StartFillingGanjoorLinkOriginalSources">
|
||||
<summary>
|
||||
@ -11740,6 +11759,14 @@
|
||||
<param name="friendlyUrl">golestan-walters-01</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.ArtifactService.StartSettingArtifactAsTextOriginalSource(System.Int32,System.Guid)">
|
||||
<summary>
|
||||
start setting an artifact items as text original source
|
||||
</summary>
|
||||
<param name="ganjoorCatId"></param>
|
||||
<param name="artifactId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.ArtifactService.StartRemovingOriginalImages">
|
||||
<summary>
|
||||
start removing original images
|
||||
|
||||
@ -579,5 +579,13 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<(PaginationMetadata PagingMeta, RArtifactItemRecordViewModel[] Items)>> SearchArtifactItems(PagingParameterModel paging, string term);
|
||||
|
||||
/// <summary>
|
||||
/// start setting an artifact items as text original source
|
||||
/// </summary>
|
||||
/// <param name="ganjoorCatId"></param>
|
||||
/// <param name="artifactId"></param>
|
||||
/// <returns></returns>
|
||||
RServiceResult<bool> StartSettingArtifactAsTextOriginalSource(int ganjoorCatId, Guid artifactId);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,93 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using RMuseum.DbContext;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using RSecurityBackend.Services.Implementation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RMuseum.Services.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// IArtifactService implementation
|
||||
/// </summary>
|
||||
public partial class ArtifactService : IArtifactService
|
||||
{
|
||||
/// <summary>
|
||||
/// start setting an artifact items as text original source
|
||||
/// </summary>
|
||||
/// <param name="ganjoorCatId"></param>
|
||||
/// <param name="artifactId"></param>
|
||||
/// <returns></returns>
|
||||
public RServiceResult<bool> StartSettingArtifactAsTextOriginalSource(int ganjoorCatId, Guid artifactId)
|
||||
{
|
||||
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($"SettingArtifactAsTextOriginalSource({ganjoorCatId}, {artifactId})", "Query Poems Data")).Result;
|
||||
|
||||
try
|
||||
{
|
||||
List<int> poemIdSet = new List<int>();
|
||||
await _EnumerateGanjoorCatPoemIdSet(context, poemIdSet, ganjoorCatId);
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 0, "Query Links Data");
|
||||
var links = await context.GanjoorLinks.Where(l => l.ArtifactId == artifactId).ToListAsync();
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 0, "Removing Old Originals");
|
||||
foreach (var poemId in poemIdSet)
|
||||
{
|
||||
var poemLinks = await context.GanjoorLinks.Where(l => l.GanjoorPostId == poemId && l.IsTextOriginalSource == true).ToListAsync();
|
||||
foreach (var poemLink in poemLinks)
|
||||
{
|
||||
poemLink.IsTextOriginalSource = false;
|
||||
context.Update(poemLink);
|
||||
}
|
||||
}
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 0, "Updating");
|
||||
foreach (var link in links)
|
||||
{
|
||||
if(poemIdSet.Where(p => p == link.GanjoorPostId).Any())
|
||||
{
|
||||
link.IsTextOriginalSource = true;
|
||||
context.Update(link);
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
private async Task _EnumerateGanjoorCatPoemIdSet(RMuseumDbContext context, List<int> poemIdSet, int catId)
|
||||
{
|
||||
var catPoemIdSets = await context.GanjoorPoems.AsNoTracking().Where(p => p.CatId == catId).Select(p => p.Id).ToListAsync();
|
||||
if (catPoemIdSets.Count > 0)
|
||||
poemIdSet.AddRange(catPoemIdSets);
|
||||
var subCatIdSet = await context.GanjoorCategories.AsNoTracking().Where(c => c.ParentId == catId).Select(c => c.Id).ToListAsync();
|
||||
foreach (var subCatId in subCatIdSet)
|
||||
{
|
||||
await _EnumerateGanjoorCatPoemIdSet(context, poemIdSet, subCatId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user