diff --git a/NzbDrone.Api/REST/RestModule.cs b/NzbDrone.Api/REST/RestModule.cs index b494206a0..54562bfea 100644 --- a/NzbDrone.Api/REST/RestModule.cs +++ b/NzbDrone.Api/REST/RestModule.cs @@ -71,6 +71,12 @@ namespace NzbDrone.Api.REST try { var resource = GetResourceById((int)options.Id); + + if (resource == null) + { + return new NotFoundResponse(); + } + return resource.AsResponse(); } catch (ModelNotFoundException) diff --git a/NzbDrone.Api/Series/SeriesModule.cs b/NzbDrone.Api/Series/SeriesModule.cs index b6e33922f..b9d7c3fd2 100644 --- a/NzbDrone.Api/Series/SeriesModule.cs +++ b/NzbDrone.Api/Series/SeriesModule.cs @@ -3,11 +3,13 @@ using System.Collections.Generic; using System.Linq; using FluentValidation; using Nancy; +using NzbDrone.Core.Datastore; using NzbDrone.Core.MediaCover; using NzbDrone.Core.SeriesStats; using NzbDrone.Core.Tv; using NzbDrone.Api.Validation; using NzbDrone.Api.Extensions; +using NzbDrone.Api.Mapping; namespace NzbDrone.Api.Series { @@ -30,7 +32,7 @@ namespace NzbDrone.Api.Series UpdateResource = UpdateSeries; DeleteResource = DeleteSeries; - Get["/{slug}"] = o => GetSeries((string)o.slug.ToString()); + Get["/{slug}"] = o => GetSeriesBySlug((string)o.slug.ToString()); SharedValidator.RuleFor(s => s.QualityProfileId).ValidId(); SharedValidator.RuleFor(s => s.Path).NotEmpty().When(s => String.IsNullOrEmpty(s.RootFolderPath)); @@ -39,7 +41,23 @@ namespace NzbDrone.Api.Series PostValidator.RuleFor(s => s.Title).NotEmpty(); } - private Response GetSeries(string slug) + private SeriesResource GetSeries(int id) + { + Core.Tv.Series series = null; + + try + { + series = _seriesService.GetSeries(id); + } + catch (ModelNotFoundException) + { + series = _seriesService.FindBySlug(id.ToString()); + } + + return GetSeriesResource(series); + } + + private Response GetSeriesBySlug(string slug) { var series = _seriesService.FindBySlug(slug); @@ -48,12 +66,16 @@ namespace NzbDrone.Api.Series return new NotFoundResponse(); } + return GetSeriesResource(series).AsResponse(); + } - var resource = ToResource(()=>_seriesService.FindBySlug(slug)); + private SeriesResource GetSeriesResource(Core.Tv.Series series) + { + if (series == null) return null; + var resource = series.InjectTo(); MapCoversToLocal(resource); - - return resource.AsResponse(); + return resource; } private List AllSeries() @@ -77,14 +99,7 @@ namespace NzbDrone.Api.Series return seriesResources; } - private SeriesResource GetSeries(int id) - { - var resource = ToResource(_seriesService.GetSeries, id); - - MapCoversToLocal(resource); - return resource; - } private SeriesResource AddSeries(SeriesResource seriesResource) { diff --git a/NzbDrone.Integration.Test/IntegrationTest.cs b/NzbDrone.Integration.Test/IntegrationTest.cs index afd59603d..56555c747 100644 --- a/NzbDrone.Integration.Test/IntegrationTest.cs +++ b/NzbDrone.Integration.Test/IntegrationTest.cs @@ -41,14 +41,12 @@ namespace NzbDrone.Integration.Test static IntegrationTest() { - if (LogManager.Configuration == null || LogManager.Configuration is XmlLoggingConfiguration) - { - LogManager.Configuration = new LoggingConfiguration(); - var consoleTarget = new ConsoleTarget { Layout = "${time} - ${logger} - ${message} ${exception}" }; - LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget); - LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget)); - } + LogManager.Configuration.Reload(); + LogManager.Configuration = new LoggingConfiguration(); + var consoleTarget = new ConsoleTarget { Layout = "${time} - ${logger} - ${message} ${exception}" }; + LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget); + LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget)); LogManager.ReconfigExistingLoggers(); } diff --git a/NzbDrone.Integration.Test/SeriesIntegrationTest.cs b/NzbDrone.Integration.Test/SeriesIntegrationTest.cs index 33c7b40d2..6431e8679 100644 --- a/NzbDrone.Integration.Test/SeriesIntegrationTest.cs +++ b/NzbDrone.Integration.Test/SeriesIntegrationTest.cs @@ -51,6 +51,23 @@ namespace NzbDrone.Integration.Test Series.All().Should().BeEmpty(); } + + [Test] + public void should_be_able_to_add_and_get_number_only_series_title() + { + var series = Series.Lookup("90210").First(c=>c.TitleSlug == "90210"); + + series.QualityProfileId = 1; + series.Path = @"C:\Test\90210"; + + series = Series.Post(series); + + Series.All().Should().HaveCount(1); + + Series.Get(series.Id).Should().NotBeNull(); + Series.Get(series.TitleSlug).Should().NotBeNull(); + } + [Test] public void wrong_slug_should_return_404() {