mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 02:26:55 -07:00
More work on #273
This commit is contained in:
parent
1d3520ce93
commit
ebeedb90af
5 changed files with 76 additions and 9 deletions
|
@ -5,24 +5,32 @@ using Nancy;
|
|||
using Nancy.Responses.Negotiation;
|
||||
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.Models;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Store;
|
||||
using PlexRequests.UI.Models;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
public class IssuesModule : BaseAuthModule
|
||||
{
|
||||
public IssuesModule(ISettingsService<PlexRequestSettings> pr, IIssueService issueService) : base("issues", pr)
|
||||
public IssuesModule(ISettingsService<PlexRequestSettings> pr, IIssueService issueService, IRequestService request) : base("issues", pr)
|
||||
{
|
||||
IssuesService = issueService;
|
||||
RequestService = request;
|
||||
|
||||
Get["/"] = x => Index();
|
||||
|
||||
Get["/issuecount", true] = async (x, ct) => await IssueCount();
|
||||
|
||||
Get["/details/{id}", true] = async (x, ct) => await Details(x.id);
|
||||
|
||||
Post["/issue", true] = async (x, ct) => await ReportIssue((int)Request.Form.requestId, (IssueState)(int)Request.Form.issue, null);
|
||||
Post["/issuecomment", true] = async (x, ct) => await ReportIssue((int)Request.Form.requestId, IssueState.Other, (string)Request.Form.commentArea);
|
||||
}
|
||||
|
||||
private IIssueService IssuesService { get; }
|
||||
private IRequestService RequestService { get; }
|
||||
|
||||
public Negotiator Index()
|
||||
{
|
||||
|
@ -41,11 +49,57 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
var issue = await IssuesService.GetAsync(id);
|
||||
|
||||
return issue == null
|
||||
? Index()
|
||||
return issue == null
|
||||
? Index()
|
||||
: View["Details", issue];
|
||||
}
|
||||
|
||||
private async Task<Response> ReportIssue(int requestId, IssueState issue, string comment)
|
||||
{
|
||||
|
||||
var model = new IssueModel
|
||||
{
|
||||
Issue = issue,
|
||||
IssueStatus = IssueStatus.PendingIssue,
|
||||
UserReported = Username,
|
||||
UserNote = !string.IsNullOrEmpty(comment)
|
||||
? $"{Username} - {comment}"
|
||||
: string.Empty,
|
||||
};
|
||||
|
||||
var request = await RequestService.GetAsync(requestId);
|
||||
|
||||
var issueEntity = await IssuesService.GetAllAsync();
|
||||
var existingIssue = issueEntity.FirstOrDefault(x => x.RequestId == requestId);
|
||||
|
||||
// An issue already exists
|
||||
if (existingIssue != null)
|
||||
{
|
||||
existingIssue.Issues.Add(model);
|
||||
var result = await IssuesService.UpdateIssueAsync(existingIssue);
|
||||
|
||||
return Response.AsJson(result
|
||||
? new JsonResponseModel { Result = true }
|
||||
: new JsonResponseModel { Result = false });
|
||||
}
|
||||
|
||||
// New issue
|
||||
var issues = new IssuesModel
|
||||
{
|
||||
Title = request.Title,
|
||||
PosterUrl = request.PosterPath,
|
||||
RequestId = requestId,
|
||||
Type = request.Type
|
||||
};
|
||||
issues.Issues.Add(model);
|
||||
|
||||
var issueId = await IssuesService.AddIssueAsync(issues);
|
||||
|
||||
request.IssueId = issueId;
|
||||
await RequestService.UpdateRequestAsync(request);
|
||||
|
||||
|
||||
return Response.AsJson(new JsonResponseModel { Result = true });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,10 @@ using PlexRequests.UI.Models;
|
|||
using System.Threading.Tasks;
|
||||
|
||||
using Nancy.Extensions;
|
||||
using Nancy.Responses;
|
||||
|
||||
using PlexRequests.Api.Models.Tv;
|
||||
using PlexRequests.Core.Models;
|
||||
using PlexRequests.Store.Models;
|
||||
using PlexRequests.Store.Repository;
|
||||
|
||||
|
@ -65,7 +68,8 @@ namespace PlexRequests.UI.Modules
|
|||
ISettingsService<SickRageSettings> sickRageService, ICouchPotatoApi cpApi, ISickRageApi srApi,
|
||||
INotificationService notify, IMusicBrainzApi mbApi, IHeadphonesApi hpApi, ISettingsService<HeadphonesSettings> hpService,
|
||||
ICouchPotatoCacher cpCacher, ISonarrCacher sonarrCacher, ISickRageCacher sickRageCacher, IPlexApi plexApi,
|
||||
ISettingsService<PlexSettings> plexService, ISettingsService<AuthenticationSettings> auth, IRepository<UsersToNotify> u, ISettingsService<EmailNotificationSettings> email) : base("search", prSettings)
|
||||
ISettingsService<PlexSettings> plexService, ISettingsService<AuthenticationSettings> auth, IRepository<UsersToNotify> u, ISettingsService<EmailNotificationSettings> email,
|
||||
IIssueService issue) : base("search", prSettings)
|
||||
{
|
||||
Auth = auth;
|
||||
PlexService = plexService;
|
||||
|
@ -90,6 +94,7 @@ namespace PlexRequests.UI.Modules
|
|||
HeadphonesService = hpService;
|
||||
UsersToNotifyRepo = u;
|
||||
EmailNotificationSettings = email;
|
||||
IssueService = issue;
|
||||
|
||||
|
||||
Get["/", true] = async (x, ct) => await RequestLoad();
|
||||
|
@ -134,6 +139,7 @@ namespace PlexRequests.UI.Modules
|
|||
private IMusicBrainzApi MusicBrainzApi { get; }
|
||||
private IHeadphonesApi HeadphonesApi { get; }
|
||||
private IRepository<UsersToNotify> UsersToNotifyRepo { get; }
|
||||
private IIssueService IssueService { get; }
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private async Task<Negotiator> RequestLoad()
|
||||
|
@ -968,5 +974,7 @@ namespace PlexRequests.UI.Modules
|
|||
var model = seasons.Select(x => x.number);
|
||||
return Response.AsJson(model);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue