Skip to content

Commit

Permalink
Simplify ManualImportModule null check
Browse files Browse the repository at this point in the history
  • Loading branch information
Qstick committed Oct 14, 2020
1 parent e8e4d76 commit 6713525
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/Lidarr.Api.V1/ManualImport/ManualImportModule.cs
Expand Up @@ -47,14 +47,11 @@ private List<ManualImportResource> GetMediaFiles()
var downloadId = (string)Request.Query.downloadId;
NzbDrone.Core.Music.Artist artist = null;

var artistIdQuery = Request.Query.artistId;
if (artistIdQuery.HasValue)
var artistIdQuery = Request.GetNullableIntegerQueryParameter("artistId", null);

if (artistIdQuery.HasValue && artistIdQuery.Value > 0)
{
var artistId = Convert.ToInt32(artistIdQuery.Value);
if (artistId > 0)
{
artist = _artistService.GetArtist(Convert.ToInt32(artistIdQuery.Value));
}
artist = _artistService.GetArtist(Convert.ToInt32(artistIdQuery.Value));
}

var filter = Request.GetBooleanQueryParameter("filterExistingFiles", true) ? FilterFilesType.Matched : FilterFilesType.None;
Expand Down
12 changes: 12 additions & 0 deletions src/Lidarr.Http/Extensions/RequestExtensions.cs
Expand Up @@ -78,5 +78,17 @@ public static Guid GetGuidQueryParameter(this Request request, string parameter,

return defaultValue;
}

public static int? GetNullableIntegerQueryParameter(this Request request, string parameter, int? defaultValue = null)
{
var parameterValue = request.Query[parameter];

if (parameterValue.HasValue)
{
return int.Parse(parameterValue.Value);
}

return defaultValue;
}
}
}

0 comments on commit 6713525

Please sign in to comment.