diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index 503fc039..54d0d7a4 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -215,11 +215,11 @@ namespace RMuseum.Controllers [HttpGet] [Route("poem/{id}/images")] [AllowAnonymous] - [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorLinkViewModel[]))] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(PoemRelatedImage[]))] [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] public async Task GetPoemImages(int id) { - RServiceResult res = + RServiceResult res = await _ganjoorService.GetPoemImages(id); if (!string.IsNullOrEmpty(res.ExceptionString)) return BadRequest(res.ExceptionString); diff --git a/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoemCompleteViewModel.cs b/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoemCompleteViewModel.cs index 53b0c7f4..16e863cd 100644 --- a/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoemCompleteViewModel.cs +++ b/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoemCompleteViewModel.cs @@ -71,6 +71,6 @@ namespace RMuseum.Models.Ganjoor.ViewModels /// /// Images /// - public GanjoorLinkViewModel[] Images { get; set; } + public PoemRelatedImage[] Images { get; set; } } } diff --git a/RMuseum/Models/Ganjoor/ViewModels/PoemRelatedImage.cs b/RMuseum/Models/Ganjoor/ViewModels/PoemRelatedImage.cs new file mode 100644 index 00000000..c634b849 --- /dev/null +++ b/RMuseum/Models/Ganjoor/ViewModels/PoemRelatedImage.cs @@ -0,0 +1,49 @@ +namespace RMuseum.Models.Ganjoor.ViewModels +{ + /// + /// Related Image Type + /// + public enum PoemRelatedImageType + { + /// + /// musueum.ganjoor.net link + /// + MuseumLink = 0, + /// + /// external link + /// + ExternalLink = 1 + } + + /// + /// Poem Related Images + /// + public class PoemRelatedImage + { + /// + /// Image Order + /// + public int ImageOrder { get; set; } + /// + /// poem related image type + /// + public PoemRelatedImageType PoemRelatedImageType { get; set; } + + /// + /// thumbnail image url + /// + public string ThumbnailImageUrl { get; set; } + + /// + /// target page url + /// + public string TargetPageUrl { get; set; } + + /// + /// alternate text + /// + public string AltText { get; set; } + + + } +} diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index f8ac3a9e..232599c4 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -860,7 +860,18 @@ - get the corresponding xml file contemnts (xml) for the narration + get the corresponding xml file contents (xml) for the narration + + + it could be protected (Authorized), but I guess I would have problems with available client components support, + so I preferred it to be anonymous, as it does not harm anybody I guess + + + + + + + get the corresponding xml file for the recitation it could be protected (Authorized), but I guess I would have problems with available client components support, @@ -2360,7 +2371,7 @@ - Xml Url + Xml Text, xml file url is https://ganjgah.ir/api/audio/file/{audio.Id}.xml @@ -3687,6 +3698,51 @@ text + + + Related Image Type + + + + + musueum.ganjoor.net link + + + + + external link + + + + + Poem Related Images + + + + + Image Order + + + + + poem related image type + + + + + thumbnail image url + + + + + target page url + + + + + alternate text + + Import Job diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index 557a7666..de5fa824 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -96,7 +96,7 @@ namespace RMuseum.Services /// /// /// - Task> GetPoemImages(int id); + Task> GetPoemImages(int id); /// /// get a random poem from hafez diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index 0b5da3fb..5793309b 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -325,11 +325,11 @@ namespace RMuseum.Services.Implementation /// /// /// - public async Task> GetPoemImages(int id) + public async Task> GetPoemImages(int id) { try { - var source = + var museumSrc = from link in _context.GanjoorLinks.Include(l => l.Artifact).Include(l => l.Item).ThenInclude(i => i.Images) join poem in _context.GanjoorPoems on link.GanjoorPostId equals poem.Id @@ -338,24 +338,45 @@ namespace RMuseum.Services.Implementation && poem.Id == id orderby link.ReviewDate - select new GanjoorLinkViewModel() + select new PoemRelatedImage() { - Id = link.Id, - GanjoorPostId = link.GanjoorPostId, - GanjoorUrl = $"https://ganjoor.net{poem.FullUrl}", - GanjoorTitle = poem.FullTitle, - EntityName = $"{link.Artifact.Name} » {link.Item.Name}", - EntityFriendlyUrl = $"https://museum.ganjoor.net/items/{link.Artifact.FriendlyUrl}/{link.Item.FriendlyUrl}", - 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) + PoemRelatedImageType = PoemRelatedImageType.MuseumLink, + ThumbnailImageUrl = $"https://ganjgah.ir/api/images/thumb/{link.Item.Images.First().Id}.jpg", + TargetPageUrl = $"https://museum.ganjoor.net/items/{link.Artifact.FriendlyUrl}/{link.Item.FriendlyUrl}", + AltText = $"{link.Artifact.Name} » {link.Item.Name}", }; - return new RServiceResult(await source.ToArrayAsync()); + List museumImages = await museumSrc.ToListAsync(); + + var externalSrc = + from link in _context.PinterestLinks + 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 PoemRelatedImage() + { + PoemRelatedImageType = PoemRelatedImageType.ExternalLink, + ThumbnailImageUrl = $"https://ganjgah.ir/api/images/thumb/{link.Item.Images.First().Id}.jpg", + TargetPageUrl = $"https://museum.ganjoor.net/items/{link.Artifact.FriendlyUrl}/{link.Item.FriendlyUrl}", + AltText = link.AltText, + }; + + museumImages.AddRange(await externalSrc.ToListAsync()); + + for(int i=0; i(museumImages.ToArray()); } catch (Exception exp) { - return new RServiceResult(null, exp.ToString()); + return new RServiceResult(null, exp.ToString()); } } @@ -512,7 +533,7 @@ namespace RMuseum.Services.Implementation rc = rcRes.Result; } - GanjoorLinkViewModel[] imgs = null; + PoemRelatedImage[] imgs = null; if(images) { var imgsRes = await GetPoemImages(id);