1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-09 20:42:37 +01:00

Episode resource now uses series resource as the subtype

Fixed: Episodes on the calendar have series images attached properly again
This commit is contained in:
Mark McDowall 2014-09-10 18:11:35 -07:00
parent b2526a136c
commit 2ff1208947
5 changed files with 20 additions and 11 deletions

View File

@ -1,7 +1,10 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using NzbDrone.Api.EpisodeFiles; using System.Linq;
using NzbDrone.Api.Extensions;
using NzbDrone.Api.Mapping; using NzbDrone.Api.Mapping;
using NzbDrone.Api.Series;
using NzbDrone.Core.Datastore.Events; using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Download; using NzbDrone.Core.Download;
@ -72,6 +75,13 @@ protected override EpisodeResource ToResource<TModel>(TModel model)
return resource; return resource;
} }
protected override List<EpisodeResource> ToListResource<TModel>(IEnumerable<TModel> modelList)
{
var resources = base.ToListResource(modelList);
return resources.LoadSubtype<EpisodeResource, SeriesResource, Core.Tv.Series>(e => e.SeriesId, _seriesService.GetSeries).ToList();
}
public void Handle(EpisodeGrabbedEvent message) public void Handle(EpisodeGrabbedEvent message)
{ {
foreach (var episode in message.Episode.Episodes) foreach (var episode in message.Episode.Episodes)

View File

@ -2,6 +2,7 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using NzbDrone.Api.EpisodeFiles; using NzbDrone.Api.EpisodeFiles;
using NzbDrone.Api.REST; using NzbDrone.Api.REST;
using NzbDrone.Api.Series;
namespace NzbDrone.Api.Episodes namespace NzbDrone.Api.Episodes
{ {
@ -27,9 +28,7 @@ public class EpisodeResource : RestResource
public DateTime? EndTime { get; set; } public DateTime? EndTime { get; set; }
public DateTime? GrabDate { get; set; } public DateTime? GrabDate { get; set; }
public String SeriesTitle { get; set; } public String SeriesTitle { get; set; }
public SeriesResource Series { get; set; }
//I'd like to replace this with SeriesResource, but LoadSubType would need to be reworked to support that
public Core.Tv.Series Series { get; set; }
//Hiding this so people don't think its usable (only used to set the initial state) //Hiding this so people don't think its usable (only used to set the initial state)
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using NzbDrone.Api.Mapping;
using NzbDrone.Api.REST; using NzbDrone.Api.REST;
using NzbDrone.Common.Cache; using NzbDrone.Common.Cache;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
@ -12,8 +13,9 @@ public static class LazyExtensions
{ {
private static readonly ICached<MethodInfo> SetterCache = new Cached<MethodInfo>(); private static readonly ICached<MethodInfo> SetterCache = new Cached<MethodInfo>();
public static IEnumerable<TParent> LoadSubtype<TParent, TChild>(this IEnumerable<TParent> parents, Func<TParent, int> foreignKeySelector, IBasicRepository<TChild> childRepository) public static IEnumerable<TParent> LoadSubtype<TParent, TChild, TSourceChild>(this IEnumerable<TParent> parents, Func<TParent, Int32> foreignKeySelector, Func<IEnumerable<Int32>, IEnumerable<TSourceChild>> sourceChildSelector)
where TChild : ModelBase, new() where TSourceChild : ModelBase, new()
where TChild : RestResource, new()
where TParent : RestResource where TParent : RestResource
{ {
var parentList = parents.Where(p => foreignKeySelector(p) != 0).ToList(); var parentList = parents.Where(p => foreignKeySelector(p) != 0).ToList();
@ -24,13 +26,13 @@ public static IEnumerable<TParent> LoadSubtype<TParent, TChild>(this IEnumerable
} }
var ids = parentList.Select(foreignKeySelector).Distinct(); var ids = parentList.Select(foreignKeySelector).Distinct();
var childDictionary = childRepository.Get(ids).ToDictionary(child => child.Id, child => child); var childDictionary = sourceChildSelector(ids).ToDictionary(child => child.Id, child => child);
var childSetter = GetChildSetter<TParent, TChild>(); var childSetter = GetChildSetter<TParent, TChild>();
foreach (var episode in parentList) foreach (var episode in parentList)
{ {
childSetter.Invoke(episode, new object[] { childDictionary[foreignKeySelector(episode)] }); childSetter.Invoke(episode, new object[] { childDictionary[foreignKeySelector(episode)].InjectTo<TChild>() });
} }
return parents; return parents;
@ -38,7 +40,7 @@ public static IEnumerable<TParent> LoadSubtype<TParent, TChild>(this IEnumerable
private static MethodInfo GetChildSetter<TParent, TChild>() private static MethodInfo GetChildSetter<TParent, TChild>()
where TChild : ModelBase where TChild : RestResource
where TParent : RestResource where TParent : RestResource
{ {
var key = typeof(TChild).FullName + typeof(TParent).FullName; var key = typeof(TChild).FullName + typeof(TParent).FullName;

View File

@ -7,7 +7,6 @@
using NzbDrone.Core.MediaCover; using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.SeriesStats; using NzbDrone.Core.SeriesStats;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;

View File

@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Newtonsoft.Json;
using NzbDrone.Api.REST; using NzbDrone.Api.REST;
using NzbDrone.Core.MediaCover; using NzbDrone.Core.MediaCover;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;