#266 approving mistakes and recomputing recitation orders

This commit is contained in:
Hamid Reza Mohammadi 2021-12-23 12:26:02 +03:30
parent 0c7cc95920
commit c9c883cd23
3 changed files with 95 additions and 2 deletions

View File

@ -858,7 +858,7 @@ namespace RMuseum.Controllers
}
/// <summary>
/// accepts a reported error for recitations and notify the reporter and recitation owner (and deletes the report)
/// accepts a reported error for recitations, change status of the recitation to rejected and notify the reporter and recitation owner (and deletes the report)
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
@ -885,6 +885,34 @@ namespace RMuseum.Controllers
return Ok();
}
/// <summary>
/// accepts a reported error for recitations, add mistake to approve the mistake and notify the reporter and recitation owner (and deletes the report)
/// </summary>
/// <param name="report"></param>
/// <returns></returns>
[HttpPut]
[Route("errors/report/save")]
[Authorize(Policy = RMuseumSecurableItem.AudioRecitationEntityShortName + ":" + RMuseumSecurableItem.PublishOperationShortName)]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(int))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
public async Task<IActionResult> AddReportToTheApprovedMistakesAsync([FromBody] RecitationErrorReportViewModel report)
{
if (ReadOnlyMode)
return BadRequest("سایت به دلایل فنی مثل انتقال سرور موقتاً در حالت فقط خواندنی قرار دارد. لطفاً ساعاتی دیگر مجدداً تلاش کنید.");
RServiceResult<bool> res = await _audioService.AddReportToTheApprovedMistakesAsync(report);
if (!string.IsNullOrEmpty(res.ExceptionString))
{
return BadRequest(res.ExceptionString);
}
if (!res.Result)
{
return NotFound();
}
return Ok();
}
/// <summary>
/// up vote a recitation
/// </summary>

View File

@ -225,12 +225,19 @@ namespace RMuseum.Services
Task<RServiceResult<bool>> RejectReportedErrorAsync(int id, string rejectionNote = "عدم تطابق با معیارهای حذف خوانش");
/// <summary>
/// accepts a reported error for recitations and notify the reporter and recitation owner (and deletes the report)
/// accepts a reported error for recitations, change status of the recitation to rejected and notify the reporter and recitation owner (and deletes the report)
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<RServiceResult<bool>> AcceptReportedErrorAsync(int id);
/// <summary>
/// accepts a reported error for recitations, add mistake to approve the mistake and notify the reporter and recitation owner (and deletes the report)
/// </summary>
/// <param name="report"></param>
/// <returns></returns>
Task<RServiceResult<bool>> AddReportToTheApprovedMistakesAsync(RecitationErrorReportViewModel report);
/// <summary>
/// compute poem recitations order
/// </summary>

View File

@ -1873,6 +1873,64 @@ namespace RMuseum.Services.Implementationa
}
}
/// <summary>
/// accepts a reported error for recitations, add mistake to approve the mistake and notify the reporter and recitation owner (and deletes the report)
/// </summary>
/// <param name="report"></param>
/// <returns></returns>
public async Task<RServiceResult<bool>> AddReportToTheApprovedMistakesAsync(RecitationErrorReportViewModel report)
{
try
{
var dbReport = await _context.RecitationErrorReports.Where(r => r.Id == r.Id).SingleAsync();
var recitation = await _context.Recitations.AsNoTracking().Where(r => r.Id == dbReport.RecitationId).SingleAsync();
var mistake = new RecitationApprovedMistake()
{
RecitationId = recitation.Id,
Mistake = report.ReasonText,
NumberOfLinesAffected = report.NumberOfLinesAffected,
CoupletIndex = report.CoupletIndex
};
_context.RecitationApprovedMistakes.Add(mistake);
var reporterUserId = dbReport.ReporterId;
_context.RecitationErrorReports.Remove(dbReport);
await _context.SaveChangesAsync();
if (reporterUserId != null)
{
await _notificationService.PushNotification
(
(Guid)reporterUserId,
"پذیرش گزارش خطای خوانش",
$"گزارش خطای ارسالی شما برای خوانش {recitation.AudioTitle} از {recitation.AudioArtist} بررسی شد و مورد پذیرش قرار گرفت.{Environment.NewLine}" +
$"خوانش یاد شده از حالت انتشار خارج شده است."
);
}
await _notificationService.PushNotification
(
recitation.OwnerId,
"تأیید خطای خوانش ارسالی",
$"خطایی در خوانش {recitation.AudioTitle} از {recitation.AudioArtist} گزارش و تأیید شده است.{Environment.NewLine}" +
$"اشکال گزارش شده: {dbReport.ReasonText}{Environment.NewLine}" +
$"لطفاً بررسی بفرمایید."
);
await ComputePoemRecitationsOrdersAsync(recitation.GanjoorPostId);
return new RServiceResult<bool>(true);
}
catch (Exception exp)
{
return new RServiceResult<bool>(false, exp.ToString());
}
}
/// <summary>
/// compute poem recitations order
/// </summary>