From 0bc721dec243dc56f51c613eaa6365117018e492 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Thu, 9 Dec 2021 21:22:46 +0330 Subject: [PATCH] #255 API method for getting list of reported errors for recitations --- RMuseum/Controllers/RecitationController.cs | 23 ++++++++++++++ .../RecitationErrorReportViewModel.cs | 14 ++++++++- RMuseum/RMuseum.xml | 31 +++++++++++++++++++ RMuseum/Services/IRecitationService.cs | 7 +++++ .../Implementation/RecitationService.cs | 27 ++++++++++++++++ 5 files changed, 101 insertions(+), 1 deletion(-) diff --git a/RMuseum/Controllers/RecitationController.cs b/RMuseum/Controllers/RecitationController.cs index d6ddb9a4..a8354684 100644 --- a/RMuseum/Controllers/RecitationController.cs +++ b/RMuseum/Controllers/RecitationController.cs @@ -819,6 +819,29 @@ namespace RMuseum.Controllers return Ok(res.Result); } + /// + /// get errors reported for recitations + /// + /// + /// + [HttpGet("errors/report")] + [Authorize(Policy = RMuseumSecurableItem.AudioRecitationEntityShortName + ":" + RMuseumSecurableItem.PublishOperationShortName)] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task GetReportedErrorsAsync([FromQuery] PagingParameterModel paging) + { + var reports = await _audioService.GetReportedErrorsAsync(paging); + if (!string.IsNullOrEmpty(reports.ExceptionString)) + { + return BadRequest(reports.ExceptionString); + } + + // Paging Header + HttpContext.Response.Headers.Add("paging-headers", JsonConvert.SerializeObject(reports.Result.PagingMeta)); + + return Ok(reports.Result.Items); + } + /// /// constructor diff --git a/RMuseum/Models/GanjoorAudio/ViewModels/RecitationErrorReportViewModel.cs b/RMuseum/Models/GanjoorAudio/ViewModels/RecitationErrorReportViewModel.cs index b22ac267..8d2fed7d 100644 --- a/RMuseum/Models/GanjoorAudio/ViewModels/RecitationErrorReportViewModel.cs +++ b/RMuseum/Models/GanjoorAudio/ViewModels/RecitationErrorReportViewModel.cs @@ -1,4 +1,6 @@ -namespace RMuseum.Models.GanjoorAudio.ViewModels +using System; + +namespace RMuseum.Models.GanjoorAudio.ViewModels { /// /// Post Error Report for recitations @@ -18,5 +20,15 @@ /// Reason Text /// public string ReasonText { get; set; } + + /// + /// recitation + /// + public RecitationViewModel Recitation { get; set; } + + /// + /// DateTime + /// + public DateTime DateTime { get; set; } } } diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index a5fc9ef0..471e94c0 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -1806,6 +1806,13 @@ + + + get errors reported for recitations + + + + constructor @@ -3904,6 +3911,16 @@ Reason Text + + + recitation + + + + + DateTime + + Poem Narration Moderation View Model @@ -12391,6 +12408,13 @@ + + + get errors reported for recitations + + + + Upload Enabled (temporary switch off/on for upload) @@ -12742,6 +12766,13 @@ + + + get errors reported for recitations + + + + Upload Enabled (temporary switch off/on for upload) diff --git a/RMuseum/Services/IRecitationService.cs b/RMuseum/Services/IRecitationService.cs index f292a496..63518f28 100644 --- a/RMuseum/Services/IRecitationService.cs +++ b/RMuseum/Services/IRecitationService.cs @@ -209,6 +209,13 @@ namespace RMuseum.Services /// Task> ReportErrorAsync(Guid userId, RecitationErrorReportViewModel report); + /// + /// get errors reported for recitations + /// + /// + /// + Task> GetReportedErrorsAsync(PagingParameterModel paging); + /// /// Upload Enabled (temporary switch off/on for upload) /// diff --git a/RMuseum/Services/Implementation/RecitationService.cs b/RMuseum/Services/Implementation/RecitationService.cs index e2546bab..8dc11393 100644 --- a/RMuseum/Services/Implementation/RecitationService.cs +++ b/RMuseum/Services/Implementation/RecitationService.cs @@ -1741,6 +1741,7 @@ namespace RMuseum.Services.Implementationa await _context.SaveChangesAsync(); report.Id = dbModel.Id; + report.DateTime = dbModel.DateTime; return new RServiceResult(report); } @@ -1750,6 +1751,32 @@ namespace RMuseum.Services.Implementationa } } + /// + /// get errors reported for recitations + /// + /// + /// + public async Task> GetReportedErrorsAsync(PagingParameterModel paging) + { + var source = + from report in _context.RecitationErrorReports.Include(r => r.Recitation).Include(r => r.Reporter) + join poem in _context.GanjoorPoems + on report.Recitation.GanjoorPostId equals poem.Id + select + new RecitationErrorReportViewModel() + { + Id = report.Id, + ReasonText = report.ReasonText, + RecitationId = report.RecitationId, + Recitation = new RecitationViewModel(report.Recitation, report.Recitation.Owner, poem), + DateTime = report.DateTime + }; + + (PaginationMetadata PagingMeta, RecitationErrorReportViewModel[] Items) paginatedResult = + await QueryablePaginator.Paginate(source, paging); + return new RServiceResult<(PaginationMetadata PagingMeta, RecitationErrorReportViewModel[] Items)>(paginatedResult); + } + /// /// Upload Enabled (temporary switch off/on for upload) ///