Added recently added stuff

pull/2089/head
Jamie 7 years ago
parent 109f5317bb
commit ee50eb79b7

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using Ombi.Core.Models;
namespace Ombi.Core.Engine
{
public interface IRecentlyAddedEngine
{
IEnumerable<RecentlyAddedMovieModel> GetRecentlyAddedMovies();
IEnumerable<RecentlyAddedMovieModel> GetRecentlyAddedMovies(DateTime from, DateTime to);
}
}

@ -11,7 +11,7 @@ using Ombi.Store.Repository;
namespace Ombi.Core.Engine namespace Ombi.Core.Engine
{ {
public class RecentlyAddedEngine public class RecentlyAddedEngine : IRecentlyAddedEngine
{ {
public RecentlyAddedEngine(IPlexContentRepository plex, IEmbyContentRepository emby) public RecentlyAddedEngine(IPlexContentRepository plex, IEmbyContentRepository emby)
{ {
@ -22,11 +22,11 @@ namespace Ombi.Core.Engine
private readonly IPlexContentRepository _plex; private readonly IPlexContentRepository _plex;
private readonly IEmbyContentRepository _emby; private readonly IEmbyContentRepository _emby;
public IEnumerable<RecentlyAddedMovieModel> GetRecentlyAddedMovies(TimeSpan from) public IEnumerable<RecentlyAddedMovieModel> GetRecentlyAddedMovies(DateTime from, DateTime to)
{ {
var model = new HashSet<RecentlyAddedMovieModel>(); var model = new HashSet<RecentlyAddedMovieModel>();
var plexMovies = _plex.GetAll().Where(x => x.Type == PlexMediaTypeEntity.Movie && x.AddedAt.Subtract(from) <= x.AddedAt); var plexMovies = _plex.GetAll().Where(x => x.Type == PlexMediaTypeEntity.Movie && x.AddedAt > from && x.AddedAt < to);
var embyMovies = _emby.GetAll().Where(x => x.Type == EmbyMediaType.Movie && x.AddedAt.Subtract(from) <= x.AddedAt); var embyMovies = _emby.GetAll().Where(x => x.Type == EmbyMediaType.Movie && x.AddedAt > from && x.AddedAt < to);
TransformPlexMovies(plexMovies, model); TransformPlexMovies(plexMovies, model);
TransformEmbyMovies(embyMovies, model); TransformEmbyMovies(embyMovies, model);

@ -79,6 +79,7 @@ namespace Ombi.DependencyInjection
services.AddTransient<ITvSearchEngine, TvSearchEngine>(); services.AddTransient<ITvSearchEngine, TvSearchEngine>();
services.AddTransient<IRuleEvaluator, RuleEvaluator>(); services.AddTransient<IRuleEvaluator, RuleEvaluator>();
services.AddTransient<IMovieSender, MovieSender>(); services.AddTransient<IMovieSender, MovieSender>();
services.AddTransient<IRecentlyAddedEngine, RecentlyAddedEngine>();
services.AddTransient<ITvSender, TvSender>(); services.AddTransient<ITvSender, TvSender>();
} }
public static void RegisterHttp(this IServiceCollection services) public static void RegisterHttp(this IServiceCollection services)

@ -0,0 +1,33 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Ombi.Core.Engine;
using Ombi.Core.Models;
using Ombi.Models;
namespace Ombi.Controllers
{
[ApiV1]
[Produces("application/json")]
[Authorize]
public class RecentlyAddedController : Controller
{
public RecentlyAddedController(IRecentlyAddedEngine engine)
{
_recentlyAdded = engine;
}
private readonly IRecentlyAddedEngine _recentlyAdded;
/// <summary>
/// Returns the recently added movies between two dates
/// </summary>
[HttpPost("movies")]
[ProducesResponseType(typeof(IEnumerable<RecentlyAddedMovieModel>), 200)]
public IEnumerable<RecentlyAddedMovieModel> GetRecentlyAddedMovies([FromBody] RecentlyAddedRangeModel model)
{
return _recentlyAdded.GetRecentlyAddedMovies(model.From, model.To);
}
}
}

@ -0,0 +1,10 @@
using System;
namespace Ombi.Models
{
public class RecentlyAddedRangeModel
{
public DateTime From { get; set; }
public DateTime To { get; set; }
}
}
Loading…
Cancel
Save