From ac063905c51cc6e7b4acc0fa0711c0a728363336 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Sun, 17 Jan 2021 21:31:34 +0330 Subject: [PATCH] #66 api for poem unapproved suggested related songs --- RMuseum/Controllers/GanjoorController.cs | 21 +++++ RMuseum/Models/Ganjoor/PoemMusicTrackType.cs | 4 + .../ViewModels/PoemMusicTrackViewModel.cs | 5 ++ RMuseum/RMuseum.xml | 37 +++++++++ RMuseum/Services/IGanjoorService.cs | 12 +++ .../Services/Implementation/GanjoorService.cs | 80 +++++++++++++------ 6 files changed, 136 insertions(+), 23 deletions(-) diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index b359864f..3e0abe55 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -252,6 +252,27 @@ namespace RMuseum.Controllers return Ok(res.Result); } + /// + /// get poem songs + /// + /// + /// + /// + /// + [HttpGet] + [Route("poem/{id}/songs")] + [AllowAnonymous] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(PoemMusicTrackViewModel[]))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task GetPoemSongs(int id, bool approved, PoemMusicTrackType trackType = PoemMusicTrackType.All) + { + RServiceResult res = + await _ganjoorService.GetPoemSongs(id, approved, trackType); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(res.Result); + } + /// /// suggest song for poem /// diff --git a/RMuseum/Models/Ganjoor/PoemMusicTrackType.cs b/RMuseum/Models/Ganjoor/PoemMusicTrackType.cs index c5c746ab..8b024237 100644 --- a/RMuseum/Models/Ganjoor/PoemMusicTrackType.cs +++ b/RMuseum/Models/Ganjoor/PoemMusicTrackType.cs @@ -5,6 +5,10 @@ /// public enum PoemMusicTrackType { + /// + /// all + /// + All = -1, /// /// https://beeptunes.com/or http://khosousi.com /// diff --git a/RMuseum/Models/Ganjoor/ViewModels/PoemMusicTrackViewModel.cs b/RMuseum/Models/Ganjoor/ViewModels/PoemMusicTrackViewModel.cs index 83e9c812..da8baf4b 100644 --- a/RMuseum/Models/Ganjoor/ViewModels/PoemMusicTrackViewModel.cs +++ b/RMuseum/Models/Ganjoor/ViewModels/PoemMusicTrackViewModel.cs @@ -60,6 +60,11 @@ /// public bool BrokenLink { get; set; } + /// + /// golha id + /// + public int GolhaTrackId { get; set; } + /// /// to string /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 87275924..4b63c5bd 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -707,6 +707,15 @@ + + + get poem songs + + + + + + suggest song for poem @@ -3819,6 +3828,11 @@ poem music track type + + + all + + https://beeptunes.com/or http://khosousi.com @@ -4232,6 +4246,11 @@ broken link + + + golha id + + to string @@ -5522,6 +5541,15 @@ + + + get poem related songs + + + + + + suggest song @@ -6346,6 +6374,15 @@ + + + get poem related songs + + + + + + suggest song diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index 8c87a922..9c086067 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -106,6 +106,15 @@ namespace RMuseum.Services /// Task> GetPoemImages(int id); + /// + /// get poem related songs + /// + /// + /// + /// + /// + Task> GetPoemSongs(int id, bool approved, PoemMusicTrackType trackType = PoemMusicTrackType.All); + /// /// suggest song /// @@ -114,6 +123,9 @@ namespace RMuseum.Services /// Task> SuggestSong(Guid userId, PoemMusicTrackViewModel song); + + + /// /// get a random poem from hafez /// diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index c4005aa1..32dfc3e7 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -667,26 +667,10 @@ namespace RMuseum.Services.Implementation PoemMusicTrackViewModel[] tracks = null; if(songs) { - tracks = await _context.GanjoorPoemMusicTracks - .Where(t => t.PoemId == id && t.Approved) - .OrderBy(t => t.Id) - .Select - ( - t => new PoemMusicTrackViewModel() - { - Id = t.Id, - TrackType = t.TrackType, - ArtistName = t.ArtistName, - ArtistUrl = t.ArtistUrl, - AlbumName = t.AlbumName, - AlbumUrl = t.AlbumUrl, - TrackName = t.TrackName, - TrackUrl = t.TrackUrl, - Description = t.Description, - BrokenLink = t.BrokenLink - - } - ).ToArrayAsync(); + var songsRes = await GetPoemSongs(id, true, PoemMusicTrackType.All); + if(!string.IsNullOrEmpty(songsRes.ExceptionString)) + return new RServiceResult(null, songsRes.ExceptionString); + tracks = songsRes.Result; } @@ -721,6 +705,57 @@ namespace RMuseum.Services.Implementation } } + + /// + /// get poem related songs + /// + /// + /// + /// + /// + public async Task> GetPoemSongs(int id, bool approved, PoemMusicTrackType trackType) + { + try + { + return new RServiceResult + ( + await _context.GanjoorPoemMusicTracks + .Where + ( + t => t.PoemId == id + && + t.Approved == approved + && + (trackType == PoemMusicTrackType.All || t.TrackType == trackType) + ) + .OrderBy(t => t.Id) + .Select + ( + t => new PoemMusicTrackViewModel() + { + Id = t.Id, + PoemId = t.PoemId, + TrackType = t.TrackType, + ArtistName = t.ArtistName, + ArtistUrl = t.ArtistUrl, + AlbumName = t.AlbumName, + AlbumUrl = t.AlbumUrl, + TrackName = t.TrackName, + TrackUrl = t.TrackUrl, + Description = t.Description, + BrokenLink = t.BrokenLink, + GolhaTrackId = t.GolhaTrackId == null ? 0 : (int)t.GolhaTrackId + + } + ).ToArrayAsync() + ); + } + catch(Exception exp) + { + return new RServiceResult(null, exp.ToString()); + } + } + /// /// suggest song /// @@ -737,8 +772,6 @@ namespace RMuseum.Services.Implementation return new RServiceResult(null, "این آهنگ پیشتر برای این شعر پیشنهاد داده شده است."); } - - var sug = new PoemMusicTrack() { @@ -750,7 +783,8 @@ namespace RMuseum.Services.Implementation AlbumUrl = song.AlbumUrl, TrackName = song.TrackName, TrackUrl = song.TrackUrl, - SuggestedById = userId + SuggestedById = userId, + GolhaTrackId = song.TrackType == PoemMusicTrackType.Golha ? song.GolhaTrackId : (int?)null }; GanjoorSinger singer = await _context.GanjoorSingers.Where(s => s.Url == song.ArtistUrl).FirstOrDefaultAsync();