#65 api for displaying poem comments
This commit is contained in:
parent
8a232b3e2d
commit
f71a31effe
@ -44,4 +44,5 @@ namespace RMuseum.Models.Ganjoor.ViewModels
|
||||
public GanjoorCommentSummaryViewModel[] Replies { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -96,5 +96,10 @@ namespace RMuseum.Models.Ganjoor.ViewModels
|
||||
/// Songs
|
||||
/// </summary>
|
||||
public PoemMusicTrackViewModel[] Songs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Comments
|
||||
/// </summary>
|
||||
public GanjoorCommentSummaryViewModel[] Comments { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -4368,6 +4368,11 @@
|
||||
Songs
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemCompleteViewModel.Comments">
|
||||
<summary>
|
||||
Comments
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemSummaryViewModel">
|
||||
<summary>
|
||||
poem summary
|
||||
@ -6727,6 +6732,14 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetPoemComments(System.Int32,System.Guid)">
|
||||
<summary>
|
||||
get poem comments
|
||||
</summary>
|
||||
<param name="poemId"></param>
|
||||
<param name="userId"></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),
|
||||
|
||||
@ -416,23 +416,18 @@ namespace RMuseum.Services.Implementation
|
||||
return new RServiceResult<PublicRecitationViewModel[]>(null, exp.ToString());
|
||||
}
|
||||
}
|
||||
/*
|
||||
public async Task<RServiceResult<GanjoorCommentSummaryViewModel[]>> GetPoemComments(int id, Guid userId)
|
||||
|
||||
/// <summary>
|
||||
/// get poem comments
|
||||
/// </summary>
|
||||
/// <param name="poemId"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<GanjoorCommentSummaryViewModel[]>> GetPoemComments(int poemId, Guid userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var source =
|
||||
from comment in _context.GanjoorComments
|
||||
where
|
||||
(comment.Status == PublishStatus.Published || (userId != Guid.Empty && comment.Status == PublishStatus.Awaiting && comment.UserId == userId))
|
||||
&&
|
||||
comment.Id == id
|
||||
orderby comment.CommentDate
|
||||
select new GanjoorCommentSummaryViewModel()
|
||||
{
|
||||
Id = comment.Id,
|
||||
};
|
||||
return new RServiceResult<GanjoorCommentSummaryViewModel[]>(await source.ToArrayAsync());
|
||||
return new RServiceResult<GanjoorCommentSummaryViewModel[]>(await _GetPoemComments(poemId, userId, null));
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
@ -440,24 +435,35 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<GanjoorCommentSummaryViewModel[]> _GetPoemComments(int id, Guid userId, int? inReplyToId)
|
||||
private async Task<GanjoorCommentSummaryViewModel[]> _GetPoemComments(int poemId, Guid userId, int? inReplyToId)
|
||||
{
|
||||
var source =
|
||||
from comment in _context.GanjoorComments
|
||||
where
|
||||
(comment.Status == PublishStatus.Published || (userId != Guid.Empty && comment.Status == PublishStatus.Awaiting && comment.UserId == userId))
|
||||
&&
|
||||
comment.Id == id
|
||||
&&
|
||||
comment.InReplyToId == inReplyToId
|
||||
orderby comment.CommentDate
|
||||
select new GanjoorCommentSummaryViewModel()
|
||||
{
|
||||
Id = comment.Id,
|
||||
};
|
||||
return await source.ToArrayAsync();
|
||||
from comment in _context.GanjoorComments.Include(c => c.User)
|
||||
where
|
||||
(comment.Status == PublishStatus.Published || (userId != Guid.Empty && comment.Status == PublishStatus.Awaiting && comment.UserId == userId))
|
||||
&&
|
||||
comment.PoemId == poemId
|
||||
&&
|
||||
comment.InReplyToId == inReplyToId
|
||||
orderby comment.CommentDate
|
||||
select new GanjoorCommentSummaryViewModel()
|
||||
{
|
||||
Id = comment.Id,
|
||||
AuthorName = comment.User == null ? comment.AuthorName : $"{comment.User.FirstName} {comment.User.SureName}".Trim(),
|
||||
AuthorUrl = comment.AuthorUrl,
|
||||
CommentDate = comment.CommentDate,
|
||||
HtmlComment = comment.HtmlComment,
|
||||
PublishStatus = comment.Status == PublishStatus.Awaiting ? "در انتظار تأیید" : ""
|
||||
};
|
||||
var comments = await source.ToArrayAsync();
|
||||
|
||||
foreach(var comment in comments)
|
||||
{
|
||||
comment.Replies = await _GetPoemComments(poemId, userId, comment.Id);
|
||||
}
|
||||
return comments;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// get poem images by id (some fields are intentionally field with blank or null),
|
||||
@ -712,6 +718,17 @@ namespace RMuseum.Services.Implementation
|
||||
tracks = songsRes.Result;
|
||||
}
|
||||
|
||||
GanjoorCommentSummaryViewModel[] poemComments = null;
|
||||
|
||||
if(comments)
|
||||
{
|
||||
var commentsRes = await GetPoemComments(id, Guid.Empty);
|
||||
if (!string.IsNullOrEmpty(commentsRes.ExceptionString))
|
||||
return new RServiceResult<GanjoorPoemCompleteViewModel>(null, commentsRes.ExceptionString);
|
||||
poemComments = commentsRes.Result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return new RServiceResult<GanjoorPoemCompleteViewModel>
|
||||
(
|
||||
@ -734,7 +751,8 @@ namespace RMuseum.Services.Implementation
|
||||
Recitations = rc,
|
||||
Images = imgs,
|
||||
Verses = verses,
|
||||
Songs = tracks
|
||||
Songs = tracks,
|
||||
Comments = poemComments
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user