#264 create a more brief version of this API:
/api/ganjoor/poem/{poemId}/recitations/upvotes
to only return an array of int (only upvoted ones)
This commit is contained in:
parent
32bd764bd0
commit
a809c6b456
@ -837,7 +837,7 @@ namespace GanjooRazor.Pages
|
||||
return new OkObjectResult(false);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnGetGetUserUpvotedRecitationsAsync(int poemId)
|
||||
public async Task<IActionResult> OnGetUserUpvotedRecitationsAsync(int poemId)
|
||||
{
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
@ -848,7 +848,7 @@ namespace GanjooRazor.Pages
|
||||
{
|
||||
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
|
||||
}
|
||||
var res = JsonConvert.DeserializeObject<RecitationUserUpVoteViewModel[]>(await response.Content.ReadAsStringAsync());
|
||||
var res = JsonConvert.DeserializeObject<int[]>(await response.Content.ReadAsStringAsync());
|
||||
return new OkObjectResult(res);
|
||||
}
|
||||
}
|
||||
|
||||
@ -868,15 +868,13 @@ function MarkUserUpvotedRecitations(poemId) {
|
||||
setTimeout(function () {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: '?Handler=GetUserUpvotedRecitations&poemId=' + String(poemId),
|
||||
url: '?Handler=UserUpvotedRecitations&poemId=' + String(poemId),
|
||||
error: function (err) {
|
||||
console.log(err);
|
||||
},
|
||||
success: function (result) {
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
if (result[i].upVote) {
|
||||
document.getElementById('recitaion-' + String(result[i].id)).classList.add('recitation-vote');
|
||||
}
|
||||
document.getElementById('recitaion-' + String(result[i])).classList.add('recitation-vote');
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@ -804,19 +804,19 @@ namespace RMuseum.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get user up votes for the recitations of a poem
|
||||
/// get user upvoted recitations of a poem
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("poem/{id}/recitations/upvotes")]
|
||||
[Authorize]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(RecitationUserUpVoteViewModel[]))]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(int[]))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public async Task<IActionResult> GetUserPoemRecitationsUpVotes(int id)
|
||||
{
|
||||
var loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
|
||||
RServiceResult<RecitationUserUpVoteViewModel[]> res =
|
||||
RServiceResult<int[]> res =
|
||||
await _ganjoorService.GetUserPoemRecitationsUpVotes(id, loggedOnUserId);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
namespace RMuseum.Models.GanjoorAudio.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// recitation user up vote
|
||||
/// </summary>
|
||||
public class RecitationUserUpVoteViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// reciation id
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// up vote
|
||||
/// </summary>
|
||||
public bool UpVote { get; set; }
|
||||
}
|
||||
}
|
||||
@ -958,7 +958,7 @@
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetUserPoemRecitationsUpVotes(System.Int32)">
|
||||
<summary>
|
||||
get user up votes for the recitations of a poem
|
||||
get user upvoted recitations of a poem
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
@ -4115,21 +4115,6 @@
|
||||
Finish Date
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RMuseum.Models.GanjoorAudio.ViewModels.RecitationUserUpVoteViewModel">
|
||||
<summary>
|
||||
recitation user up vote
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.GanjoorAudio.ViewModels.RecitationUserUpVoteViewModel.Id">
|
||||
<summary>
|
||||
reciation id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.GanjoorAudio.ViewModels.RecitationUserUpVoteViewModel.UpVote">
|
||||
<summary>
|
||||
up vote
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RMuseum.Models.GanjoorAudio.ViewModels.RecitationVerseSync">
|
||||
<summary>
|
||||
Verse Sync Range
|
||||
|
||||
@ -129,7 +129,7 @@ namespace RMuseum.Services
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<RecitationUserUpVoteViewModel[]>> GetUserPoemRecitationsUpVotes(int id, Guid userId);
|
||||
Task<RServiceResult<int[]>> GetUserPoemRecitationsUpVotes(int id, Guid userId);
|
||||
|
||||
/// <summary>
|
||||
/// get poem images by id (some fields are intentionally field with blank or null),
|
||||
|
||||
@ -556,7 +556,7 @@ namespace RMuseum.Services.Implementation
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<RecitationUserUpVoteViewModel[]>> GetUserPoemRecitationsUpVotes(int id, Guid userId)
|
||||
public async Task<RServiceResult<int[]>> GetUserPoemRecitationsUpVotes(int id, Guid userId)
|
||||
{
|
||||
var source =
|
||||
from audio in _context.Recitations
|
||||
@ -567,19 +567,19 @@ namespace RMuseum.Services.Implementation
|
||||
&&
|
||||
poem.Id == id
|
||||
orderby audio.AudioOrder
|
||||
select new RecitationUserUpVoteViewModel
|
||||
{
|
||||
Id = audio.Id
|
||||
};
|
||||
|
||||
var recitationUpVotes = await source.ToArrayAsync();
|
||||
foreach (var recitationUpVote in recitationUpVotes)
|
||||
select audio.Id;
|
||||
|
||||
List<int> upVotedRecitations = new List<int>();
|
||||
var recitationIds = await source.ToArrayAsync();
|
||||
foreach (var recitationId in recitationIds)
|
||||
{
|
||||
recitationUpVote.UpVote =
|
||||
await _context.RecitationUserUpVotes.Where(v => v.RecitationId == recitationUpVote.Id && v.UserId == userId).AnyAsync();
|
||||
if (await _context.RecitationUserUpVotes.Where(v => v.RecitationId == recitationId && v.UserId == userId).AnyAsync())
|
||||
{
|
||||
upVotedRecitations.Add(recitationId);
|
||||
}
|
||||
}
|
||||
|
||||
return new RServiceResult<RecitationUserUpVoteViewModel[]>(recitationUpVotes);
|
||||
return new RServiceResult<int[]>(upVotedRecitations.ToArray());
|
||||
}
|
||||
|
||||
private async Task _FillPoemCoupletIndices(RMuseumDbContext context, int poemId)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user