From c5bb6a1612d2246ef3c798ab957ca424d780289e Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Mon, 20 Dec 2021 19:31:00 +0330 Subject: [PATCH] #264 GET api method for a user upvoted recitations --- RMuseum/Controllers/RecitationController.cs | 24 ++++++++++ RMuseum/RMuseum.xml | 46 +++++++++++++++++++ RMuseum/Services/IRecitationService.cs | 8 ++++ .../Implementation/RecitationService.cs | 43 +++++++++++++++++ 4 files changed, 121 insertions(+) diff --git a/RMuseum/Controllers/RecitationController.cs b/RMuseum/Controllers/RecitationController.cs index 9639be31..0da50104 100644 --- a/RMuseum/Controllers/RecitationController.cs +++ b/RMuseum/Controllers/RecitationController.cs @@ -948,6 +948,30 @@ namespace RMuseum.Controllers return Ok(res.Result); } + /// + /// get user upvoted recitations + /// + /// + /// + [HttpGet("votes")] + [Authorize] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task GetUserUpvotedRecitationsAsync([FromQuery] PagingParameterModel paging) + { + if (paging.PageSize == -1 || paging.PageSize > 1000) + paging.PageSize = 1000; + Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); + var res = await _audioService.GetUserUpvotedRecitationsAsync(paging, loggedOnUserId); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + + // Paging Header + HttpContext.Response.Headers.Add("paging-headers", JsonConvert.SerializeObject(res.Result.PagingMeta)); + + return Ok(res.Result.Items); + } + /// /// readonly mode /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 3da5888c..af4ea37e 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -1852,6 +1852,20 @@ + + + revoke recitaion up vote + + + + + + + get user upvoted recitations + + + + readonly mode @@ -12584,6 +12598,22 @@ + + + switches recitation upvote + + + + upvote status + + + + get user upvoted recitations + + + + + Upload Enabled (temporary switch off/on for upload) @@ -12980,6 +13010,22 @@ + + + switches recitation upvote + + + + upvote status + + + + get user upvoted recitations + + + + + Upload Enabled (temporary switch off/on for upload) diff --git a/RMuseum/Services/IRecitationService.cs b/RMuseum/Services/IRecitationService.cs index b3cc85e9..35b5b56d 100644 --- a/RMuseum/Services/IRecitationService.cs +++ b/RMuseum/Services/IRecitationService.cs @@ -262,6 +262,14 @@ namespace RMuseum.Services /// upvote status Task> SwitchRecitationUpVoteAsync(int id, Guid userId); + /// + /// get user upvoted recitations + /// + /// + /// + /// + Task> GetUserUpvotedRecitationsAsync(PagingParameterModel paging, Guid userId); + /// /// Upload Enabled (temporary switch off/on for upload) /// diff --git a/RMuseum/Services/Implementation/RecitationService.cs b/RMuseum/Services/Implementation/RecitationService.cs index 540f216c..b8d764c9 100644 --- a/RMuseum/Services/Implementation/RecitationService.cs +++ b/RMuseum/Services/Implementation/RecitationService.cs @@ -2021,6 +2021,49 @@ namespace RMuseum.Services.Implementationa } } + /// + /// get user upvoted recitations + /// + /// + /// + /// + public async Task> GetUserUpvotedRecitationsAsync(PagingParameterModel paging, Guid userId) + { + var source = + from upvote in _context.RecitationUserUpVotes.AsNoTracking().Include(u => u.Recitation) + join poem in _context.GanjoorPoems + on upvote.Recitation.GanjoorPostId equals poem.Id + where + upvote.UserId == userId + orderby upvote.DateTime descending + select new PublicRecitationViewModel() + { + Id = upvote.Recitation.Id, + PoemId = poem.Id, + PoemFullTitle = poem.FullTitle, + PoemFullUrl = poem.FullUrl, + AudioTitle = upvote.Recitation.AudioTitle, + AudioArtist = upvote.Recitation.AudioArtist, + AudioArtistUrl = upvote.Recitation.AudioArtistUrl, + AudioSrc = upvote.Recitation.AudioSrc, + AudioSrcUrl = upvote.Recitation.AudioSrcUrl, + LegacyAudioGuid = upvote.Recitation.LegacyAudioGuid, + Mp3FileCheckSum = upvote.Recitation.Mp3FileCheckSum, + Mp3SizeInBytes = upvote.Recitation.Mp3SizeInBytes, + PublishDate = upvote.Recitation.ReviewDate, + FileLastUpdated = upvote.Recitation.FileLastUpdated, + Mp3Url = $"{WebServiceUrl.Url}/api/audio/file/{upvote.Recitation.Id}.mp3", + XmlText = $"{WebServiceUrl.Url}/api/audio/xml/{upvote.Recitation.Id}", + PlainText = poem.PlainText, + HtmlText = poem.HtmlText + }; + + (PaginationMetadata PagingMeta, PublicRecitationViewModel[] Items) paginatedResult = + await QueryablePaginator.Paginate(source, paging); + + return new RServiceResult<(PaginationMetadata PagingMeta, PublicRecitationViewModel[] Items)>(paginatedResult); + } + /// /// Upload Enabled (temporary switch off/on for upload) ///