mirror of
https://github.com/sphildreth/roadie
synced 2025-02-16 21:18:26 +00:00
label related work
This commit is contained in:
parent
7e1286363f
commit
6242831067
4 changed files with 36 additions and 4 deletions
|
@ -48,10 +48,11 @@ namespace Roadie.Api.Controllers
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType(200)]
|
[ProducesResponseType(200)]
|
||||||
public async Task<IActionResult> List([FromQuery]PagedRequest request)
|
public async Task<IActionResult> List([FromQuery]PagedRequest request, bool? doRandomize = false)
|
||||||
{
|
{
|
||||||
var result = await this.LabelService.List(roadieUser: await this.CurrentUserModel(),
|
var result = await this.LabelService.List(roadieUser: await this.CurrentUserModel(),
|
||||||
request: request);
|
request: request,
|
||||||
|
doRandomize: doRandomize);
|
||||||
if (!result.IsSuccess)
|
if (!result.IsSuccess)
|
||||||
{
|
{
|
||||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||||
|
|
|
@ -378,6 +378,17 @@ namespace Roadie.Api.Services
|
||||||
select a.Id
|
select a.Id
|
||||||
).ToArray();
|
).ToArray();
|
||||||
}
|
}
|
||||||
|
int[] labelArtistIds = new int[0];
|
||||||
|
if(request.FilterToLabelId.HasValue)
|
||||||
|
{
|
||||||
|
labelArtistIds = (from l in this.DbContext.Labels
|
||||||
|
join rl in this.DbContext.ReleaseLabels on l.Id equals rl.LabelId
|
||||||
|
join r in this.DbContext.Releases on rl.ReleaseId equals r.Id
|
||||||
|
where l.RoadieId == request.FilterToLabelId
|
||||||
|
select r.ArtistId)
|
||||||
|
.Distinct()
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
var onlyWithReleases = onlyIncludeWithReleases ?? true;
|
var onlyWithReleases = onlyIncludeWithReleases ?? true;
|
||||||
var result = (from a in this.DbContext.Artists
|
var result = (from a in this.DbContext.Artists
|
||||||
where (!onlyWithReleases || a.ReleaseCount > 0)
|
where (!onlyWithReleases || a.ReleaseCount > 0)
|
||||||
|
@ -385,6 +396,7 @@ namespace Roadie.Api.Services
|
||||||
where (request.FilterMinimumRating == null || a.Rating >= request.FilterMinimumRating.Value)
|
where (request.FilterMinimumRating == null || a.Rating >= request.FilterMinimumRating.Value)
|
||||||
where (request.FilterValue == "" || (a.Name.Contains(request.FilterValue) || a.SortName.Contains(request.FilterValue) || a.AlternateNames.Contains(request.FilterValue)))
|
where (request.FilterValue == "" || (a.Name.Contains(request.FilterValue) || a.SortName.Contains(request.FilterValue) || a.AlternateNames.Contains(request.FilterValue)))
|
||||||
where (!request.FilterFavoriteOnly || favoriteArtistIds.Contains(a.Id))
|
where (!request.FilterFavoriteOnly || favoriteArtistIds.Contains(a.Id))
|
||||||
|
where (request.FilterToLabelId == null || labelArtistIds.Contains(a.Id))
|
||||||
select new ArtistList
|
select new ArtistList
|
||||||
{
|
{
|
||||||
DatabaseId = a.Id,
|
DatabaseId = a.Id,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using Mapster;
|
using Mapster;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Roadie.Library;
|
using Roadie.Library;
|
||||||
using Roadie.Library.Caching;
|
using Roadie.Library.Caching;
|
||||||
|
@ -156,9 +157,26 @@ namespace Roadie.Api.Services
|
||||||
TrackCount = l.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);
|
LabelList[] rows = null;
|
||||||
var rowCount = result.Count();
|
var rowCount = result.Count();
|
||||||
var rows = result.OrderBy(sortBy).Skip(request.SkipValue).Take(request.LimitValue).ToArray();
|
if (doRandomize ?? false)
|
||||||
|
{
|
||||||
|
|
||||||
|
var randomLimit = roadieUser?.RandomReleaseLimit ?? 100;
|
||||||
|
request.Limit = request.LimitValue > randomLimit ? randomLimit : request.LimitValue;
|
||||||
|
var sql = "SELECT l.Id FROM `label` l ORDER BY RAND() LIMIT {0}";
|
||||||
|
rows = (from rdn in this.DbContext.Labels.FromSql(sql, randomLimit)
|
||||||
|
join rs in result on rdn.Id equals rs.DatabaseId
|
||||||
|
select rs)
|
||||||
|
.Take(request.LimitValue)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var sortBy = string.IsNullOrEmpty(request.Sort) ? request.OrderValue(new Dictionary<string, string> { { "SortName", "ASC" }, { "Label.Text", "ASC" } }) : request.OrderValue(null);
|
||||||
|
rows = result.OrderBy(sortBy).Skip(request.SkipValue).Take(request.LimitValue).ToArray();
|
||||||
|
}
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
return new Library.Models.Pagination.PagedResult<LabelList>
|
return new Library.Models.Pagination.PagedResult<LabelList>
|
||||||
{
|
{
|
||||||
|
|
|
@ -105,6 +105,7 @@ namespace Roadie.Library.Models.Pagination
|
||||||
public Guid? FilterToTrackId { get; set; }
|
public Guid? FilterToTrackId { get; set; }
|
||||||
public Guid? FilterToCollectionId { get; set; }
|
public Guid? FilterToCollectionId { get; set; }
|
||||||
public Guid? FilterToPlaylistId { get; set; }
|
public Guid? FilterToPlaylistId { get; set; }
|
||||||
|
public Guid? FilterToLabelId { get; set; }
|
||||||
|
|
||||||
public int? FilterMinimumRating { get; set; }
|
public int? FilterMinimumRating { get; set; }
|
||||||
public bool FilterRatedOnly { get; set; }
|
public bool FilterRatedOnly { get; set; }
|
||||||
|
|
Loading…
Add table
Reference in a new issue