Fixed getting series with number only titles. eg. 90210

pull/24/head
Keivan Beigi 12 years ago
parent 87731d56bf
commit e88768d621

@ -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)

@ -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<SeriesResource>();
MapCoversToLocal(resource);
return resource.AsResponse();
return resource;
}
private List<SeriesResource> 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)
{

@ -41,14 +41,12 @@ namespace NzbDrone.Integration.Test
static IntegrationTest()
{
if (LogManager.Configuration == null || LogManager.Configuration is XmlLoggingConfiguration)
{
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();
}

@ -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()
{

Loading…
Cancel
Save