diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index 563a6d35..deb13154 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc; using RMuseum.Models.Auth.Memory; using RMuseum.Models.Ganjoor; +using RMuseum.Models.Ganjoor.ViewModels; using RMuseum.Models.GanjoorAudio.ViewModels; using RMuseum.Models.GanjoorIntegration.ViewModels; using RMuseum.Services; @@ -72,6 +73,24 @@ namespace RMuseum.Controllers return Ok(res.Result); } + /// + /// get a random poem from hafez + /// + /// + [HttpGet] + [Route("hafez/faal")] + [AllowAnonymous] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoemCompleteViewModel))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task Faal() + { + RServiceResult res = + await _ganjoorService.Faal(); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(res.Result); + } + /// /// imports data from ganjoor SQLite database /// diff --git a/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoemCompleteViewModel.cs b/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoemCompleteViewModel.cs index 3c50ef03..ef9a4c3c 100644 --- a/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoemCompleteViewModel.cs +++ b/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoemCompleteViewModel.cs @@ -1,8 +1,5 @@ using RMuseum.Models.GanjoorAudio.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using RMuseum.Models.GanjoorIntegration.ViewModels; namespace RMuseum.Models.Ganjoor.ViewModels { @@ -20,5 +17,10 @@ namespace RMuseum.Models.Ganjoor.ViewModels /// Recitations /// public PublicRecitationViewModel[] Recitations { get; set; } + + /// + /// Images + /// + public GanjoorLinkViewModel[] Images { get; set; } } } diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 39b2bb17..81859961 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -636,6 +636,12 @@ + + + get a random poem from hafez + + + imports data from ganjoor SQLite database @@ -3418,6 +3424,11 @@ Recitations + + + Images + + Import Job @@ -4446,6 +4457,12 @@ + + + get a random poem from hafez + + + imports unimported poem data from a locally accessible ganjoor SqlLite database @@ -5179,6 +5196,12 @@ + + + get a random poem from hafez + + + imports unimported poem data from a locally accessible ganjoor SqlLite database diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index 4a042e32..3f8e0a4f 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -1,4 +1,5 @@ using RMuseum.Models.Ganjoor; +using RMuseum.Models.Ganjoor.ViewModels; using RMuseum.Models.GanjoorAudio.ViewModels; using RMuseum.Models.GanjoorIntegration.ViewModels; using RSecurityBackend.Models.Generic; @@ -33,6 +34,12 @@ namespace RMuseum.Services /// Task> GetPoemImages(int id); + /// + /// get a random poem from hafez + /// + /// + Task> Faal(); + /// /// imports unimported poem data from a locally accessible ganjoor SqlLite database /// diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index b9a9e325..3916dbae 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using RMuseum.DbContext; using RMuseum.Models.Ganjoor; +using RMuseum.Models.Ganjoor.ViewModels; using RMuseum.Models.GanjoorAudio; using RMuseum.Models.GanjoorAudio.ViewModels; using RMuseum.Models.GanjoorIntegration.ViewModels; @@ -31,7 +32,7 @@ namespace RMuseum.Services.Implementation { try { - var poem = await _context.GanjoorPoems.Include(p => p.Cat).ThenInclude(c => c.Poet).Where(p => p.Id == id).SingleOrDefaultAsync(); + var poem = await _context.GanjoorPoems.Include(p => p.Cat).Where(p => p.Id == id).SingleOrDefaultAsync(); var cat = poem.Cat; while(cat != null) { @@ -134,6 +135,39 @@ namespace RMuseum.Services.Implementation } } + /// + /// get a random poem from hafez + /// + /// + public async Task> Faal() + { + try + { + //this is magic number based method! + int startPoemId = 2130; + int endPoemId = 2634 + 1; //one is added for مژده ای دل که مسیحا نفسی می‌آید + Random r = new Random(DateTime.Now.Millisecond); + int poemId = r.Next(startPoemId, endPoemId); + if(poemId == endPoemId) + { + poemId = 33179;//مژده ای دل که مسیحا نفسی می‌آید + } + return new RServiceResult + ( + new GanjoorPoemCompleteViewModel() + { + Poem = (await GetPoemById(poemId)).Result, + Recitations = (await GetPoemRecitations(poemId)).Result, + Images = (await GetPoemImages(poemId)).Result + } + ); + } + catch (Exception exp) + { + return new RServiceResult(null, exp.ToString()); + } + } + #region Date import / modifications /// /// imports unimported poem data from a locally accessible ganjoor SqlLite database