mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-31 03:50:08 -07:00
This commit is contained in:
parent
e7aba8a4c8
commit
9d4881032d
3 changed files with 47 additions and 11 deletions
|
@ -5,10 +5,14 @@ using System.Threading.Tasks;
|
|||
|
||||
using Nancy;
|
||||
using Nancy.Responses.Negotiation;
|
||||
using Nancy.Security;
|
||||
|
||||
using NLog;
|
||||
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.Models;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Store;
|
||||
using PlexRequests.UI.Models;
|
||||
|
||||
|
@ -23,22 +27,37 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
Get["/"] = x => Index();
|
||||
|
||||
Get["/issuecount", true] = async (x, ct) => await IssueCount();
|
||||
|
||||
Get["/{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);
|
||||
|
||||
Get["/inprogress", true] = async (x, ct) => await GetInProgressIssues(IssueStatus.InProgressIssue);
|
||||
Get["/pending", true] = async (x, ct) => await GetInProgressIssues(IssueStatus.PendingIssue);
|
||||
Get["/resolved", true] = async (x, ct) => await GetInProgressIssues(IssueStatus.ResolvedIssue);
|
||||
|
||||
Post["/remove", true] = async (x, ct) => await RemoveIssue((int)Request.Form.issueId);
|
||||
|
||||
Get["/issuecount", true] = async (x, ct) => await IssueCount();
|
||||
|
||||
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; }
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public Negotiator Index()
|
||||
{
|
||||
return View["Index"];
|
||||
}
|
||||
|
||||
private async Task<Response> GetInProgressIssues(IssueStatus status)
|
||||
{
|
||||
var issues = await IssuesService.GetAllAsync();
|
||||
|
||||
return Response.AsJson(issues.Where(x => x.IssueStatus == status));
|
||||
}
|
||||
|
||||
public async Task<Response> IssueCount()
|
||||
{
|
||||
var issues = await IssuesService.GetAllAsync();
|
||||
|
@ -52,7 +71,6 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
public async Task<Negotiator> Details(int id)
|
||||
{
|
||||
|
||||
var issue = await IssuesService.GetAsync(id);
|
||||
|
||||
return issue == null
|
||||
|
@ -66,7 +84,6 @@ namespace PlexRequests.UI.Modules
|
|||
var model = new IssueModel
|
||||
{
|
||||
Issue = issue,
|
||||
IssueStatus = IssueStatus.PendingIssue,
|
||||
UserReported = Username,
|
||||
UserNote = !string.IsNullOrEmpty(comment)
|
||||
? $"{Username} - {comment}"
|
||||
|
@ -95,7 +112,8 @@ namespace PlexRequests.UI.Modules
|
|||
Title = request.Title,
|
||||
PosterUrl = request.PosterPath,
|
||||
RequestId = requestId,
|
||||
Type = request.Type
|
||||
Type = request.Type,
|
||||
IssueStatus = IssueStatus.PendingIssue
|
||||
};
|
||||
issues.Issues.Add(model);
|
||||
|
||||
|
@ -130,6 +148,24 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
return myIssues;
|
||||
}
|
||||
|
||||
private async Task<Response> RemoveIssue(int issueId)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.RequiresClaims(UserClaims.PowerUser);
|
||||
|
||||
await IssuesService.DeleteIssueAsync(issueId);
|
||||
|
||||
return Response.AsJson(new JsonResponseModel {Result = true, Message = "Issue Removed"});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Looks like we couldn't remove the issue. Check the logs!" });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue