diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index 40c8bef9..51cd86bf 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; using RMuseum.Models.Auth.Memory; using RMuseum.Models.Ganjoor; using RMuseum.Models.Ganjoor.ViewModels; @@ -316,6 +317,7 @@ namespace RMuseum.Controllers [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(PoemMusicTrackViewModel))] [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] [ProducesResponseType((int)HttpStatusCode.Forbidden)] + [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task GetNextUnreviewedSong(int skip = 0, bool onlyMine = false) { Guid userId = @@ -332,6 +334,28 @@ namespace RMuseum.Controllers await _ganjoorService.GetNextUnreviewedSong(skip, onlyMine ? userId : Guid.Empty); if (!string.IsNullOrEmpty(res.ExceptionString)) return BadRequest(res.ExceptionString); + + if (res.Result == null) + return NotFound(); + + var resCount = await _ganjoorService.GetUnreviewedSongsCount(onlyMine ? userId : Guid.Empty); + if (!string.IsNullOrEmpty(resCount.ExceptionString)) + return BadRequest(resCount.ExceptionString); + + // Paging Header + HttpContext.Response.Headers.Add("paging-headers", + JsonConvert.SerializeObject( + new PaginationMetadata() + { + totalCount = resCount.Result, + pageSize = -1, + currentPage = -1, + hasNextPage = false, + hasPreviousPage = false, + totalPages = -1 + }) + ); + return Ok(res.Result); } diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index dcddb3f5..f3cbc591 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -5706,6 +5706,13 @@ + + + get unreviewed count + + + + review song @@ -6546,6 +6553,13 @@ + + + get unreviewed count + + + + next unreviewed track diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index 5c0b7f4c..85d78548 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -131,6 +131,13 @@ namespace RMuseum.Services /// Task> SuggestSong(Guid userId, PoemMusicTrackViewModel song); + /// + /// get unreviewed count + /// + /// + /// + Task> GetUnreviewedSongsCount(Guid suggestedById); + /// /// review song /// diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index 6fc3e314..9ac2e2c8 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -846,6 +846,25 @@ namespace RMuseum.Services.Implementation } } + /// + /// get unreviewed count + /// + /// + /// + public async Task> GetUnreviewedSongsCount(Guid suggestedById) + { + try + { + return new RServiceResult(await _context.GanjoorPoemMusicTracks + .Where(p => p.Approved == false && p.Rejected == false && (suggestedById == Guid.Empty || p.SuggestedById == suggestedById)) + .CountAsync()); + } + catch(Exception exp) + { + return new RServiceResult(0, exp.ToString()); + } + } + /// /// next unreviewed track