diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index dad1a8e3..503fc039 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -157,6 +157,37 @@ namespace RMuseum.Controllers return Ok(res.Result); } + /// + /// get poem by url + /// + /// + /// + /// + /// not implemented yet + /// + /// + /// not implemented yet + /// not implemented yet + /// + /// next/previous + /// + [HttpGet] + [Route("poem")] + [AllowAnonymous] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoemCompleteViewModel))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + [ProducesResponseType((int)HttpStatusCode.NotFound)] + public async Task GetPoemByUrl(string url, bool catInfo = true, bool catPoems = false, bool rhymes = true, bool recitations = true, bool images = true, bool songs = true, bool comments = true, bool verseDetails = true, bool navigation = true) + { + RServiceResult res = + await _ganjoorService.GetPoemByUrl(url, catInfo, catPoems, rhymes, recitations, images, songs, comments, verseDetails, navigation); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + if (res.Result == null) + return NotFound(); + return Ok(res.Result); + } + /// /// get poem recitations (PlainText/HtmlText are intentionally empty) /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 737baf75..f8ac3a9e 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -669,6 +669,22 @@ next/previous + + + get poem by url + + + + + not implemented yet + + + not implemented yet + not implemented yet + + next/previous + + get poem recitations (PlainText/HtmlText are intentionally empty) @@ -4731,6 +4747,22 @@ + + + Get Poem By Url + + + + + + + + + + + + + get poem recitations (PlainText/HtmlText are intentionally empty) @@ -5516,6 +5548,22 @@ + + + Get Poem By Url + + + + + + + + + + + + + Get Poem By Id diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index d22de313..557a7666 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -67,6 +67,22 @@ namespace RMuseum.Services /// Task> GetPoemById(int id, bool catInfo = true, bool catPoems = false, bool rhymes = true, bool recitations = true, bool images = true, bool songs = true, bool comments = true, bool verseDetails = true, bool navigation = true); + /// + /// Get Poem By Url + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + Task> GetPoemByUrl(string url, bool catInfo = true, bool catPoems = false, bool rhymes = true, bool recitations = true, bool images = true, bool songs = true, bool comments = true, bool verseDetails = true, bool navigation = true); + /// /// get poem recitations (PlainText/HtmlText are intentionally empty) /// diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index ec586f77..0b5da3fb 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -373,6 +373,42 @@ namespace RMuseum.Services.Implementation return poemId; } + /// + /// Get Poem By Url + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public async Task> GetPoemByUrl(string url, bool catInfo = true, bool catPoems = false, bool rhymes = true, bool recitations = true, bool images = true, bool songs = true, bool comments = true, bool verseDetails = true, bool navigation = true) + { + try + { + // /hafez/ => /hafez : + if (url.LastIndexOf('/') == url.Length - 1) + { + url = url.Substring(0, url.Length - 1); + } + var poem = await _context.GanjoorPoems.Where(p => p.FullUrl == url).SingleOrDefaultAsync(); + if (poem == null) + { + return new RServiceResult(null); //not found + } + return await GetPoemById(poem.Id, catInfo, catPoems, rhymes, recitations, images, songs, comments, verseDetails, navigation); + } + catch(Exception exp) + { + return new RServiceResult(null, exp.ToString()); + } + } + /// /// Get Poem By Id ///