|
|
|
@ -8,6 +8,7 @@ using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Ombi.Store.Entities.Requests;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Ombi.Attributes;
|
|
|
|
|
using Ombi.Core.Models.UI;
|
|
|
|
|
using Ombi.Models;
|
|
|
|
@ -21,14 +22,19 @@ namespace Ombi.Controllers
|
|
|
|
|
[Produces("application/json")]
|
|
|
|
|
public class RequestController : Controller
|
|
|
|
|
{
|
|
|
|
|
public RequestController(IMovieRequestEngine engine, ITvRequestEngine tvRequestEngine)
|
|
|
|
|
public RequestController(IMovieRequestEngine engine, ITvRequestEngine tvRequestEngine, IVoteEngine vote,
|
|
|
|
|
ILogger<RequestController> log)
|
|
|
|
|
{
|
|
|
|
|
MovieRequestEngine = engine;
|
|
|
|
|
TvRequestEngine = tvRequestEngine;
|
|
|
|
|
VoteEngine = vote;
|
|
|
|
|
Log = log;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IMovieRequestEngine MovieRequestEngine { get; }
|
|
|
|
|
private ITvRequestEngine TvRequestEngine { get; }
|
|
|
|
|
private IVoteEngine VoteEngine { get; }
|
|
|
|
|
private ILogger Log { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets movie requests.
|
|
|
|
@ -75,7 +81,17 @@ namespace Ombi.Controllers
|
|
|
|
|
[HttpPost("movie")]
|
|
|
|
|
public async Task<RequestEngineResult> RequestMovie([FromBody] MovieRequestViewModel movie)
|
|
|
|
|
{
|
|
|
|
|
return await MovieRequestEngine.RequestMovie(movie);
|
|
|
|
|
var result = await MovieRequestEngine.RequestMovie(movie);
|
|
|
|
|
if (result.Result)
|
|
|
|
|
{
|
|
|
|
|
var voteResult = await VoteEngine.UpVote(result.RequestId, RequestType.Movie);
|
|
|
|
|
if (voteResult.IsError)
|
|
|
|
|
{
|
|
|
|
|
Log.LogError("Couldn't automatically add the vote for the movie {0} because {1}", movie.TheMovieDbId, voteResult.ErrorMessage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -249,7 +265,17 @@ namespace Ombi.Controllers
|
|
|
|
|
[HttpPost("tv")]
|
|
|
|
|
public async Task<RequestEngineResult> RequestTv([FromBody] TvRequestViewModel tv)
|
|
|
|
|
{
|
|
|
|
|
return await TvRequestEngine.RequestTvShow(tv);
|
|
|
|
|
var result = await TvRequestEngine.RequestTvShow(tv);
|
|
|
|
|
if (result.Result)
|
|
|
|
|
{
|
|
|
|
|
var voteResult = await VoteEngine.UpVote(result.RequestId, RequestType.TvShow);
|
|
|
|
|
if (voteResult.IsError)
|
|
|
|
|
{
|
|
|
|
|
Log.LogError("Couldn't automatically add the vote for the tv {0} because {1}", tv.TvDbId, voteResult.ErrorMessage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|