Fixed getting series with number only titles. eg. 90210

This commit is contained in:
Keivan Beigi 2013-07-12 12:13:16 -07:00
parent 87731d56bf
commit e88768d621
4 changed files with 55 additions and 19 deletions

View File

@ -71,6 +71,12 @@ namespace NzbDrone.Api.REST
try try
{ {
var resource = GetResourceById((int)options.Id); var resource = GetResourceById((int)options.Id);
if (resource == null)
{
return new NotFoundResponse();
}
return resource.AsResponse(); return resource.AsResponse();
} }
catch (ModelNotFoundException) catch (ModelNotFoundException)

View File

@ -3,11 +3,13 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using FluentValidation; using FluentValidation;
using Nancy; using Nancy;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.MediaCover; using NzbDrone.Core.MediaCover;
using NzbDrone.Core.SeriesStats; using NzbDrone.Core.SeriesStats;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using NzbDrone.Api.Validation; using NzbDrone.Api.Validation;
using NzbDrone.Api.Extensions; using NzbDrone.Api.Extensions;
using NzbDrone.Api.Mapping;
namespace NzbDrone.Api.Series namespace NzbDrone.Api.Series
{ {
@ -30,7 +32,7 @@ namespace NzbDrone.Api.Series
UpdateResource = UpdateSeries; UpdateResource = UpdateSeries;
DeleteResource = DeleteSeries; 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.QualityProfileId).ValidId();
SharedValidator.RuleFor(s => s.Path).NotEmpty().When(s => String.IsNullOrEmpty(s.RootFolderPath)); 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(); 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); var series = _seriesService.FindBySlug(slug);
@ -48,12 +66,16 @@ namespace NzbDrone.Api.Series
return new NotFoundResponse(); 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<SeriesResource>();
MapCoversToLocal(resource); MapCoversToLocal(resource);
return resource;
return resource.AsResponse();
} }
private List<SeriesResource> AllSeries() private List<SeriesResource> AllSeries()
@ -77,14 +99,7 @@ namespace NzbDrone.Api.Series
return seriesResources; return seriesResources;
} }
private SeriesResource GetSeries(int id)
{
var resource = ToResource(_seriesService.GetSeries, id);
MapCoversToLocal(resource);
return resource;
}
private SeriesResource AddSeries(SeriesResource seriesResource) private SeriesResource AddSeries(SeriesResource seriesResource)
{ {

View File

@ -41,14 +41,12 @@ namespace NzbDrone.Integration.Test
static IntegrationTest() static IntegrationTest()
{ {
if (LogManager.Configuration == null || LogManager.Configuration is XmlLoggingConfiguration) LogManager.Configuration.Reload();
{
LogManager.Configuration = new LoggingConfiguration(); LogManager.Configuration = new LoggingConfiguration();
var consoleTarget = new ConsoleTarget { Layout = "${time} - ${logger} - ${message} ${exception}" }; var consoleTarget = new ConsoleTarget { Layout = "${time} - ${logger} - ${message} ${exception}" };
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget); LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget)); LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget));
}
LogManager.ReconfigExistingLoggers(); LogManager.ReconfigExistingLoggers();
} }

View File

@ -51,6 +51,23 @@ namespace NzbDrone.Integration.Test
Series.All().Should().BeEmpty(); 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] [Test]
public void wrong_slug_should_return_404() public void wrong_slug_should_return_404()
{ {