When a users requests content and the voting is enabled, the user who requested is an automatic +1 vote.

pull/2588/head^2
TidusJar 6 years ago
parent 870a07de9d
commit 4508f79a5f

@ -483,7 +483,7 @@ namespace Ombi.Core.Engine
RequestType = RequestType.Movie,
});
return new RequestEngineResult {Result = true, Message = $"{movieName} has been successfully added!"};
return new RequestEngineResult {Result = true, Message = $"{movieName} has been successfully added!", RequestId = model.Id};
}
public async Task<RequestQuotaCountModel> GetRemainingRequests(OmbiUser user)

@ -495,7 +495,7 @@ namespace Ombi.Core.Engine
RequestType = RequestType.Album,
});
return new RequestEngineResult { Result = true, Message = $"{model.Title} has been successfully added!" };
return new RequestEngineResult { Result = true, Message = $"{model.Title} has been successfully added!", RequestId = model.Id };
}

@ -6,5 +6,6 @@
public string Message { get; set; }
public bool IsError => !string.IsNullOrEmpty(ErrorMessage);
public string ErrorMessage { get; set; }
public int RequestId { get; set; }
}
}

@ -604,15 +604,16 @@ namespace Ombi.Core.Engine
var result = await TvSender.Send(model);
if (result.Success)
{
return new RequestEngineResult { Result = true };
return new RequestEngineResult { Result = true, RequestId = model.Id};
}
return new RequestEngineResult
{
ErrorMessage = result.Message
ErrorMessage = result.Message,
RequestId = model.Id
};
}
return new RequestEngineResult { Result = true };
return new RequestEngineResult { Result = true, RequestId = model.Id };
}
public async Task<RequestQuotaCountModel> GetRemainingRequests(OmbiUser user)

@ -149,13 +149,17 @@ namespace Ombi.Core.Engine
public async Task<VoteEngineResult> UpVote(int requestId, RequestType requestType)
{
var voteSettings = await _voteSettings.GetSettingsAsync();
if (!voteSettings.Enabled)
{
return new VoteEngineResult {Result = true};
}
// How many votes does this have?!
var currentVotes = GetVotes(requestId, requestType);
var voteSettings = await _voteSettings.GetSettingsAsync();
// Does this user have a downvote? If so we should revert it and make it an upvote
var user = await GetUser();
// Does this user have a downvote? If so we should revert it and make it an upvote
var currentVote = await GetVoteForUser(requestId, user.Id);
if (currentVote != null && currentVote.VoteType == VoteType.Upvote)
{
@ -206,7 +210,7 @@ namespace Ombi.Core.Engine
{
return new VoteEngineResult
{
ErrorMessage = "Voted succesfully but could not approve movie!"
ErrorMessage = "Voted succesfully but could not approve!"
};
}
@ -218,6 +222,11 @@ namespace Ombi.Core.Engine
public async Task<VoteEngineResult> DownVote(int requestId, RequestType requestType)
{
var voteSettings = await _voteSettings.GetSettingsAsync();
if (!voteSettings.Enabled)
{
return new VoteEngineResult { Result = true };
}
var user = await GetUser();
var currentVote = await GetVoteForUser(requestId, user.Id);
if (currentVote != null && currentVote.VoteType == VoteType.Downvote)

@ -4,10 +4,13 @@ using Ombi.Core.Engine;
using Ombi.Core.Models.Requests;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Ombi.Store.Entities.Requests;
using Ombi.Attributes;
using Ombi.Core.Models;
using Ombi.Core.Models.UI;
using Ombi.Store.Entities;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace Ombi.Controllers
{
@ -16,12 +19,16 @@ namespace Ombi.Controllers
[Produces("application/json")]
public class MusicRequestController : Controller
{
public MusicRequestController(IMusicRequestEngine engine)
public MusicRequestController(IMusicRequestEngine engine, IVoteEngine voteEngine, ILogger<MusicRequestController> log)
{
_engine = engine;
_voteEngine = voteEngine;
_log = log;
}
private readonly IMusicRequestEngine _engine;
private readonly IVoteEngine _voteEngine;
private readonly ILogger _log;
/// <summary>
/// Gets album requests.
@ -66,9 +73,19 @@ namespace Ombi.Controllers
/// <param name="album">The album.</param>
/// <returns></returns>
[HttpPost]
public async Task<RequestEngineResult> Request([FromBody] MusicAlbumRequestViewModel album)
public async Task<RequestEngineResult> RequestAlbum([FromBody] MusicAlbumRequestViewModel album)
{
return await _engine.RequestAlbum(album);
var result = await _engine.RequestAlbum(album);
if (result.Result)
{
var voteResult = await _voteEngine.UpVote(result.RequestId, RequestType.Album);
if (voteResult.IsError)
{
_log.LogError("Couldn't automatically add the vote for the album {0} because {1}", album.ForeignAlbumId, voteResult.ErrorMessage);
}
}
return result;
}
/// <summary>

@ -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>

Loading…
Cancel
Save