#48 related images API (untested)
This commit is contained in:
parent
b949f49f5a
commit
fe38acc26c
@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using RMuseum.Models.Auth.Memory;
|
||||
using RMuseum.Models.Ganjoor;
|
||||
using RMuseum.Models.GanjoorAudio.ViewModels;
|
||||
using RMuseum.Models.GanjoorIntegration.ViewModels;
|
||||
using RMuseum.Services;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using System.Net;
|
||||
@ -52,6 +53,25 @@ namespace RMuseum.Controllers
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get poem images (PlainText/HtmlText are intentionally empty)
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("poem/{id}/images")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorLinkViewModel[]))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public async Task<IActionResult> GetPoemImages(int id)
|
||||
{
|
||||
RServiceResult<GanjoorLinkViewModel[]> res =
|
||||
await _ganjoorService.GetPoemImages(id);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// imports data from ganjoor SQLite database
|
||||
/// </summary>
|
||||
|
||||
@ -8,6 +8,21 @@ namespace RMuseum.Models.GanjoorIntegration.ViewModels
|
||||
/// </summary>
|
||||
public class GanjoorLinkViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// default constructor
|
||||
/// </summary>
|
||||
public GanjoorLinkViewModel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// parameterized constructor
|
||||
/// </summary>
|
||||
/// <param name="src"></param>
|
||||
/// <param name="entityName"></param>
|
||||
/// <param name="entityFriendlyUrl"></param>
|
||||
/// <param name="entityImageId"></param>
|
||||
public GanjoorLinkViewModel(GanjoorLink src, string entityName, string entityFriendlyUrl, Guid entityImageId)
|
||||
{
|
||||
Id = src.Id;
|
||||
|
||||
@ -629,6 +629,13 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetPoemImages(System.Int32)">
|
||||
<summary>
|
||||
get poem images (PlainText/HtmlText are intentionally empty)
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.ImportLocalSQLiteDb">
|
||||
<summary>
|
||||
imports data from ganjoor SQLite database
|
||||
@ -2950,6 +2957,20 @@
|
||||
Ganjoor Link View Model
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Models.GanjoorIntegration.ViewModels.GanjoorLinkViewModel.#ctor">
|
||||
<summary>
|
||||
default constructor
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Models.GanjoorIntegration.ViewModels.GanjoorLinkViewModel.#ctor(RMuseum.Models.GanjoorIntegration.GanjoorLink,System.String,System.String,System.Guid)">
|
||||
<summary>
|
||||
parameterized constructor
|
||||
</summary>
|
||||
<param name="src"></param>
|
||||
<param name="entityName"></param>
|
||||
<param name="entityFriendlyUrl"></param>
|
||||
<param name="entityImageId"></param>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.GanjoorIntegration.ViewModels.GanjoorLinkViewModel.Id">
|
||||
<summary>
|
||||
Id
|
||||
@ -4402,6 +4423,14 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.GetPoemImages(System.Int32)">
|
||||
<summary>
|
||||
get poem images by id (some fields are intentionally field with blank or null),
|
||||
EntityImageId : the most important data field, image url is https://ganjgah.ir/api/images/thumb/{EntityImageId}.jpg or https://ganjgah.ir/api/images/norm/{EntityImageId}.jpg
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.ImportLocalSQLiteDb">
|
||||
<summary>
|
||||
imports unimported poem data from a locally accessible ganjoor SqlLite database
|
||||
@ -5127,6 +5156,14 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetPoemImages(System.Int32)">
|
||||
<summary>
|
||||
get poem images by id (some fields are intentionally field with blank or null),
|
||||
EntityImageId : the most important data field, image url is https://ganjgah.ir/api/images/thumb/{EntityImageId}.jpg or https://ganjgah.ir/api/images/norm/{EntityImageId}.jpg
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.ImportLocalSQLiteDb">
|
||||
<summary>
|
||||
imports unimported poem data from a locally accessible ganjoor SqlLite database
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using RMuseum.Models.Ganjoor;
|
||||
using RMuseum.Models.GanjoorAudio.ViewModels;
|
||||
using RMuseum.Models.GanjoorIntegration.ViewModels;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -24,6 +25,14 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<PublicRecitationViewModel[]>> GetPoemRecitations(int id);
|
||||
|
||||
/// <summary>
|
||||
/// get poem images by id (some fields are intentionally field with blank or null),
|
||||
/// EntityImageId : the most important data field, image url is https://ganjgah.ir/api/images/thumb/{EntityImageId}.jpg or https://ganjgah.ir/api/images/norm/{EntityImageId}.jpg
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorLinkViewModel[]>> GetPoemImages(int id);
|
||||
|
||||
/// <summary>
|
||||
/// imports unimported poem data from a locally accessible ganjoor SqlLite database
|
||||
/// </summary>
|
||||
|
||||
@ -6,6 +6,7 @@ using RMuseum.DbContext;
|
||||
using RMuseum.Models.Ganjoor;
|
||||
using RMuseum.Models.GanjoorAudio;
|
||||
using RMuseum.Models.GanjoorAudio.ViewModels;
|
||||
using RMuseum.Models.GanjoorIntegration.ViewModels;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using System;
|
||||
using System.Data;
|
||||
@ -93,6 +94,45 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get poem images by id (some fields are intentionally field with blank or null),
|
||||
/// EntityImageId : the most important data field, image url is https://ganjgah.ir/api/images/thumb/{EntityImageId}.jpg or https://ganjgah.ir/api/images/norm/{EntityImageId}.jpg
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<GanjoorLinkViewModel[]>> GetPoemImages(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var source =
|
||||
from link in _context.GanjoorLinks.Include(l => l.Item).ThenInclude(i => i.Images)
|
||||
join poem in _context.GanjoorPoems
|
||||
on link.GanjoorPostId equals poem.Id
|
||||
where
|
||||
link.ReviewResult == Models.GanjoorIntegration.ReviewResult.Approved
|
||||
&&
|
||||
poem.Id == id
|
||||
orderby link.ReviewDate
|
||||
select new GanjoorLinkViewModel()
|
||||
{
|
||||
Id = link.Id,
|
||||
GanjoorPostId = link.GanjoorPostId,
|
||||
GanjoorUrl = $"https://ganjoor.net{poem.FullUrl}",
|
||||
GanjoorTitle = poem.FullTitle,
|
||||
EntityName = "", //intentional
|
||||
EntityFriendlyUrl = "", //intentional
|
||||
EntityImageId = link.Item.Images.First().Id,//the most important data field, image url is https://ganjgah.ir/api/images/thumb/{EntityImageId}.jpg
|
||||
ReviewResult = link.ReviewResult,
|
||||
Synchronized = link.Synchronized,
|
||||
SuggestedBy = null //intentional (this is going to be used in an anonymous method)
|
||||
};
|
||||
return new RServiceResult<GanjoorLinkViewModel[]>(await source.ToArrayAsync());
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<GanjoorLinkViewModel[]>(null, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
#region Date import / modifications
|
||||
/// <summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user