diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs
index e93196b2..0eae839c 100644
--- a/RMuseum/Controllers/GanjoorController.cs
+++ b/RMuseum/Controllers/GanjoorController.cs
@@ -35,6 +35,25 @@ namespace RMuseum.Controllers
return Ok(res.Result);
}
+ ///
+ /// poet by id
+ ///
+ ///
+ ///
+ [HttpGet]
+ [Route("poet/{id}")]
+ [AllowAnonymous]
+ [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoetCompleteViewModel))]
+ [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
+ public async Task GetPoetById(int id)
+ {
+ RServiceResult res =
+ await _ganjoorService.GetPoetById(id);
+ if (!string.IsNullOrEmpty(res.ExceptionString))
+ return BadRequest(res.ExceptionString);
+ return Ok(res.Result);
+ }
+
///
/// get poem by id
///
diff --git a/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoetCompleteViewModel.cs b/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoetCompleteViewModel.cs
new file mode 100644
index 00000000..38625aa1
--- /dev/null
+++ b/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoetCompleteViewModel.cs
@@ -0,0 +1,30 @@
+using System.Collections.Generic;
+
+namespace RMuseum.Models.Ganjoor.ViewModels
+{
+ ///
+ /// Poet Complete Information
+ ///
+ public class GanjoorPoetCompleteViewModel
+ {
+ ///
+ /// poet info
+ ///
+ public GanjoorPoet Poet { get; set; }
+
+ ///
+ /// poet cat info
+ ///
+ public GanjoorCat Cat { get; set; }
+
+ ///
+ /// poet cat children
+ ///
+ public ICollection Children { get; set; }
+
+ ///
+ /// poems
+ ///
+ public ICollection Poems { get; set; }
+ }
+}
diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml
index 24b8e439..eac6d172 100644
--- a/RMuseum/RMuseum.xml
+++ b/RMuseum/RMuseum.xml
@@ -622,6 +622,13 @@
+
+
+ poet by id
+
+
+
+
get poem by id
@@ -3436,6 +3443,31 @@
Images
+
+
+ Poet Complete Information
+
+
+
+
+ poet info
+
+
+
+
+ poet cat info
+
+
+
+
+ poet cat children
+
+
+
+
+ poems
+
+
Import Job
@@ -4449,6 +4481,13 @@
+
+
+ get poet by id
+
+
+
+
get poem by id
@@ -5195,6 +5234,20 @@
+
+
+ get poet by id
+
+
+
+
+
+
+ get poet by url
+
+ base web site address should be removed: hafez or /hafez and not https://ganjoor.net/hafez
+
+
get poem by id
diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs
index defdd3a5..3e5f24fe 100644
--- a/RMuseum/Services/IGanjoorService.cs
+++ b/RMuseum/Services/IGanjoorService.cs
@@ -19,6 +19,14 @@ namespace RMuseum.Services
///
Task> GetPoets(bool websitePoets);
+ ///
+ /// get poet by id
+ ///
+ ///
+ ///
+ Task> GetPoetById(int id);
+
+
///
/// get poem by id
///
diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs
index 85913218..5373d14a 100644
--- a/RMuseum/Services/Implementation/GanjoorService.cs
+++ b/RMuseum/Services/Implementation/GanjoorService.cs
@@ -40,12 +40,64 @@ namespace RMuseum.Services.Implementation
.ToArrayAsync()
);
}
- catch(Exception exp)
+ catch (Exception exp)
{
return new RServiceResult(null, exp.ToString());
}
}
+ ///
+ /// get poet by id
+ ///
+ ///
+ ///
+ public async Task> GetPoetById(int id)
+ {
+ try
+ {
+ var poet = await _context.GanjoorPoets.Where(p => p.Id == id).FirstOrDefaultAsync();
+ if (poet == null)
+ return new RServiceResult(null);
+ var cat = await _context.GanjoorCategories.Where(c => c.ParentId == null && c.PoetId == id).FirstOrDefaultAsync();
+
+ return new RServiceResult
+ (
+ new GanjoorPoetCompleteViewModel()
+ {
+ Poet = poet,
+ Cat = cat,
+ Children = await _context.GanjoorCategories.Where(c => c.ParentId == cat.Id).ToListAsync(),
+ Poems = await _context.GanjoorPoems.Where(p => p.CatId == cat.Id).ToListAsync()
+ }
+ );
+ }
+ catch(Exception exp)
+ {
+ return new RServiceResult(null, exp.ToString());
+ }
+ }
+
+ ///
+ /// get poet by url
+ ///
+ /// base web site address should be removed: hafez or /hafez and not https://ganjoor.net/hafez
+ ///
+ public async Task> GetPoetByUrl(string url)
+ {
+ try
+ {
+ url = url.Replace("/", "");
+ var cat = await _context.GanjoorCategories.Where(c => c.UrlSlug == url).SingleOrDefaultAsync();
+ if (cat == null)
+ return new RServiceResult(null);
+ return await GetPoetById(cat.PoetId);
+ }
+ catch (Exception exp)
+ {
+ return new RServiceResult(null, exp.ToString());
+ }
+ }
+
///
/// get poem by id
///