From 7b8ab40b9d85be6e0342bbe114e682be930c9b12 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Thu, 12 May 2022 18:17:04 +0430 Subject: [PATCH] docs: #319 section editor + some needed API --- GanjooRazor/Areas/User/Pages/Section.cshtml | 22 ------ .../Areas/User/Pages/Section.cshtml.cs | 10 ++- RMuseum/Controllers/GanjoorController.cs | 23 +++++++ RMuseum/DbContext/RMuseumDbContext.cs | 5 ++ RMuseum/RMuseum.xml | 31 +++++++++ RMuseum/Services/IGanjoorService.cs | 8 +++ ...anjoorService-ModerateSectionCorrection.cs | 67 +++++++++++++++++++ 7 files changed, 143 insertions(+), 23 deletions(-) create mode 100644 RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModerateSectionCorrection.cs diff --git a/GanjooRazor/Areas/User/Pages/Section.cshtml b/GanjooRazor/Areas/User/Pages/Section.cshtml index 5e3a766b..fef44d83 100644 --- a/GanjooRazor/Areas/User/Pages/Section.cshtml +++ b/GanjooRazor/Areas/User/Pages/Section.cshtml @@ -106,27 +106,5 @@ else پیشنهاد وزن جدید - - - - شکستن به اشعار مجزا - - - - @foreach (var verse in Model.Verses) - { - - -

@verse.Text

