docs: #319 API for moderating section corrections (only prosody meters)
This commit is contained in:
parent
efc382a1cb
commit
020e108ae3
@ -2863,6 +2863,34 @@ namespace RMuseum.Controllers
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// moderate poem section correction
|
||||
/// </summary>
|
||||
/// <param name="correction"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("section/moderate")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoemSectionCorrectionViewModel))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> ModeratePoemSectionCorrection([FromBody] GanjoorPoemSectionCorrectionViewModel correction)
|
||||
{
|
||||
if (ReadOnlyMode)
|
||||
return BadRequest("سایت به دلایل فنی مثل انتقال سرور موقتاً در حالت فقط خواندنی قرار دارد. لطفاً ساعاتی دیگر مجدداً تلاش کنید.");
|
||||
|
||||
Guid userId =
|
||||
new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
|
||||
|
||||
RServiceResult<GanjoorPoemSectionCorrectionViewModel> res =
|
||||
await _ganjoorService.ModeratePoemSectionCorrection(userId, correction);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
if (res.Result == null)
|
||||
return NotFound();
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// readonly mode
|
||||
|
||||
@ -1727,6 +1727,13 @@
|
||||
<param name="correction"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.ModeratePoemSectionCorrection(RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemSectionCorrectionViewModel)">
|
||||
<summary>
|
||||
moderate poem section correction
|
||||
</summary>
|
||||
<param name="correction"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:RMuseum.Controllers.GanjoorController.ReadOnlyMode">
|
||||
<summary>
|
||||
readonly mode
|
||||
@ -12361,6 +12368,14 @@
|
||||
<param name="correction"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.ModeratePoemSectionCorrection(System.Guid,RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemSectionCorrectionViewModel)">
|
||||
<summary>
|
||||
moderate poem section correction
|
||||
</summary>
|
||||
<param name="userId"></param>
|
||||
<param name="moderation"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:RMuseum.Services.IGanjoorTranslationService">
|
||||
<summary>
|
||||
translation service implementation
|
||||
@ -13917,6 +13932,14 @@
|
||||
<param name="moderation"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.ModeratePoemSectionCorrection(System.Guid,RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemSectionCorrectionViewModel)">
|
||||
<summary>
|
||||
moderate poem section correction
|
||||
</summary>
|
||||
<param name="userId"></param>
|
||||
<param name="moderation"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetLastUnreviewedUserCorrectionForSection(System.Guid,System.Int32)">
|
||||
<summary>
|
||||
last unreviewed user correction for a section
|
||||
|
||||
@ -956,5 +956,14 @@ namespace RMuseum.Services
|
||||
/// <param name="correction"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorPoemSectionCorrectionViewModel>> SuggestPoemSectionCorrection(GanjoorPoemSectionCorrectionViewModel correction);
|
||||
|
||||
/// <summary>
|
||||
/// moderate poem section correction
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="moderation"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorPoemSectionCorrectionViewModel>> ModeratePoemSectionCorrection(Guid userId,
|
||||
GanjoorPoemSectionCorrectionViewModel moderation);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ using RMuseum.Models.Ganjoor.ViewModels;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using RSecurityBackend.Services.Implementation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@ -17,6 +16,144 @@ namespace RMuseum.Services.Implementation
|
||||
/// </summary>
|
||||
public partial class GanjoorService : IGanjoorService
|
||||
{
|
||||
/// <summary>
|
||||
/// moderate poem section correction
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="moderation"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<GanjoorPoemSectionCorrectionViewModel>> ModeratePoemSectionCorrection(Guid userId,
|
||||
GanjoorPoemSectionCorrectionViewModel moderation)
|
||||
{
|
||||
var dbCorrection = await _context.GanjoorPoemSectionCorrections.Include(c => c.User)
|
||||
.Where(c => c.Id == moderation.Id)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (dbCorrection == null)
|
||||
return new RServiceResult<GanjoorPoemSectionCorrectionViewModel>(null);
|
||||
|
||||
dbCorrection.ReviewerUserId = userId;
|
||||
dbCorrection.ReviewDate = DateTime.Now;
|
||||
dbCorrection.ApplicationOrder = await _context.GanjoorPoemSectionCorrections.Where(c => c.Reviewed).AnyAsync() ? 1 + await _context.GanjoorPoemSectionCorrections.Where(c => c.Reviewed).MaxAsync(c => c.ApplicationOrder) : 1;
|
||||
dbCorrection.Reviewed = true;
|
||||
dbCorrection.AffectedThePoem = false;
|
||||
dbCorrection.ReviewNote = moderation.ReviewNote;
|
||||
|
||||
var editingSectionNotTracked = await _context.GanjoorPoemSections.AsNoTracking().Include(p => p.GanjoorMetre).Where(p => p.Id == moderation.SectionId).SingleOrDefaultAsync();
|
||||
|
||||
editingSectionNotTracked.OldGanjoorMetreId = editingSectionNotTracked.GanjoorMetreId;
|
||||
editingSectionNotTracked.OldRhymeLetters = editingSectionNotTracked.RhymeLetters;
|
||||
|
||||
var sections = await _context.GanjoorPoemSections.Where(p => p.PoemId == editingSectionNotTracked.PoemId).ToListAsync();
|
||||
|
||||
|
||||
if (dbCorrection.Rhythm != null)
|
||||
{
|
||||
if (moderation.RhythmResult == CorrectionReviewResult.NotReviewed)
|
||||
return new RServiceResult<GanjoorPoemSectionCorrectionViewModel>(null, "تغییرات وزن بررسی نشده است.");
|
||||
dbCorrection.RhythmResult = moderation.RhythmResult;
|
||||
if (dbCorrection.RhythmResult == CorrectionReviewResult.Approved)
|
||||
{
|
||||
dbCorrection.AffectedThePoem = true;
|
||||
if (moderation.Rhythm == "")
|
||||
{
|
||||
editingSectionNotTracked.GanjoorMetreId = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var metre = await _context.GanjoorMetres.AsNoTracking().Where(m => m.Rhythm == moderation.Rhythm).SingleOrDefaultAsync();
|
||||
if (metre == null)
|
||||
{
|
||||
metre = new GanjoorMetre()
|
||||
{
|
||||
Rhythm = moderation.Rhythm,
|
||||
VerseCount = 0
|
||||
};
|
||||
_context.GanjoorMetres.Add(metre);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
editingSectionNotTracked.GanjoorMetreId = metre.Id;
|
||||
}
|
||||
|
||||
editingSectionNotTracked.Modified = editingSectionNotTracked.OldGanjoorMetreId != editingSectionNotTracked.GanjoorMetreId;
|
||||
|
||||
foreach (var section in sections.Where(s => s.GanjoorMetreRefSectionIndex == editingSectionNotTracked.Index || s.Id == editingSectionNotTracked.Id))
|
||||
{
|
||||
section.GanjoorMetreId = editingSectionNotTracked.GanjoorMetreId;
|
||||
section.Modified = editingSectionNotTracked.Modified;
|
||||
_context.Update(section);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_context.GanjoorPoemSectionCorrections.Update(dbCorrection);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var dbPoem = await _context.GanjoorPoems.AsNoTracking().Where(p => p.Id == editingSectionNotTracked.PoemId).SingleAsync();
|
||||
|
||||
await _notificationService.PushNotification(dbCorrection.UserId,
|
||||
"بررسی ویرایش پیشنهادی شما",
|
||||
$"با سپاس از زحمت و همت شما ویرایش پیشنهادیتان برای <a href=\"{dbPoem.FullUrl}\" target=\"_blank\">{dbPoem.FullTitle}</a> بررسی شد.{Environment.NewLine}" +
|
||||
$"جهت مشاهدهٔ نتیجهٔ بررسی در میز کاربری خود بخش «ویرایشهای من» را مشاهده بفرمایید.{Environment.NewLine}"
|
||||
);
|
||||
|
||||
foreach (var section in sections)
|
||||
{
|
||||
if (section.Modified)
|
||||
{
|
||||
if (section.OldGanjoorMetreId != section.GanjoorMetreId || section.OldRhymeLetters != section.RhymeLetters)
|
||||
{
|
||||
_backgroundTaskQueue.QueueBackgroundWorkItem
|
||||
(
|
||||
async token =>
|
||||
{
|
||||
using (RMuseumDbContext inlineContext = new RMuseumDbContext(new DbContextOptions<RMuseumDbContext>())) //this is long running job, so context might be already been freed/collected by GC
|
||||
{
|
||||
if (section.OldGanjoorMetreId != null && !string.IsNullOrEmpty(section.OldRhymeLetters))
|
||||
{
|
||||
LongRunningJobProgressServiceEF jobProgressServiceEF = new LongRunningJobProgressServiceEF(inlineContext);
|
||||
var job = (await jobProgressServiceEF.NewJob($"بازسازی فهرست بخشهای مرتبط", $"M: {section.OldGanjoorMetreId}, G: {section.OldRhymeLetters}")).Result;
|
||||
|
||||
try
|
||||
{
|
||||
await _UpdateRelatedSections(inlineContext, (int)section.OldGanjoorMetreId, section.OldRhymeLetters);
|
||||
await inlineContext.SaveChangesAsync();
|
||||
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
if (section.GanjoorMetreId != null && !string.IsNullOrEmpty(section.RhymeLetters))
|
||||
{
|
||||
LongRunningJobProgressServiceEF jobProgressServiceEF = new LongRunningJobProgressServiceEF(inlineContext);
|
||||
var job = (await jobProgressServiceEF.NewJob($"بازسازی فهرست بخشهای مرتبط", $"M: {section.GanjoorMetreId}, G: {section.RhymeLetters}")).Result;
|
||||
|
||||
try
|
||||
{
|
||||
await _UpdateRelatedSections(inlineContext, (int)section.GanjoorMetreId, section.RhymeLetters);
|
||||
await inlineContext.SaveChangesAsync();
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, exp.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new RServiceResult<GanjoorPoemSectionCorrectionViewModel>(moderation);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// last unreviewed user correction for a section
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user