Temp Fix for Calendar Feed until Data Mapper can be fixed.

This commit is contained in:
Qstick 2017-11-25 00:16:46 -05:00
parent 8c68ddfeb2
commit f7f6ad159c
2 changed files with 30 additions and 4 deletions

View File

@ -19,12 +19,14 @@ namespace Lidarr.Api.V1.Calendar
public class CalendarFeedModule : LidarrV1FeedModule
{
private readonly IAlbumService _albumService;
private readonly IArtistService _artistService;
private readonly ITagService _tagService;
public CalendarFeedModule(IAlbumService albumService, ITagService tagService)
public CalendarFeedModule(IAlbumService albumService, IArtistService artistService, ITagService tagService)
: base("calendar")
{
_albumService = albumService;
_artistService = artistService;
_tagService = tagService;
Get["/Lidarr.ics"] = options => GetCalendarFeed();
@ -37,7 +39,6 @@ namespace Lidarr.Api.V1.Calendar
var start = DateTime.Today.AddDays(-pastDays);
var end = DateTime.Today.AddDays(futureDays);
var unmonitored = Request.GetBooleanQueryParameter("unmonitored");
var asAllDay = Request.GetBooleanQueryParameter("asAllDay");
var tags = new List<int>();
var queryPastDays = Request.Query.PastDays;
@ -74,7 +75,9 @@ namespace Lidarr.Api.V1.Calendar
foreach (var album in albums.OrderBy(v => v.ReleaseDate.Value))
{
if (tags.Any() && tags.None(album.Artist.Tags.Contains))
var artist = _artistService.GetArtist(album.ArtistId); // Temp fix TODO: Figure out why Album.Artist is not populated during AlbumsBetweenDates Query
if (tags.Any() && tags.None(artist.Tags.Contains))
{
continue;
}
@ -87,7 +90,7 @@ namespace Lidarr.Api.V1.Calendar
occurrence.Start = new CalDateTime(album.ReleaseDate.Value.ToLocalTime()) { HasTime = false };
occurrence.Summary = $"{album.Artist.Name} - {album.Title}";
occurrence.Summary = $"{artist.Name} - {album.Title}";
}
var serializer = (IStringSerializer)new SerializerFactory().Build(calendar.GetType(), new SerializationContext());

View File

@ -46,6 +46,13 @@ namespace NzbDrone.Core.Test.Datastore
Db.InsertMany(artist);
var albums = Builder<Album>.CreateListOfSize(3)
.All()
.With(v => v.ArtistId = artist[0].Id)
.BuildListOfNew();
Db.InsertMany(albums);
var trackFiles = Builder<TrackFile>.CreateListOfSize(1)
.All()
.With(v => v.ArtistId = artist[0].Id)
@ -64,6 +71,22 @@ namespace NzbDrone.Core.Test.Datastore
Db.InsertMany(tracks);
}
[Test]
public void should_join_artist_when_query_for_albums()
{
var db = Mocker.Resolve<IDatabase>();
var DataMapper = db.GetDataMapper();
var albums = DataMapper.Query<Album>()
.Join<Album, Artist>(Marr.Data.QGen.JoinType.Inner, v => v.Artist, (l, r) => l.ArtistId == r.Id)
.ToList();
foreach (var album in albums)
{
Assert.IsNotNull(album.Artist);
}
}
[Test]
public void should_lazy_load_profile_if_not_joined()
{