- - - - - - از اینجا به بعد شعر جداگانه‌ایست - - - - } } diff --git a/GanjooRazor/Areas/User/Pages/Section.cshtml.cs b/GanjooRazor/Areas/User/Pages/Section.cshtml.cs index ce0174ca..e989ff95 100644 --- a/GanjooRazor/Areas/User/Pages/Section.cshtml.cs +++ b/GanjooRazor/Areas/User/Pages/Section.cshtml.cs @@ -45,7 +45,7 @@ namespace GanjooRazor.Areas.User.Pages /// /// my last edit /// - public GanjoorPoemCorrectionViewModel MyLastEdit { get; set; } + public GanjoorPoemSectionCorrectionViewModel MyLastEdit { get; set; } /// /// verses @@ -128,6 +128,14 @@ namespace GanjooRazor.Areas.User.Pages PoemSection = PageInformation.Poem.Sections.Where(s => s.Index == int.Parse(Request.Query["index"])).Single(); + var editResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/section/correction/last/{PoemSection.Id}"); + if (!editResponse.IsSuccessStatusCode) + { + FatalError = JsonConvert.DeserializeObject(await editResponse.Content.ReadAsStringAsync()); + return Page(); + } + MyLastEdit = JsonConvert.DeserializeObject(await editResponse.Content.ReadAsStringAsync()); + Verses = _FilterSectionVerses(PoemSection, PageInformation.Poem.Verses); } else diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index d66be5e8..60af5c2d 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -2812,6 +2812,29 @@ namespace RMuseum.Controllers return Ok(); } + /// + /// returns last unreviewed correction from the user for a section + /// + /// section id + /// + [HttpGet] + [Route("section/correction/last/{id}")] + [Authorize] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoemSectionCorrectionViewModel))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + [ProducesResponseType((int)HttpStatusCode.NotFound)] + public async Task GetLastUnreviewedUserCorrectionForSection(int id) + { + Guid userId = + new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); + + RServiceResult res = + await _ganjoorService.GetLastUnreviewedUserCorrectionForSection(userId, id); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(res.Result);//might be null + } + /// /// readonly mode diff --git a/RMuseum/DbContext/RMuseumDbContext.cs b/RMuseum/DbContext/RMuseumDbContext.cs index 5593eff0..f7b3277a 100644 --- a/RMuseum/DbContext/RMuseumDbContext.cs +++ b/RMuseum/DbContext/RMuseumDbContext.cs @@ -482,5 +482,10 @@ namespace RMuseum.DbContext /// public DbSet GanjoorCachedRelatedSections { get; set; } + /// + /// section correctons + /// + public DbSet GanjoorPoemSectionCorrections { get; set; } + } } diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index b95afb7c..2c16866e 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -1713,6 +1713,13 @@ + + + returns last unreviewed correction from the user for a section + + section id + + readonly mode @@ -2894,6 +2901,11 @@ related sections to each section (having same rhyme letters and prosody metre) + + + section correctons + + donation expenditures @@ -12327,6 +12339,14 @@ + + + last unreviewed user correction for a section + + + + + translation service implementation @@ -13706,6 +13726,9 @@ IGanjoorService implementation + + IGanjoorService implementation + @@ -13880,6 +13903,14 @@ + + + last unreviewed user correction for a section + + + + + start updating stats page diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index 72651e2f..530dfb49 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -941,5 +941,13 @@ namespace RMuseum.Services /// /// Task> GetPoemSectionsAsync(int id); + + /// + /// last unreviewed user correction for a section + /// + /// + /// + /// + Task> GetLastUnreviewedUserCorrectionForSection(Guid userId, int sectionId); } } diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModerateSectionCorrection.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModerateSectionCorrection.cs new file mode 100644 index 00000000..d2560c33 --- /dev/null +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModerateSectionCorrection.cs @@ -0,0 +1,67 @@ +using Microsoft.EntityFrameworkCore; +using RMuseum.DbContext; +using RMuseum.Models.Ganjoor; +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; + +namespace RMuseum.Services.Implementation +{ + /// + /// IGanjoorService implementation + /// + public partial class GanjoorService : IGanjoorService + { + /// + /// last unreviewed user correction for a section + /// + /// + /// + /// + public async Task> GetLastUnreviewedUserCorrectionForSection(Guid userId, int sectionId) + { + var dbCorrection = await _context.GanjoorPoemSectionCorrections.AsNoTracking().Include(c => c.User) + .Where(c => c.UserId == userId && c.SectionId == sectionId && c.Reviewed == false) + .OrderByDescending(c => c.Id) + .FirstOrDefaultAsync(); + + if (dbCorrection == null) + return new RServiceResult(null); + + return new RServiceResult + ( + new GanjoorPoemSectionCorrectionViewModel() + { + Id = dbCorrection.Id, + SectionId = dbCorrection.SectionId, + UserId = dbCorrection.UserId, + Rhythm = dbCorrection.Rhythm, + OriginalRhythm = dbCorrection.OriginalRhythm, + RhythmResult = dbCorrection.RhythmResult, + Rhythm2 = dbCorrection.Rhythm2, + OriginalRhythm2 = dbCorrection.OriginalRhythm2, + RhythmResult2 = dbCorrection.RhythmResult2, + BreakFromVerse1VOrder = dbCorrection.BreakFromVerse1VOrder, + BreakFromVerse1VOrderResult = dbCorrection.BreakFromVerse1VOrderResult, + BreakFromVerse2VOrder = dbCorrection.BreakFromVerse2VOrder, + BreakFromVerse2VOrderResult = dbCorrection.BreakFromVerse2VOrderResult, + BreakFromVerse3VOrder = dbCorrection.BreakFromVerse3VOrder, + BreakFromVerse3VOrderResult = dbCorrection.BreakFromVerse3VOrderResult, + BreakFromVerse4VOrder = dbCorrection.BreakFromVerse4VOrder, + BreakFromVerse4VOrderResult = dbCorrection.BreakFromVerse4VOrderResult, + Note = dbCorrection.Note, + Date = dbCorrection.Date, + Reviewed = dbCorrection.Reviewed, + ReviewNote = dbCorrection.ReviewNote, + ReviewDate = dbCorrection.ReviewDate, + UserNickname = string.IsNullOrEmpty(dbCorrection.User.NickName) ? dbCorrection.User.Id.ToString() : dbCorrection.User.NickName + } + ); + } + } +} \ No newline at end of file