From dc990cea096fcf9eac1c664fa63e9515eb7bd078 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Fri, 29 Jan 2021 18:12:40 +0330 Subject: [PATCH] #70 get next unreviewed song API method --- RMuseum/Controllers/GanjoorController.cs | 31 +++++++++++++++++++ RMuseum/RMuseum.xml | 14 +++++++-- RMuseum/Services/IGanjoorService.cs | 3 +- .../Services/Implementation/GanjoorService.cs | 7 +++-- 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index 3e0abe55..d60cf038 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -304,6 +304,37 @@ namespace RMuseum.Controllers return Ok(res.Result); } + /// + /// get next unreviewed song + /// + /// + /// + /// + [HttpGet] + [Route("song")] + [Authorize] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(PoemMusicTrackViewModel))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + [ProducesResponseType((int)HttpStatusCode.Forbidden)] + public async Task GetNextUnreviewedSong(int skip = 0, bool onlyMine = false) + { + Guid userId = + new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); + Guid sessionId = + new Guid(User.Claims.FirstOrDefault(c => c.Type == "SessionId").Value); + RServiceResult sessionCheckResult = await _appUserService.SessionExists(userId, sessionId); + if (!string.IsNullOrEmpty(sessionCheckResult.ExceptionString)) + { + return StatusCode((int)HttpStatusCode.Forbidden); + } + + var res = + await _ganjoorService.GetNextUnreviewedSong(skip, onlyMine ? userId : Guid.Empty); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(res.Result); + } + /// /// get a random poem from hafez /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 45612b6b..56e814dd 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -723,6 +723,14 @@ + + + get next unreviewed song + + + + + get a random poem from hafez @@ -5660,11 +5668,12 @@ - + next unreviewed track + @@ -6508,11 +6517,12 @@ - + next unreviewed track + diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index cc49c6c3..90ffbd4e 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -119,8 +119,9 @@ namespace RMuseum.Services /// next unreviewed track /// /// + /// /// - Task> GetNextUnreviewedSong(int skip); + Task> GetNextUnreviewedSong(int skip, Guid suggestedById); /// /// suggest song diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index b1afbdf3..b1a4f53d 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -841,12 +841,15 @@ namespace RMuseum.Services.Implementation /// next unreviewed track /// /// + /// /// - public async Task> GetNextUnreviewedSong(int skip) + public async Task> GetNextUnreviewedSong(int skip, Guid suggestedById) { try { - var song = await _context.GanjoorPoemMusicTracks.Where(p => p.Approved == false && p.Rejected == false).OrderBy(p => p.Id).Skip(skip).FirstOrDefaultAsync(); + var song = await _context.GanjoorPoemMusicTracks + .Where(p => p.Approved == false && p.Rejected == false && (suggestedById == Guid.Empty || p.SuggestedById == suggestedById)) + .OrderBy(p => p.Id).Skip(skip).FirstOrDefaultAsync(); if(song != null) { return new RServiceResult