diff --git a/RMuseum/DbContext/RMuseumDbContext.cs b/RMuseum/DbContext/RMuseumDbContext.cs index 76529c41..3864bb9c 100644 --- a/RMuseum/DbContext/RMuseumDbContext.cs +++ b/RMuseum/DbContext/RMuseumDbContext.cs @@ -572,7 +572,7 @@ namespace RMuseum.DbContext /// /// paper sources /// - public DbSet PaperSources { get; set; } + public DbSet GanjoorPaperSources { get; set; } } } diff --git a/RMuseum/Models/Ganjoor/ViewModels/GanjoorCatViewModel.cs b/RMuseum/Models/Ganjoor/ViewModels/GanjoorCatViewModel.cs index ae5cea1f..9110fab3 100644 --- a/RMuseum/Models/Ganjoor/ViewModels/GanjoorCatViewModel.cs +++ b/RMuseum/Models/Ganjoor/ViewModels/GanjoorCatViewModel.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Http; +using RMuseum.Models.GanjoorIntegration; using System; using System.Collections.Generic; @@ -104,6 +105,11 @@ namespace RMuseum.Models.Ganjoor.ViewModels /// public ICollection Poems { get; set; } + /// + /// paper sources + /// + public ICollection PaperSources { get; set; } + /// /// new image /// diff --git a/RMuseum/Models/GanjoorIntegration/PaperSource.cs b/RMuseum/Models/GanjoorIntegration/GanjoorPaperSource.cs similarity index 98% rename from RMuseum/Models/GanjoorIntegration/PaperSource.cs rename to RMuseum/Models/GanjoorIntegration/GanjoorPaperSource.cs index a8f42706..53aa37a1 100644 --- a/RMuseum/Models/GanjoorIntegration/PaperSource.cs +++ b/RMuseum/Models/GanjoorIntegration/GanjoorPaperSource.cs @@ -5,7 +5,7 @@ namespace RMuseum.Models.GanjoorIntegration /// /// Ganjoor Paper Source /// - public class PaperSource + public class GanjoorPaperSource { /// /// Id diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 4d049b9f..624bf30f 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -2033,6 +2033,13 @@ + + + import naskban ganjoor matchings + + + + delete poem related naskban images by url @@ -3508,7 +3515,7 @@ discover quoted q items - + paper sources @@ -6492,6 +6499,86 @@ is text original source + + + Ganjoor Paper Source + + + + + Id + + + + + poet id + + + + + cat id + + + + + cat full title + + + + + cat full url + + + + + book type + + + + + book full url + + + + + naskban book id + + + + + book title + + + + + description + + + + + is the text original source for the category? + + + + + cover thumbnail image url + + + + + match percent + + + + + reviewed by a human + + + + + position in sorting + + Link Type @@ -6522,86 +6609,6 @@ Naskban - - - Ganjoor Paper Source - - - - - Id - - - - - poet id - - - - - cat id - - - - - cat full title - - - - - cat full url - - - - - book type - - - - - book full url - - - - - naskban book id - - - - - book title - - - - - description - - - - - is the text original source for the category? - - - - - cover thumbnail image url - - - - - match percent - - - - - reviewed by a human - - - - - position in sorting - - PDFBook Ganjoor Link @@ -10293,6 +10300,11 @@ poems + + + paper sources + + new image @@ -15001,22 +15013,24 @@ - + get cat by id + - + get cat by url + @@ -16163,6 +16177,20 @@ + + + import naskban ganjoor matchings + + + + + + + category paper sources + + + + mark naskban links as human reviewed @@ -18189,6 +18217,13 @@ number of synched items + + + category paper sources + + + + return list of suggested spec lines @@ -18750,13 +18785,14 @@ - + get cat by url + @@ -18771,13 +18807,14 @@ - + get cat by id + diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index 488da861..12c39e4f 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -2,6 +2,7 @@ using RMuseum.Models.Ganjoor; using RMuseum.Models.Ganjoor.ViewModels; using RMuseum.Models.GanjoorAudio.ViewModels; +using RMuseum.Models.GanjoorIntegration; using RSecurityBackend.Models.Generic; using System; using System.Threading.Tasks; @@ -50,8 +51,9 @@ namespace RMuseum.Services /// /// /// + /// /// - Task> GetCatById(int id, bool poems = false, bool mainSections = false); + Task> GetCatById(int id, bool poems = false, bool mainSections = false, bool paperSources = false); /// /// get cat by url @@ -59,8 +61,9 @@ namespace RMuseum.Services /// /// /// + /// /// - Task> GetCatByUrl(string url, bool poems = false, bool mainSections = false); + Task> GetCatByUrl(string url, bool poems = false, bool mainSections = false, bool paperSources = false); /// /// Update category extra info @@ -1227,6 +1230,13 @@ namespace RMuseum.Services /// void ImportNaskbanGanjoorPoemMatchFindings(string naskbanUserName, string naskbanPassword); + /// + /// category paper sources + /// + /// + /// + Task> GetCategoryPaperSourcesAsync(int categoryId); + /// /// mark naskban links as human reviewed /// diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Naskban.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Naskban.cs index e34c5926..855a903b 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Naskban.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Naskban.cs @@ -579,7 +579,7 @@ namespace RMuseum.Services.Implementation var matchings = JsonConvert.DeserializeObject(await unsyncedResponse.Content.ReadAsStringAsync()); foreach (var matching in matchings) { - if (false == await context.PaperSources.Where(p => p.NaskbanBookId == matching.BookId).AnyAsync()) + if (false == await context.GanjoorPaperSources.Where(p => p.NaskbanBookId == matching.BookId).AnyAsync()) { HttpResponseMessage responseBook = await secureClient.GetAsync($"https://api.naskban.ir/api/pdf/{matching.BookId}?includePages=false&includeBookText=false&includePageText=false"); if (responseBook.StatusCode != HttpStatusCode.OK) @@ -590,7 +590,7 @@ namespace RMuseum.Services.Implementation var book = JsonConvert.DeserializeObject(await responseBook.Content.ReadAsStringAsync()); var cat = await context.GanjoorCategories.AsNoTracking().Where(c => c.Id == matching.GanjoorCatId).SingleAsync(); - PaperSource paperSource = new PaperSource() + GanjoorPaperSource paperSource = new GanjoorPaperSource() { GanjoorPoetId = cat.PoetId, GanjoorCatId = matching.GanjoorCatId, @@ -607,7 +607,7 @@ namespace RMuseum.Services.Implementation HumanReviewed = false, OrderIndicator = 0, }; - context.PaperSources.Add(paperSource); + context.GanjoorPaperSources.Add(paperSource); await context.SaveChangesAsync(); } } @@ -622,5 +622,25 @@ namespace RMuseum.Services.Implementation return new RServiceResult(0, exp.ToString()); } } + + /// + /// category paper sources + /// + /// + /// + public async Task> GetCategoryPaperSourcesAsync(int categoryId) + { + try + { + return new RServiceResult + ( + await _context.GanjoorPaperSources.AsNoTracking().Where(p => p.GanjoorCatId == categoryId).OrderBy(c => c.OrderIndicator).ThenBy(c => c.Id).ToArrayAsync() + ); + } + catch (Exception exp) + { + return new RServiceResult(null, exp.ToString()); + } + } } } \ No newline at end of file diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index 2af3d9e7..80133fac 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -167,8 +167,9 @@ namespace RMuseum.Services.Implementation /// /// /// + /// /// - public async Task> GetCatByUrl(string url, bool poems = false, bool mainSections = false) + public async Task> GetCatByUrl(string url, bool poems = false, bool mainSections = false, bool paperSources = false) { // /hafez/ => /hafez : if (url.LastIndexOf('/') == url.Length - 1) @@ -178,7 +179,7 @@ namespace RMuseum.Services.Implementation var cat = await _context.GanjoorCategories.Where(c => c.FullUrl == url).AsNoTracking().SingleOrDefaultAsync(); if (cat == null) return new RServiceResult(null); - return await GetCatById(cat.Id, poems, mainSections); + return await GetCatById(cat.Id, poems, mainSections, paperSources); } @@ -269,13 +270,14 @@ namespace RMuseum.Services.Implementation /// /// /// + /// /// - public async Task> GetCatById(int id, bool poems = false, bool mainSections = false) + public async Task> GetCatById(int id, bool poems = false, bool mainSections = false, bool paperSources = false) { - return await _GetCatById(_context, id, poems, mainSections); + return await _GetCatById(_context, id, poems, mainSections, paperSources); } - private async Task> _GetCatById(RMuseumDbContext context, int id, bool poems = false, bool mainSections = false) + private async Task> _GetCatById(RMuseumDbContext context, int id, bool poems = false, bool mainSections = false, bool paperSources = false) { var cat = await context.GanjoorCategories.Include(c => c.Poet).Include(c => c.Parent).Where(c => c.Id == id).AsNoTracking().FirstOrDefaultAsync(); if (cat == null) @@ -413,7 +415,8 @@ namespace RMuseum.Services.Implementation } ).AsNoTracking().ToListAsync() : - null + null, + PaperSources = paperSources ? await context.GanjoorPaperSources.AsNoTracking().Where(p => p.GanjoorCatId == cat.Id).ToListAsync() : null, }; if (poems && mainSections)