mirror of
https://github.com/sphildreth/roadie
synced 2024-11-22 20:23:16 +00:00
Label and playlist
This commit is contained in:
parent
f0e6fa53ef
commit
7e1286363f
6 changed files with 153 additions and 55 deletions
|
@ -7,8 +7,10 @@ using Roadie.Api.Services;
|
||||||
using Roadie.Library.Caching;
|
using Roadie.Library.Caching;
|
||||||
using Roadie.Library.Identity;
|
using Roadie.Library.Identity;
|
||||||
using Roadie.Library.Models.Pagination;
|
using Roadie.Library.Models.Pagination;
|
||||||
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using models = Roadie.Library.Models;
|
||||||
|
|
||||||
namespace Roadie.Api.Controllers
|
namespace Roadie.Api.Controllers
|
||||||
{
|
{
|
||||||
|
@ -27,33 +29,22 @@ namespace Roadie.Api.Controllers
|
||||||
this.LabelService = labelService;
|
this.LabelService = labelService;
|
||||||
}
|
}
|
||||||
|
|
||||||
//[EnableQuery]
|
[HttpGet("{id}")]
|
||||||
//public IActionResult Get()
|
[ProducesResponseType(200)]
|
||||||
//{
|
[ProducesResponseType(404)]
|
||||||
// return Ok(this._RoadieDbContext.Labels.ProjectToType<models.Label>());
|
public async Task<IActionResult> Get(Guid id, string inc = null)
|
||||||
//}
|
{
|
||||||
|
var result = await this.LabelService.ById(await this.CurrentUserModel(), id, (inc ?? models.Label.DefaultIncludes).ToLower().Split(","));
|
||||||
//[HttpGet("{id}")]
|
if (result == null || result.IsNotFoundResult)
|
||||||
//[ProducesResponseType(200)]
|
{
|
||||||
//[ProducesResponseType(404)]
|
return NotFound();
|
||||||
//public IActionResult Get(Guid id)
|
}
|
||||||
//{
|
if (!result.IsSuccess)
|
||||||
// var key = id.ToString();
|
{
|
||||||
// var result = this._cacheManager.Get<models.Label>(key, () =>
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||||
// {
|
}
|
||||||
// var d = this._RoadieDbContext.Labels.FirstOrDefault(x => x.RoadieId == id);
|
return Ok(result);
|
||||||
// if (d != null)
|
}
|
||||||
// {
|
|
||||||
// return d.Adapt<models.Label>();
|
|
||||||
// }
|
|
||||||
// return null;
|
|
||||||
// }, key);
|
|
||||||
// if (result == null)
|
|
||||||
// {
|
|
||||||
// return NotFound();
|
|
||||||
// }
|
|
||||||
// return Ok(result);
|
|
||||||
//}
|
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType(200)]
|
[ProducesResponseType(200)]
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
using Roadie.Library.Models;
|
using Roadie.Library;
|
||||||
|
using Roadie.Library.Models;
|
||||||
using Roadie.Library.Models.Pagination;
|
using Roadie.Library.Models.Pagination;
|
||||||
using Roadie.Library.Models.Users;
|
using Roadie.Library.Models.Users;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Roadie.Api.Services
|
namespace Roadie.Api.Services
|
||||||
{
|
{
|
||||||
public interface ILabelService
|
public interface ILabelService
|
||||||
{
|
{
|
||||||
|
Task<OperationResult<Label>> ById(User roadieUser, Guid id, IEnumerable<string> includes = null);
|
||||||
Task<PagedResult<LabelList>> List(User roadieUser, PagedRequest request, bool? doRandomize = false);
|
Task<PagedResult<LabelList>> List(User roadieUser, PagedRequest request, bool? doRandomize = false);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,11 @@
|
||||||
using Microsoft.Extensions.Logging;
|
using Mapster;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Roadie.Library;
|
||||||
using Roadie.Library.Caching;
|
using Roadie.Library.Caching;
|
||||||
using Roadie.Library.Configuration;
|
using Roadie.Library.Configuration;
|
||||||
using Roadie.Library.Encoding;
|
using Roadie.Library.Encoding;
|
||||||
|
using Roadie.Library.Enums;
|
||||||
|
using Roadie.Library.Extensions;
|
||||||
using Roadie.Library.Models;
|
using Roadie.Library.Models;
|
||||||
using Roadie.Library.Models.Pagination;
|
using Roadie.Library.Models.Pagination;
|
||||||
using Roadie.Library.Models.Users;
|
using Roadie.Library.Models.Users;
|
||||||
|
@ -18,6 +22,8 @@ namespace Roadie.Api.Services
|
||||||
{
|
{
|
||||||
public class LabelService : ServiceBase, ILabelService
|
public class LabelService : ServiceBase, ILabelService
|
||||||
{
|
{
|
||||||
|
private IBookmarkService BookmarkService { get; } = null;
|
||||||
|
|
||||||
public LabelService(IRoadieSettings configuration,
|
public LabelService(IRoadieSettings configuration,
|
||||||
IHttpEncoder httpEncoder,
|
IHttpEncoder httpEncoder,
|
||||||
IHttpContext httpContext,
|
IHttpContext httpContext,
|
||||||
|
@ -25,11 +31,99 @@ namespace Roadie.Api.Services
|
||||||
ICacheManager cacheManager,
|
ICacheManager cacheManager,
|
||||||
ILogger<LabelService> logger,
|
ILogger<LabelService> logger,
|
||||||
ICollectionService collectionService,
|
ICollectionService collectionService,
|
||||||
IPlaylistService playlistService)
|
IPlaylistService playlistService,
|
||||||
|
IBookmarkService bookmarkService)
|
||||||
: base(configuration, httpEncoder, context, cacheManager, logger, httpContext)
|
: base(configuration, httpEncoder, context, cacheManager, logger, httpContext)
|
||||||
{
|
{
|
||||||
|
this.BookmarkService = bookmarkService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<OperationResult<Label>> ById(User roadieUser, Guid id, IEnumerable<string> includes = null)
|
||||||
|
{
|
||||||
|
var sw = Stopwatch.StartNew();
|
||||||
|
sw.Start();
|
||||||
|
var cacheKey = string.Format("urn:label_by_id_operation:{0}:{1}", id, includes == null ? "0" : string.Join("|", includes));
|
||||||
|
var result = await this.CacheManager.GetAsync<OperationResult<Label>>(cacheKey, async () =>
|
||||||
|
{
|
||||||
|
return await this.LabelByIdAction(id, includes);
|
||||||
|
}, data.Artist.CacheRegionUrn(id));
|
||||||
|
sw.Stop();
|
||||||
|
if (result?.Data != null && roadieUser != null)
|
||||||
|
{
|
||||||
|
var userBookmarkResult = await this.BookmarkService.List(roadieUser, new PagedRequest(), false, BookmarkType.Label);
|
||||||
|
if (userBookmarkResult.IsSuccess)
|
||||||
|
{
|
||||||
|
result.Data.UserBookmarked = userBookmarkResult?.Rows?.FirstOrDefault(x => x.Bookmark.Text == result.Data.Id.ToString()) != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new OperationResult<Label>(result.Messages)
|
||||||
|
{
|
||||||
|
Data = result?.Data,
|
||||||
|
IsNotFoundResult = result?.IsNotFoundResult ?? false,
|
||||||
|
Errors = result?.Errors,
|
||||||
|
IsSuccess = result?.IsSuccess ?? false,
|
||||||
|
OperationTime = sw.ElapsedMilliseconds
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<OperationResult<Label>> LabelByIdAction(Guid id, IEnumerable<string> includes = null)
|
||||||
|
{
|
||||||
|
var sw = Stopwatch.StartNew();
|
||||||
|
sw.Start();
|
||||||
|
|
||||||
|
var label = this.GetLabel(id);
|
||||||
|
|
||||||
|
if (label == null)
|
||||||
|
{
|
||||||
|
return new OperationResult<Label>(true, string.Format("Label Not Found [{0}]", id));
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = label.Adapt<Label>();
|
||||||
|
result.AlternateNames = label.AlternateNames;
|
||||||
|
result.Tags = label.Tags;
|
||||||
|
result.URLs = label.URLs;
|
||||||
|
result.Thumbnail = this.MakeLabelThumbnailImage(label.RoadieId);
|
||||||
|
result.MediumThumbnail = base.MakeThumbnailImage(id, "label", this.Configuration.MediumImageSize.Width, this.Configuration.MediumImageSize.Height);
|
||||||
|
if (includes != null && includes.Any())
|
||||||
|
{
|
||||||
|
if (includes.Contains("stats"))
|
||||||
|
{
|
||||||
|
var labelTracks = (from l in this.DbContext.Labels
|
||||||
|
join rl in this.DbContext.ReleaseLabels on l.Id equals rl.LabelId into rld
|
||||||
|
from rl in rld.DefaultIfEmpty()
|
||||||
|
join r in this.DbContext.Releases on rl.ReleaseId equals r.Id
|
||||||
|
join rm in this.DbContext.ReleaseMedias on r.Id equals rm.ReleaseId
|
||||||
|
join t in this.DbContext.Tracks on rm.Id equals t.ReleaseMediaId
|
||||||
|
where (l.Id == label.Id)
|
||||||
|
select new
|
||||||
|
{
|
||||||
|
t.Duration,
|
||||||
|
t.FileSize
|
||||||
|
});
|
||||||
|
result.Duration = labelTracks.Sum(x => x.Duration);
|
||||||
|
|
||||||
|
result.Statistics = new Library.Models.Statistics.ReleaseGroupingStatistics
|
||||||
|
{
|
||||||
|
TrackCount = label.TrackCount,
|
||||||
|
ArtistCount = label.ArtistCount,
|
||||||
|
ReleaseCount = label.ReleaseCount,
|
||||||
|
TrackSize = result.DurationTime,
|
||||||
|
FileSize = labelTracks.Sum(x => (long?)x.FileSize).ToFileSize()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sw.Stop();
|
||||||
|
return new OperationResult<Label>
|
||||||
|
{
|
||||||
|
Data = result,
|
||||||
|
IsSuccess = result != null,
|
||||||
|
OperationTime = sw.ElapsedMilliseconds
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<Library.Models.Pagination.PagedResult<LabelList>> List(User roadieUser, PagedRequest request, bool? doRandomize = false)
|
public async Task<Library.Models.Pagination.PagedResult<LabelList>> List(User roadieUser, PagedRequest request, bool? doRandomize = false)
|
||||||
{
|
{
|
||||||
var sw = new Stopwatch();
|
var sw = new Stopwatch();
|
||||||
|
@ -41,27 +135,6 @@ namespace Roadie.Api.Services
|
||||||
request.Sort = request.Sort.Replace("lastUpdated", "lastUpdatedDateTime");
|
request.Sort = request.Sort.Replace("lastUpdated", "lastUpdatedDateTime");
|
||||||
}
|
}
|
||||||
var result = (from l in this.DbContext.Labels
|
var result = (from l in this.DbContext.Labels
|
||||||
let artistCount = (from lb in this.DbContext.Labels
|
|
||||||
join rll in this.DbContext.ReleaseLabels on lb.Id equals rll.LabelId into rldd
|
|
||||||
from rll in rldd.DefaultIfEmpty()
|
|
||||||
join rr in this.DbContext.Releases on rll.ReleaseId equals rr.Id
|
|
||||||
join aa in this.DbContext.Artists on rr.ArtistId equals aa.Id
|
|
||||||
where lb.Id == l.Id
|
|
||||||
select aa.Id).Count()
|
|
||||||
let releaseCount = (from lbb in this.DbContext.Labels
|
|
||||||
join rlll in this.DbContext.ReleaseLabels on lbb.Id equals rlll.LabelId into rlddd
|
|
||||||
from rlll in rlddd.DefaultIfEmpty()
|
|
||||||
join rrr in this.DbContext.Releases on rlll.ReleaseId equals rrr.Id
|
|
||||||
where lbb.Id == l.Id
|
|
||||||
select rrr.Id).Count()
|
|
||||||
let trackCount = (from lbtc in this.DbContext.Labels
|
|
||||||
join rlltc in this.DbContext.ReleaseLabels on lbtc.Id equals rlltc.LabelId into rlddtc
|
|
||||||
from rlltc in rlddtc.DefaultIfEmpty()
|
|
||||||
join rrtc in this.DbContext.Releases on rlltc.ReleaseId equals rrtc.Id
|
|
||||||
join rmtc in this.DbContext.ReleaseMedias on rrtc.Id equals rmtc.ReleaseId
|
|
||||||
join tttc in this.DbContext.Tracks on rmtc.Id equals tttc.ReleaseMediaId
|
|
||||||
where lbtc.Id == l.Id
|
|
||||||
select tttc.Id).Count()
|
|
||||||
where (request.FilterValue.Length == 0 || (request.FilterValue.Length > 0 && (
|
where (request.FilterValue.Length == 0 || (request.FilterValue.Length > 0 && (
|
||||||
l.Name != null && l.Name.Contains(request.FilterValue) ||
|
l.Name != null && l.Name.Contains(request.FilterValue) ||
|
||||||
l.AlternateNames != null && l.AlternateNames.Contains(request.FilterValue)
|
l.AlternateNames != null && l.AlternateNames.Contains(request.FilterValue)
|
||||||
|
@ -78,9 +151,9 @@ namespace Roadie.Api.Services
|
||||||
SortName = l.SortName,
|
SortName = l.SortName,
|
||||||
CreatedDate = l.CreatedDate,
|
CreatedDate = l.CreatedDate,
|
||||||
LastUpdated = l.LastUpdated,
|
LastUpdated = l.LastUpdated,
|
||||||
ArtistCount = artistCount,
|
ArtistCount = l.ArtistCount,
|
||||||
ReleaseCount = releaseCount,
|
ReleaseCount = l.ReleaseCount,
|
||||||
TrackCount = trackCount,
|
TrackCount = l.TrackCount,
|
||||||
Thumbnail = this.MakeLabelThumbnailImage(l.RoadieId)
|
Thumbnail = this.MakeLabelThumbnailImage(l.RoadieId)
|
||||||
});
|
});
|
||||||
var sortBy = string.IsNullOrEmpty(request.Sort) ? request.OrderValue(new Dictionary<string, string> { { "SortName", "ASC" }, { "Label.Text", "ASC" } }) : request.OrderValue(null);
|
var sortBy = string.IsNullOrEmpty(request.Sort) ? request.OrderValue(new Dictionary<string, string> { { "SortName", "ASC" }, { "Label.Text", "ASC" } }) : request.OrderValue(null);
|
||||||
|
|
|
@ -259,6 +259,8 @@ namespace Roadie.Api.Services
|
||||||
playlistTrackIds = playListTrackPositions.Select(x => x.Key).ToArray();
|
playlistTrackIds = playListTrackPositions.Select(x => x.Key).ToArray();
|
||||||
request.Sort = "TrackNumber";
|
request.Sort = "TrackNumber";
|
||||||
request.Order = "ASC";
|
request.Order = "ASC";
|
||||||
|
request.Page = 1; // Set back to first or it skips already paged tracks for playlist
|
||||||
|
request.SkipValue = 0;
|
||||||
}
|
}
|
||||||
int[] topTrackids = new int[0];
|
int[] topTrackids = new int[0];
|
||||||
if (request.FilterTopPlayedOnly)
|
if (request.FilterTopPlayedOnly)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using Roadie.Library.Models.Statistics;
|
||||||
|
using System;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace Roadie.Library.Models
|
namespace Roadie.Library.Models
|
||||||
|
@ -6,6 +7,8 @@ namespace Roadie.Library.Models
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class Label : EntityModelBase
|
public class Label : EntityModelBase
|
||||||
{
|
{
|
||||||
|
public const string DefaultIncludes = "stats";
|
||||||
|
|
||||||
[MaxLength(65535)]
|
[MaxLength(65535)]
|
||||||
public string BioContext { get; set; }
|
public string BioContext { get; set; }
|
||||||
|
|
||||||
|
@ -24,5 +27,23 @@ namespace Roadie.Library.Models
|
||||||
public string Profile { get; set; }
|
public string Profile { get; set; }
|
||||||
|
|
||||||
public Image Thumbnail { get; set; }
|
public Image Thumbnail { get; set; }
|
||||||
|
|
||||||
|
public Image MediumThumbnail { get; set; }
|
||||||
|
|
||||||
|
public ReleaseGroupingStatistics Statistics { get; set; }
|
||||||
|
|
||||||
|
public int? Duration { get; set; }
|
||||||
|
public string DurationTime
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!this.Duration.HasValue)
|
||||||
|
{
|
||||||
|
return "--:--";
|
||||||
|
}
|
||||||
|
return TimeSpan.FromSeconds(this.Duration.Value / 1000).ToString(@"dd\.hh\:mm\:ss");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,12 +8,19 @@ namespace Roadie.Library.Models.Statistics
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class ReleaseGroupingStatistics
|
public class ReleaseGroupingStatistics
|
||||||
{
|
{
|
||||||
|
public int? ArtistCount { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Formatted sum of track file sizes
|
||||||
|
/// </summary>
|
||||||
public string FileSize { get; set; }
|
public string FileSize { get; set; }
|
||||||
public int? MissingTrackCount { get; set; }
|
public int? MissingTrackCount { get; set; }
|
||||||
public int? ReleaseCount { get; set; }
|
public int? ReleaseCount { get; set; }
|
||||||
public int? ReleaseMediaCount { get; set; }
|
public int? ReleaseMediaCount { get; set; }
|
||||||
public int? TrackCount { get; set; }
|
public int? TrackCount { get; set; }
|
||||||
public int? TrackPlayedCount { get; set; }
|
public int? TrackPlayedCount { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Sum of duration of tracks
|
||||||
|
/// </summary>
|
||||||
public string TrackSize { get; set; }
|
public string TrackSize { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue