|
|
|
@ -1,12 +1,14 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Ombi.Core.Engine;
|
|
|
|
|
using Ombi.Core.Engine.Interfaces;
|
|
|
|
|
using Ombi.Core.Models.Requests;
|
|
|
|
|
using Ombi.Core.Models.Requests.Movie;
|
|
|
|
|
using Ombi.Core.Models.Search;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Ombi.Models;
|
|
|
|
|
|
|
|
|
|
namespace Ombi.Controllers
|
|
|
|
|
{
|
|
|
|
@ -22,15 +24,20 @@ namespace Ombi.Controllers
|
|
|
|
|
private IMovieRequestEngine MovieRequestEngine { get; }
|
|
|
|
|
private ITvRequestEngine TvRequestEngine { get; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("movie/{count:int}/{position:int}")]
|
|
|
|
|
public async Task<IEnumerable<MovieRequestModel>> GetRequests(int count, int position)
|
|
|
|
|
{
|
|
|
|
|
return await MovieRequestEngine.GetMovieRequests(count, position);
|
|
|
|
|
return await MovieRequestEngine.GetRequests(count, position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("movie")]
|
|
|
|
|
public async Task<IEnumerable<MovieRequestModel>> GetRequests()
|
|
|
|
|
{
|
|
|
|
|
return await MovieRequestEngine.GetRequests();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("movie")]
|
|
|
|
|
public async Task<RequestEngineResult> RequestMovie([FromBody]SearchMovieViewModel movie)
|
|
|
|
|
public async Task<RequestEngineResult> RequestMovie([FromBody] SearchMovieViewModel movie)
|
|
|
|
|
{
|
|
|
|
|
return await MovieRequestEngine.RequestMovie(movie);
|
|
|
|
|
}
|
|
|
|
@ -38,7 +45,6 @@ namespace Ombi.Controllers
|
|
|
|
|
[HttpGet("movie/search/{searchTerm}")]
|
|
|
|
|
public async Task<IEnumerable<MovieRequestModel>> Search(string searchTerm)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return await MovieRequestEngine.SearchMovieRequest(searchTerm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -49,7 +55,7 @@ namespace Ombi.Controllers
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPut("movie")]
|
|
|
|
|
public async Task<MovieRequestModel> UpdateRequest([FromBody]MovieRequestModel model)
|
|
|
|
|
public async Task<MovieRequestModel> UpdateRequest([FromBody] MovieRequestModel model)
|
|
|
|
|
{
|
|
|
|
|
return await MovieRequestEngine.UpdateMovieRequest(model);
|
|
|
|
|
}
|
|
|
|
@ -57,28 +63,24 @@ namespace Ombi.Controllers
|
|
|
|
|
[HttpGet("tv/{count:int}/{position:int}")]
|
|
|
|
|
public async Task<IEnumerable<TvRequestModel>> GetTvRequests(int count, int position)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return await TvRequestEngine.GetTvRequests(count, position);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
return await TvRequestEngine.GetRequests(count, position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("tv")]
|
|
|
|
|
public async Task<IEnumerable<TvRequestModel>> GetTvRequests()
|
|
|
|
|
{
|
|
|
|
|
return await TvRequestEngine.GetRequests();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("tv")]
|
|
|
|
|
public async Task<RequestEngineResult> RequestTv([FromBody]SearchTvShowViewModel tv)
|
|
|
|
|
public async Task<RequestEngineResult> RequestTv([FromBody] SearchTvShowViewModel tv)
|
|
|
|
|
{
|
|
|
|
|
return await TvRequestEngine.RequestTvShow(tv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("tv/search/{searchTerm}")]
|
|
|
|
|
public async Task<IEnumerable<TvRequestModel>> SearchTv(string searchTerm)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return await TvRequestEngine.SearchTvRequest(searchTerm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -89,7 +91,7 @@ namespace Ombi.Controllers
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPut("tv")]
|
|
|
|
|
public async Task<TvRequestModel> UpdateRequest([FromBody]TvRequestModel model)
|
|
|
|
|
public async Task<TvRequestModel> UpdateRequest([FromBody] TvRequestModel model)
|
|
|
|
|
{
|
|
|
|
|
return await TvRequestEngine.UpdateTvRequest(model);
|
|
|
|
|
}
|
|
|
|
@ -101,5 +103,30 @@ namespace Ombi.Controllers
|
|
|
|
|
// Doesn't matter if we use the TvEngine or MovieEngine, this method is in the base class
|
|
|
|
|
return TvRequestEngine.RequestCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("tv/grid")]
|
|
|
|
|
public async Task<RequestGridModel<TvRequestModel>> GetTvRequestsGrid()
|
|
|
|
|
{
|
|
|
|
|
return await GetGrid(TvRequestEngine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("movie/grid")]
|
|
|
|
|
public async Task<RequestGridModel<MovieRequestModel>> GetMovieRequestsGrid()
|
|
|
|
|
{
|
|
|
|
|
return await GetGrid(MovieRequestEngine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<RequestGridModel<T>> GetGrid<T>(IRequestEngine<T> engine) where T : BaseRequestModel
|
|
|
|
|
{
|
|
|
|
|
var allRequests = await engine.GetRequests();
|
|
|
|
|
var r = allRequests.ToList();
|
|
|
|
|
var model = new RequestGridModel<T>
|
|
|
|
|
{
|
|
|
|
|
Available = r.Where(x => x.Available && !x.Approved),
|
|
|
|
|
Approved = r.Where(x => x.Approved && !x.Available),
|
|
|
|
|
New = r.Where(x => !x.Available && !x.Approved)
|
|
|
|
|
};
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|