From 7d8aed75b26e2abbcd6544a75031883f82b1e92e Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Tue, 1 Aug 2023 09:55:20 +0330 Subject: [PATCH] #404 suggest ganjoor link for naskban --- RMuseum/DbContext/RMuseumDbContext.cs | 5 + .../GanjoorIntegration/PDFGanjoorLink.cs | 91 +++++++++++ .../ViewModels/PDFGanjoorLinkSuggestion.cs | 33 ++++ RMuseum/RMuseum.xml | 128 ++++++++++++++++ .../Implementation/ArtifactService.cs | 4 +- .../Implementation/PDFLibraryService.cs | 142 ++++++++++++------ 6 files changed, 358 insertions(+), 45 deletions(-) create mode 100644 RMuseum/Models/GanjoorIntegration/PDFGanjoorLink.cs create mode 100644 RMuseum/Models/PDFLibrary/ViewModels/PDFGanjoorLinkSuggestion.cs diff --git a/RMuseum/DbContext/RMuseumDbContext.cs b/RMuseum/DbContext/RMuseumDbContext.cs index b802dd25..c451f365 100644 --- a/RMuseum/DbContext/RMuseumDbContext.cs +++ b/RMuseum/DbContext/RMuseumDbContext.cs @@ -543,5 +543,10 @@ namespace RMuseum.DbContext /// public DbSet QueuedFTPUploads { get; set; } + /// + /// PDF Ganjoor Links + /// + public DbSet PDFGanjoorLinks { get; set; } + } } diff --git a/RMuseum/Models/GanjoorIntegration/PDFGanjoorLink.cs b/RMuseum/Models/GanjoorIntegration/PDFGanjoorLink.cs new file mode 100644 index 00000000..b499012d --- /dev/null +++ b/RMuseum/Models/GanjoorIntegration/PDFGanjoorLink.cs @@ -0,0 +1,91 @@ +using RSecurityBackend.Models.Auth.Db; +using System; + +namespace RMuseum.Models.GanjoorIntegration +{ + /// + /// PDFBook Ganjoor Link + /// + public class PDFGanjoorLink + { + /// + /// Ganjoor Post Id + /// + public int GanjoorPostId { get; set; } + + /// + /// ganjoor url + /// + public string GanjoorUrl { get; set; } + + /// + /// ganjoor title + /// + public string GanjoorTitle { get; set; } + + /// + /// pdf book id + /// + public int PDFBookId { get; set; } + + /// + /// page number + /// + public int PageNumber { get; set; } + + /// + /// User Id who suggested the link + /// + public Guid SuggestedById { get; set; } + + /// + /// Suggestion Date + /// + public DateTime SuggestionDate { get; set; } + + /// + /// User who suggested the link + /// + public RAppUser SuggestedBy { get; set; } + + /// + /// User id who reviewed the link + /// + public Guid? ReviewerId { get; set; } + + /// + /// User who reviewed the link + /// + public virtual RAppUser Reviewer { get; set; } + + /// + /// Review Date + /// + public DateTime ReviewDate { get; set; } + + /// + /// review result + /// + public ReviewResult ReviewResult { get; set; } + + /// + /// Synchronized with ganjoor + /// + public bool Synchronized { get; set; } + + /// + /// is the is the text original source? + /// + public bool IsTextOriginalSource { get; set; } + + /// + /// PDF Page Title + /// + public string PDFPageTitle { get; set; } + + /// + /// external thumbnail image url + /// + public string ExternalThumbnailImageUrl { get; set; } + } +} diff --git a/RMuseum/Models/PDFLibrary/ViewModels/PDFGanjoorLinkSuggestion.cs b/RMuseum/Models/PDFLibrary/ViewModels/PDFGanjoorLinkSuggestion.cs new file mode 100644 index 00000000..4de8ed2d --- /dev/null +++ b/RMuseum/Models/PDFLibrary/ViewModels/PDFGanjoorLinkSuggestion.cs @@ -0,0 +1,33 @@ +namespace RMuseum.Models.PDFLibrary.ViewModels +{ + /// + /// PDFBook Ganjoor Link Suggestion + /// + public class PDFGanjoorLinkSuggestion + { + /// + /// Ganjoor Post Id + /// + public int GanjoorPostId { get; set; } + + /// + /// ganjoor url + /// + public string GanjoorUrl { get; set; } + + /// + /// ganjoor title + /// + public string GanjoorTitle { get; set; } + + /// + /// pdf book id + /// + public int PDFBookId { get; set; } + + /// + /// page number + /// + public int PageNumber { get; set; } + } +} diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index e23df9f4..052f2976 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -3624,6 +3624,11 @@ Queued FTP Uploads + + + PDF Ganjoor Links + + @@ -6345,6 +6350,91 @@ Instagram + + + PDFBook Ganjoor Link + + + + + Ganjoor Post Id + + + + + ganjoor url + + + + + ganjoor title + + + + + pdf book id + + + + + page number + + + + + User Id who suggested the link + + + + + Suggestion Date + + + + + User who suggested the link + + + + + User id who reviewed the link + + + + + User who reviewed the link + + + + + Review Date + + + + + review result + + + + + Synchronized with ganjoor + + + + + is the is the text original source? + + + + + PDF Page Title + + + + + external thumbnail image url + + pinterest link @@ -12796,6 +12886,36 @@ Book Script Type + + + PDFBook Ganjoor Link Suggestion + + + + + Ganjoor Post Id + + + + + ganjoor url + + + + + ganjoor title + + + + + pdf book id + + + + + page number + + Upload Session @@ -18321,6 +18441,14 @@ + + + suggest ganjoor link + + + + + Database Context diff --git a/RMuseum/Services/Implementation/ArtifactService.cs b/RMuseum/Services/Implementation/ArtifactService.cs index 43383b60..5c643da2 100644 --- a/RMuseum/Services/Implementation/ArtifactService.cs +++ b/RMuseum/Services/Implementation/ArtifactService.cs @@ -2630,11 +2630,11 @@ namespace RMuseum.Services.Implementation { RArtifactMasterRecord artifact = await _context.Artifacts.Where(a => a.FriendlyUrl == link.ArtifactFriendlyUrl).SingleOrDefaultAsync(); - GanjoorLink alreaySuggest = + GanjoorLink alreadySuggest = await _context.GanjoorLinks. Where(l => l.GanjoorPostId == link.GanjoorPostId && l.ArtifactId == artifact.Id && l.ItemId == link.ItemId && l.ReviewResult != ReviewResult.Rejected) .SingleOrDefaultAsync(); - if (alreaySuggest != null) + if (alreadySuggest != null) return new RServiceResult(null, "این مورد پیشتر پیشنهاد شده است."); GanjoorLink suggestion = diff --git a/RMuseum/Services/Implementation/PDFLibraryService.cs b/RMuseum/Services/Implementation/PDFLibraryService.cs index ba816979..4a7f3d34 100644 --- a/RMuseum/Services/Implementation/PDFLibraryService.cs +++ b/RMuseum/Services/Implementation/PDFLibraryService.cs @@ -4,8 +4,11 @@ using Microsoft.Extensions.Configuration; using RMuseum.DbContext; using RMuseum.Models.Artifact; using RMuseum.Models.Artifact.ViewModels; +using RMuseum.Models.GanjoorIntegration.ViewModels; +using RMuseum.Models.GanjoorIntegration; using RMuseum.Models.PDFLibrary; using RMuseum.Models.PDFLibrary.ViewModels; +using RSecurityBackend.Models.Auth.ViewModels; using RSecurityBackend.Models.Generic; using RSecurityBackend.Models.Image; using RSecurityBackend.Services; @@ -1285,59 +1288,111 @@ namespace RMuseum.Services.Implementation /// public async Task> SearchPDFBooksAsync(PagingParameterModel paging, string term) { - term = term.Trim().ApplyCorrectYeKe(); - - if (string.IsNullOrEmpty(term)) + try { - return new RServiceResult<(PaginationMetadata PagingMeta, PDFBook[] Items)>((null, null), "خطای جستجوی عبارت خالی"); - } + term = term.Trim().ApplyCorrectYeKe(); - term = term.Replace("‌", " ");//replace zwnj with space - - string searchConditions; - if (term.IndexOf('"') == 0 && term.LastIndexOf('"') == (term.Length - 1)) - { - searchConditions = term.Replace("\"", "").Replace("'", ""); - searchConditions = $"\"{searchConditions}\""; - } - else - { - string[] words = term.Replace("\"", "").Replace("'", "").Split(' ', StringSplitOptions.RemoveEmptyEntries); - - searchConditions = ""; - string emptyOrAnd = ""; - foreach (string word in words) + if (string.IsNullOrEmpty(term)) { - searchConditions += $" {emptyOrAnd} \"*{word}*\" "; - emptyOrAnd = " AND "; + return new RServiceResult<(PaginationMetadata PagingMeta, PDFBook[] Items)>((null, null), "خطای جستجوی عبارت خالی"); } + + term = term.Replace("‌", " ");//replace zwnj with space + + string searchConditions; + if (term.IndexOf('"') == 0 && term.LastIndexOf('"') == (term.Length - 1)) + { + searchConditions = term.Replace("\"", "").Replace("'", ""); + searchConditions = $"\"{searchConditions}\""; + } + else + { + string[] words = term.Replace("\"", "").Replace("'", "").Split(' ', StringSplitOptions.RemoveEmptyEntries); + + searchConditions = ""; + string emptyOrAnd = ""; + foreach (string word in words) + { + searchConditions += $" {emptyOrAnd} \"*{word}*\" "; + emptyOrAnd = " AND "; + } + } + //full text catalogue should be created manually + + var source = + _context.PDFBooks.AsNoTracking().Include(a => a.Tags) + .Where(p => + p.Status == PublishStatus.Published + && + ( + EF.Functions.Contains(p.Title, searchConditions) + || + EF.Functions.Contains(p.AuthorsLine, searchConditions) + || + EF.Functions.Contains(p.TranslatorsLine, searchConditions) + || + EF.Functions.Contains(p.Description, searchConditions) + || + p.Tags.Where(t => EF.Functions.Contains(t.Value, searchConditions) || EF.Functions.Contains(t.ValueInEnglish, searchConditions)).Any() + ) + ).OrderBy(i => i.Title); + + + (PaginationMetadata PagingMeta, PDFBook[] Items) paginatedResult = + await QueryablePaginator.Paginate(source, paging); + + + return new RServiceResult<(PaginationMetadata PagingMeta, PDFBook[] Items)>(paginatedResult); } - //full text catalogue should be created manually + catch (Exception exp) + { + return new RServiceResult<(PaginationMetadata PagingMeta, PDFBook[] Items)>((null, null), exp.ToString()); + } + } - var source = - _context.PDFBooks.AsNoTracking().Include(a => a.Tags) - .Where(p => - p.Status == PublishStatus.Published - && - ( - EF.Functions.Contains(p.Title, searchConditions) - || - EF.Functions.Contains(p.AuthorsLine, searchConditions) - || - EF.Functions.Contains(p.TranslatorsLine, searchConditions) - || - EF.Functions.Contains(p.Description, searchConditions) - || - p.Tags.Where(t => EF.Functions.Contains(t.Value, searchConditions) || EF.Functions.Contains(t.ValueInEnglish, searchConditions)).Any() - ) - ).OrderBy(i => i.Title); + /// + /// suggest ganjoor link + /// + /// + /// + /// + public async Task> SuggestGanjoorLink(Guid userId, PDFGanjoorLinkSuggestion link) + { + try + { + PDFBook pdfBook = await _context.PDFBooks.AsNoTracking().Where(a => a.Id == link.PDFBookId).SingleOrDefaultAsync(); + PDFGanjoorLink alreadySuggest = + await _context.PDFGanjoorLinks.AsNoTracking(). + Where(l => l.GanjoorPostId == link.GanjoorPostId && l.PDFBookId == pdfBook.Id && l.PageNumber == link.PageNumber && l.ReviewResult != ReviewResult.Rejected) + .SingleOrDefaultAsync(); + if (alreadySuggest != null) + return new RServiceResult(false, "این مورد پیشتر پیشنهاد شده است."); - (PaginationMetadata PagingMeta, PDFBook[] Items) paginatedResult = - await QueryablePaginator.Paginate(source, paging); + PDFGanjoorLink suggestion = + new PDFGanjoorLink() + { + GanjoorPostId = link.GanjoorPostId, + GanjoorTitle = link.GanjoorTitle, + GanjoorUrl = link.GanjoorUrl, + PDFBookId = pdfBook.Id, + PageNumber = link.PageNumber, + SuggestedById = userId, + SuggestionDate = DateTime.Now, + ReviewResult = ReviewResult.Awaiting, + ExternalThumbnailImageUrl = (await _context.PDFPages.AsNoTracking().Where(l => l.PDFBookId == link.PDFBookId && l.PageNumber == link.PageNumber).SingleAsync()).ExtenalThumbnailImageUrl, + PDFPageTitle = pdfBook.Title + " - صفحهٔ " + link.PageNumber.ToString().ToPersianNumbers() + }; + _context.PDFGanjoorLinks.Add(suggestion); + await _context.SaveChangesAsync(); - return new RServiceResult<(PaginationMetadata PagingMeta, PDFBook[] Items)>(paginatedResult); + return new RServiceResult(true); + } + catch (Exception exp) + { + return new RServiceResult(false, exp.ToString()); + } } /// @@ -1356,6 +1411,7 @@ namespace RMuseum.Services.Implementation /// ftp service /// protected readonly IQueuedFTPUploadService _ftpService; + /// /// Configuration ///