docs: #319 API for suggesting a correction for a section (mainly a prosody meter)
This commit is contained in:
parent
7b8ab40b9d
commit
efc382a1cb
@ -2835,6 +2835,34 @@ namespace RMuseum.Controllers
|
||||
return Ok(res.Result);//might be null
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// send a correction for a section
|
||||
/// </summary>
|
||||
/// <param name="correction"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("section/correction")]
|
||||
[Authorize]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoemSectionCorrectionViewModel))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> SuggestPoemSectionCorrection([FromBody] GanjoorPoemSectionCorrectionViewModel correction)
|
||||
{
|
||||
if (ReadOnlyMode)
|
||||
return BadRequest("سایت به دلایل فنی مثل انتقال سرور موقتاً در حالت فقط خواندنی قرار دارد. لطفاً ساعاتی دیگر مجدداً تلاش کنید.");
|
||||
|
||||
correction.UserId =
|
||||
new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
|
||||
|
||||
RServiceResult<GanjoorPoemSectionCorrectionViewModel> res =
|
||||
await _ganjoorService.SuggestPoemSectionCorrection(correction);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
if (res.Result == null)
|
||||
return NotFound();
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// readonly mode
|
||||
|
||||
@ -1720,6 +1720,13 @@
|
||||
<param name="id">section id</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.SuggestPoemSectionCorrection(RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemSectionCorrectionViewModel)">
|
||||
<summary>
|
||||
send a correction for a section
|
||||
</summary>
|
||||
<param name="correction"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:RMuseum.Controllers.GanjoorController.ReadOnlyMode">
|
||||
<summary>
|
||||
readonly mode
|
||||
@ -12347,6 +12354,13 @@
|
||||
<param name="sectionId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.SuggestPoemSectionCorrection(RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemSectionCorrectionViewModel)">
|
||||
<summary>
|
||||
send a correction for a section
|
||||
</summary>
|
||||
<param name="correction"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:RMuseum.Services.IGanjoorTranslationService">
|
||||
<summary>
|
||||
translation service implementation
|
||||
@ -13911,6 +13925,13 @@
|
||||
<param name="sectionId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.SuggestPoemSectionCorrection(RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemSectionCorrectionViewModel)">
|
||||
<summary>
|
||||
send a correction for a section
|
||||
</summary>
|
||||
<param name="correction"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.StartUpdatingMundexPage(System.Guid)">
|
||||
<summary>
|
||||
start updating stats page
|
||||
|
||||
@ -949,5 +949,12 @@ namespace RMuseum.Services
|
||||
/// <param name="sectionId"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorPoemSectionCorrectionViewModel>> GetLastUnreviewedUserCorrectionForSection(Guid userId, int sectionId);
|
||||
|
||||
/// <summary>
|
||||
/// send a correction for a section
|
||||
/// </summary>
|
||||
/// <param name="correction"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorPoemSectionCorrectionViewModel>> SuggestPoemSectionCorrection(GanjoorPoemSectionCorrectionViewModel correction);
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,5 +63,56 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// send a correction for a section
|
||||
/// </summary>
|
||||
/// <param name="correction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<GanjoorPoemSectionCorrectionViewModel>> SuggestPoemSectionCorrection(GanjoorPoemSectionCorrectionViewModel correction)
|
||||
{
|
||||
try
|
||||
{
|
||||
var preCorrections = await _context.GanjoorPoemSectionCorrections
|
||||
.Where(c => c.UserId == correction.UserId && c.SectionId == correction.SectionId && c.Reviewed == false)
|
||||
.ToListAsync();
|
||||
|
||||
|
||||
GanjoorPoemSectionCorrection dbCorrection = new GanjoorPoemSectionCorrection()
|
||||
{
|
||||
SectionId = correction.SectionId,
|
||||
UserId = correction.UserId,
|
||||
Rhythm = correction.Rhythm,
|
||||
RhythmResult = CorrectionReviewResult.NotReviewed,
|
||||
BreakFromVerse1VOrder = correction.BreakFromVerse1VOrder,
|
||||
BreakFromVerse1VOrderResult = CorrectionReviewResult.NotReviewed,
|
||||
BreakFromVerse2VOrder = correction.BreakFromVerse2VOrder,
|
||||
BreakFromVerse2VOrderResult = CorrectionReviewResult.NotReviewed,
|
||||
BreakFromVerse3VOrder = correction.BreakFromVerse3VOrder,
|
||||
BreakFromVerse3VOrderResult = CorrectionReviewResult.NotReviewed,
|
||||
BreakFromVerse4VOrder = correction.BreakFromVerse4VOrder,
|
||||
BreakFromVerse4VOrderResult = CorrectionReviewResult.NotReviewed,
|
||||
Note = correction.Note,
|
||||
Date = DateTime.Now,
|
||||
Reviewed = false,
|
||||
AffectedThePoem = false,
|
||||
};
|
||||
_context.GanjoorPoemSectionCorrections.Add(dbCorrection);
|
||||
await _context.SaveChangesAsync();
|
||||
correction.Id = dbCorrection.Id;
|
||||
|
||||
if (preCorrections.Count > 0)
|
||||
{
|
||||
_context.GanjoorPoemSectionCorrections.RemoveRange(preCorrections);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return new RServiceResult<GanjoorPoemSectionCorrectionViewModel>(correction);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<GanjoorPoemSectionCorrectionViewModel>(null, exp.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user