Fixed: Alt Titles on Main Load, Alt Titles API updates

pull/3564/head
Qstick 5 years ago
parent ac59b7060e
commit d86c811543

@ -50,7 +50,7 @@ namespace NzbDrone.Core.Datastore
_eventAggregator = eventAggregator;
}
protected QueryBuilder<TModel> Query => DataMapper.Query<TModel>();
protected QueryBuilder<TModel> Query => AddJoinQueries(DataMapper.Query<TModel>());
protected void Delete(Expression<Func<TModel, bool>> filter)
{
@ -59,7 +59,7 @@ namespace NzbDrone.Core.Datastore
public IEnumerable<TModel> All()
{
return DataMapper.Query<TModel>().ToList();
return AddJoinQueries(DataMapper.Query<TModel>()).ToList();
}
public int Count()
@ -296,6 +296,11 @@ namespace NzbDrone.Core.Datastore
}
}
protected virtual QueryBuilder<TActual> AddJoinQueries<TActual>(QueryBuilder<TActual> baseQuery)
{
return baseQuery;
}
protected virtual bool PublishModelEvents => false;
}
}

@ -13,6 +13,7 @@ namespace NzbDrone.Core.Movies.AlternativeTitles
AlternativeTitle AddAltTitle(AlternativeTitle title, Movie movie);
List<AlternativeTitle> AddAltTitles(List<AlternativeTitle> titles, Movie movie);
AlternativeTitle GetById(int id);
List<AlternativeTitle> GetAllTitles();
void DeleteNotEnoughVotes(List<AlternativeTitle> mappingsTitles);
}
@ -58,6 +59,11 @@ namespace NzbDrone.Core.Movies.AlternativeTitles
return _titleRepo.Get(id);
}
public List<AlternativeTitle> GetAllTitles()
{
return _titleRepo.All().ToList();
}
public void RemoveTitle(AlternativeTitle title)
{
_titleRepo.Delete(title);

@ -270,5 +270,14 @@ namespace NzbDrone.Core.Movies
{
return Query.Where(m => m.TmdbId == tmdbid).FirstOrDefault();
}
protected override QueryBuilder<TActual> AddJoinQueries<TActual>(QueryBuilder<TActual> baseQuery)
{
baseQuery = base.AddJoinQueries(baseQuery);
baseQuery = baseQuery.Join<Movie, AlternativeTitle>(JoinType.Left, m => m.AlternativeTitles,
(m, t) => m.Id == t.MovieId);
return baseQuery;
}
}
}

@ -450,16 +450,12 @@ namespace NzbDrone.Core.Parser
{
case MappingResultType.Success:
return $"Successfully mapped release name {ReleaseName} to movie {Movie}";
break;
case MappingResultType.SuccessLenientMapping:
return $"Successfully mapped parts of the release name {ReleaseName} to movie {Movie}";
break;
case MappingResultType.NotParsable:
return $"Failed to find movie title in release name {ReleaseName}";
break;
case MappingResultType.TitleNotFound:
return $"Could not find {RemoteMovie.ParsedMovieInfo.MovieTitle}";
break;
case MappingResultType.WrongYear:
return $"Failed to map movie, expected year {RemoteMovie.Movie.Year}, but found {RemoteMovie.ParsedMovieInfo.Year}";
case MappingResultType.WrongTitle:

@ -1,19 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Marr.Data;
using Nancy;
using Radarr.Api.V2;
using NzbDrone.Common.Cache;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.MovieImport;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.MetadataSource.RadarrAPI;
using NzbDrone.Core.Movies.AlternativeTitles;
using NzbDrone.Core.RootFolders;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Movies.Events;
using Radarr.Http;
@ -33,9 +22,11 @@ namespace Radarr.Api.V2.Movies
_altTitleService = altTitleService;
_movieService = movieService;
_radarrApi = radarrApi;
CreateResource = AddTitle;
GetResourceById = GetTitle;
_eventAggregator = eventAggregator;
CreateResource = AddTitle;
GetResourceById = GetAltTitle;
GetResourceAll = GetAltTitles;
}
private int AddTitle(AlternativeTitleResource altTitle)
@ -49,9 +40,23 @@ namespace Radarr.Api.V2.Movies
return addedTitle.Id;
}
private AlternativeTitleResource GetTitle(int id)
private AlternativeTitleResource GetAltTitle(int id)
{
return _altTitleService.GetById(id).ToResource();
}
private List<AlternativeTitleResource> GetAltTitles()
{
var movieIdQuery = Request.Query.MovieId;
if (movieIdQuery.HasValue)
{
int movieId = Convert.ToInt32(movieIdQuery.Value);
return _altTitleService.GetAllTitlesForMovie(movieId).ToResource();
}
return _altTitleService.GetAllTitles().ToResource();
}
}
}

@ -2,12 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Radarr.Http.REST;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Movies.AlternativeTitles;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Languages;
namespace Radarr.Api.V2.Movies

Loading…
Cancel
Save