New: MB ID filter when getting artist from API

Fixes #1200

Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
pull/1689/head
Qstick 4 years ago
parent 2a76ae4087
commit 140f3f88c4

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentValidation;
@ -122,8 +123,18 @@ namespace Lidarr.Api.V1.Artist
private List<ArtistResource> AllArtists()
{
var mbId = Request.GetGuidQueryParameter("mbId");
var artistStats = _artistStatisticsService.ArtistStatistics();
var artistsResources = _artistService.GetAllArtists().ToResource();
var artistsResources = new List<ArtistResource>();
if (mbId != Guid.Empty)
{
artistsResources.AddIfNotNull(_artistService.FindById(mbId.ToString()).ToResource());
}
else
{
artistsResources.AddRange(_artistService.GetAllArtists().ToResource());
}
MapCoversToLocal(artistsResources.ToArray());
LinkNextPreviousAlbums(artistsResources.ToArray());

@ -54,5 +54,29 @@ namespace Lidarr.Http.Extensions
return request.Path.StartsWith("/MediaCover/", StringComparison.InvariantCultureIgnoreCase) ||
request.Path.StartsWith("/Content/Images/", StringComparison.InvariantCultureIgnoreCase);
}
public static int GetIntegerQueryParameter(this Request request, string parameter, int defaultValue = 0)
{
var parameterValue = request.Query[parameter];
if (parameterValue.HasValue)
{
return int.Parse(parameterValue.Value);
}
return defaultValue;
}
public static Guid GetGuidQueryParameter(this Request request, string parameter, Guid defaultValue = default)
{
var parameterValue = request.Query[parameter];
if (parameterValue.HasValue)
{
return Guid.Parse(parameterValue.Value);
}
return defaultValue;
}
}
}

Loading…
Cancel
Save