#66 api for poem unapproved suggested related songs

This commit is contained in:
Hamid Reza Mohammadi 2021-01-17 21:31:34 +03:30
parent 2e8dd59d5d
commit ac063905c5
6 changed files with 136 additions and 23 deletions

View File

@ -252,6 +252,27 @@ namespace RMuseum.Controllers
return Ok(res.Result);
}
/// <summary>
/// get poem songs
/// </summary>
/// <param name="id"></param>
/// <param name="approved"></param>
/// <param name="trackType"></param>
/// <returns></returns>
[HttpGet]
[Route("poem/{id}/songs")]
[AllowAnonymous]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(PoemMusicTrackViewModel[]))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task<IActionResult> GetPoemSongs(int id, bool approved, PoemMusicTrackType trackType = PoemMusicTrackType.All)
{
RServiceResult<PoemMusicTrackViewModel[]> res =
await _ganjoorService.GetPoemSongs(id, approved, trackType);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
return Ok(res.Result);
}
/// <summary>
/// suggest song for poem
/// </summary>

View File

@ -5,6 +5,10 @@
/// </summary>
public enum PoemMusicTrackType
{
/// <summary>
/// all
/// </summary>
All = -1,
/// <summary>
/// https://beeptunes.com/or http://khosousi.com
/// </summary>

View File

@ -60,6 +60,11 @@
/// </summary>
public bool BrokenLink { get; set; }
/// <summary>
/// golha id
/// </summary>
public int GolhaTrackId { get; set; }
/// <summary>
/// to string
/// </summary>

View File

@ -707,6 +707,15 @@
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.GetPoemSongs(System.Int32,System.Boolean,RMuseum.Models.Ganjoor.PoemMusicTrackType)">
<summary>
get poem songs
</summary>
<param name="id"></param>
<param name="approved"></param>
<param name="trackType"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.SuggestSong(RMuseum.Models.Ganjoor.ViewModels.PoemMusicTrackViewModel)">
<summary>
suggest song for poem
@ -3819,6 +3828,11 @@
poem music track type
</summary>
</member>
<member name="F:RMuseum.Models.Ganjoor.PoemMusicTrackType.All">
<summary>
all
</summary>
</member>
<member name="F:RMuseum.Models.Ganjoor.PoemMusicTrackType.BeepTunesOrKhosousi">
<summary>
https://beeptunes.com/or http://khosousi.com
@ -4232,6 +4246,11 @@
broken link
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.ViewModels.PoemMusicTrackViewModel.GolhaTrackId">
<summary>
golha id
</summary>
</member>
<member name="M:RMuseum.Models.Ganjoor.ViewModels.PoemMusicTrackViewModel.ToString">
<summary>
to string
@ -5522,6 +5541,15 @@
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.GetPoemSongs(System.Int32,System.Boolean,RMuseum.Models.Ganjoor.PoemMusicTrackType)">
<summary>
get poem related songs
</summary>
<param name="id"></param>
<param name="approved"></param>
<param name="trackType"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.SuggestSong(System.Guid,RMuseum.Models.Ganjoor.ViewModels.PoemMusicTrackViewModel)">
<summary>
suggest song
@ -6346,6 +6374,15 @@
<param name="navigation"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetPoemSongs(System.Int32,System.Boolean,RMuseum.Models.Ganjoor.PoemMusicTrackType)">
<summary>
get poem related songs
</summary>
<param name="id"></param>
<param name="approved"></param>
<param name="trackType"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.SuggestSong(System.Guid,RMuseum.Models.Ganjoor.ViewModels.PoemMusicTrackViewModel)">
<summary>
suggest song

View File

@ -106,6 +106,15 @@ namespace RMuseum.Services
/// <returns></returns>
Task<RServiceResult<PoemRelatedImage[]>> GetPoemImages(int id);
/// <summary>
/// get poem related songs
/// </summary>
/// <param name="id"></param>
/// <param name="approved"></param>
/// <param name="trackType"></param>
/// <returns></returns>
Task<RServiceResult<PoemMusicTrackViewModel[]>> GetPoemSongs(int id, bool approved, PoemMusicTrackType trackType = PoemMusicTrackType.All);
/// <summary>
/// suggest song
/// </summary>
@ -114,6 +123,9 @@ namespace RMuseum.Services
/// <returns></returns>
Task<RServiceResult<PoemMusicTrackViewModel>> SuggestSong(Guid userId, PoemMusicTrackViewModel song);
/// <summary>
/// get a random poem from hafez
/// </summary>

View File

@ -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<GanjoorPoemCompleteViewModel>(null, songsRes.ExceptionString);
tracks = songsRes.Result;
}
@ -721,6 +705,57 @@ namespace RMuseum.Services.Implementation
}
}
/// <summary>
/// get poem related songs
/// </summary>
/// <param name="id"></param>
/// <param name="approved"></param>
/// <param name="trackType"></param>
/// <returns></returns>
public async Task<RServiceResult<PoemMusicTrackViewModel[]>> GetPoemSongs(int id, bool approved, PoemMusicTrackType trackType)
{
try
{
return new RServiceResult<PoemMusicTrackViewModel[]>
(
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<PoemMusicTrackViewModel[]>(null, exp.ToString());
}
}
/// <summary>
/// suggest song
/// </summary>
@ -737,8 +772,6 @@ namespace RMuseum.Services.Implementation
return new RServiceResult<PoemMusicTrackViewModel>(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();