This commit is contained in:
Hamid Reza Mohammadi 2020-12-17 17:39:48 +03:30
parent 6d5cb93742
commit aad97e72a7
5 changed files with 90 additions and 5 deletions

View File

@ -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);
}
/// <summary>
/// get a random poem from hafez
/// </summary>
/// <returns></returns>
[HttpGet]
[Route("hafez/faal")]
[AllowAnonymous]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoemCompleteViewModel))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task<IActionResult> Faal()
{
RServiceResult<GanjoorPoemCompleteViewModel> res =
await _ganjoorService.Faal();
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
return Ok(res.Result);
}
/// <summary>
/// imports data from ganjoor SQLite database
/// </summary>

View File

@ -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
/// </summary>
public PublicRecitationViewModel[] Recitations { get; set; }
/// <summary>
/// Images
/// </summary>
public GanjoorLinkViewModel[] Images { get; set; }
}
}

View File

@ -636,6 +636,12 @@
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.Faal">
<summary>
get a random poem from hafez
</summary>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.ImportLocalSQLiteDb">
<summary>
imports data from ganjoor SQLite database
@ -3418,6 +3424,11 @@
Recitations
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemCompleteViewModel.Images">
<summary>
Images
</summary>
</member>
<member name="T:RMuseum.Models.ImportJob.ImportJob">
<summary>
Import Job
@ -4446,6 +4457,12 @@
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.Faal">
<summary>
get a random poem from hafez
</summary>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.ImportLocalSQLiteDb">
<summary>
imports unimported poem data from a locally accessible ganjoor SqlLite database
@ -5179,6 +5196,12 @@
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.Faal">
<summary>
get a random poem from hafez
</summary>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.ImportLocalSQLiteDb">
<summary>
imports unimported poem data from a locally accessible ganjoor SqlLite database

View File

@ -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
/// <returns></returns>
Task<RServiceResult<GanjoorLinkViewModel[]>> GetPoemImages(int id);
/// <summary>
/// get a random poem from hafez
/// </summary>
/// <returns></returns>
Task<RServiceResult<GanjoorPoemCompleteViewModel>> Faal();
/// <summary>
/// imports unimported poem data from a locally accessible ganjoor SqlLite database
/// </summary>

View File

@ -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
}
}
/// <summary>
/// get a random poem from hafez
/// </summary>
/// <returns></returns>
public async Task<RServiceResult<GanjoorPoemCompleteViewModel>> 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<GanjoorPoemCompleteViewModel>
(
new GanjoorPoemCompleteViewModel()
{
Poem = (await GetPoemById(poemId)).Result,
Recitations = (await GetPoemRecitations(poemId)).Result,
Images = (await GetPoemImages(poemId)).Result
}
);
}
catch (Exception exp)
{
return new RServiceResult<GanjoorPoemCompleteViewModel>(null, exp.ToString());
}
}
#region Date import / modifications
/// <summary>
/// imports unimported poem data from a locally accessible ganjoor SqlLite database