/api/ganjoor/comments/id API for retrieving a single comment information
This commit is contained in:
parent
5bd31dc7ae
commit
daab3b6735
@ -1848,6 +1848,31 @@ namespace RMuseum.Controllers
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get a single comment information (replies are not included)
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("comments/{id}")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorCommentFullViewModel))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> GetCommentByIdAsync(int id)
|
||||
{
|
||||
var res = await _ganjoorService.GetCommentByIdAsync(id);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
{
|
||||
return BadRequest(res.ExceptionString);
|
||||
}
|
||||
if(res.Result == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get recent comments
|
||||
/// </summary>
|
||||
|
||||
@ -1458,6 +1458,13 @@
|
||||
<param name="poetId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetCommentByIdAsync(System.Int32)">
|
||||
<summary>
|
||||
get a single comment information (replies are not included)
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetRecentComments(RSecurityBackend.Models.Generic.PagingParameterModel,System.Nullable{System.Guid},System.String)">
|
||||
<summary>
|
||||
get recent comments
|
||||
@ -14888,6 +14895,13 @@
|
||||
<param name="coupletIndex"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.GetCommentByIdAsync(System.Int32)">
|
||||
<summary>
|
||||
get a single comment information (replies are not included)
|
||||
</summary>
|
||||
<param name="commentId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.GetRelatedSections(System.Int32,System.Int32,System.Int32,System.Int32)">
|
||||
<summary>
|
||||
get a section related sections
|
||||
@ -18462,6 +18476,13 @@
|
||||
<param name="coupletIndex"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetCommentByIdAsync(System.Int32)">
|
||||
<summary>
|
||||
get a single comment information (replies are not included)
|
||||
</summary>
|
||||
<param name="commentId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.NewComment(System.Guid,System.String,System.Int32,System.String,System.Nullable{System.Int32},System.Nullable{System.Int32})">
|
||||
<summary>
|
||||
new comment
|
||||
|
||||
@ -211,6 +211,13 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorCommentSummaryViewModel[]>> GetPoemComments(int poemId, Guid userId, int? coupletIndex);
|
||||
|
||||
/// <summary>
|
||||
/// get a single comment information (replies are not included)
|
||||
/// </summary>
|
||||
/// <param name="commentId"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorCommentSummaryViewModel>> GetCommentByIdAsync(int commentId);
|
||||
|
||||
/// <summary>
|
||||
/// get a section related sections
|
||||
/// </summary>
|
||||
|
||||
@ -854,8 +854,6 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// get poem comments
|
||||
/// </summary>
|
||||
@ -919,6 +917,53 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get a single comment information (replies are not included)
|
||||
/// </summary>
|
||||
/// <param name="commentId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<GanjoorCommentSummaryViewModel>> GetCommentByIdAsync(int commentId)
|
||||
{
|
||||
var source =
|
||||
from c in _context.GanjoorComments.Include(c => c.User)
|
||||
where
|
||||
c.Status == PublishStatus.Published
|
||||
&&
|
||||
c.Id == commentId
|
||||
select new GanjoorCommentSummaryViewModel()
|
||||
{
|
||||
Id = c.Id,
|
||||
AuthorName = c.User == null ? c.AuthorName : $"{c.User.NickName}",
|
||||
AuthorUrl = c.AuthorUrl,
|
||||
CommentDate = c.CommentDate,
|
||||
HtmlComment = c.HtmlComment,
|
||||
PublishStatus = c.Status == PublishStatus.Awaiting ? "در انتظار تأیید" : "",
|
||||
InReplyToId = c.InReplyToId,
|
||||
UserId = c.UserId,
|
||||
CoupletIndex = c.CoupletIndex == null ? -1 : (int)c.CoupletIndex,
|
||||
};
|
||||
|
||||
GanjoorCommentSummaryViewModel comment = await source.AsNoTracking().SingleOrDefaultAsync();
|
||||
if (comment == null)
|
||||
{
|
||||
return new RServiceResult<GanjoorCommentSummaryViewModel>(null);
|
||||
}
|
||||
|
||||
comment.AuthorName = comment.AuthorName.ToPersianNumbers().ApplyCorrectYeKe();
|
||||
|
||||
var dbComment = await _context.GanjoorComments.AsNoTracking().Where(c => c.Id == commentId).SingleAsync();
|
||||
|
||||
var relatedVerses = comment.CoupletIndex == -1 ? new List<GanjoorVerse>() : await _context.GanjoorVerses.Where(v => v.PoemId == dbComment.PoemId && v.CoupletIndex == comment.CoupletIndex).OrderBy(v => v.VOrder).ToListAsync();
|
||||
string coupleText = relatedVerses.Count == 0 ? "" : relatedVerses[0].Text;
|
||||
for (int nVerseIndex = 1; nVerseIndex < relatedVerses.Count; nVerseIndex++)
|
||||
{
|
||||
coupleText += $" {relatedVerses[nVerseIndex].Text}";
|
||||
}
|
||||
comment.CoupletSummary = _CutSummary(coupleText);
|
||||
|
||||
return new RServiceResult<GanjoorCommentSummaryViewModel>(comment);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// new comment
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user