diff --git a/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs b/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs index 3410313cb..32e1a150b 100644 --- a/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs +++ b/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs @@ -10,7 +10,7 @@ namespace Ombi.Core.Engine.Interfaces Task RemoveTvRequest(int requestId); Task RequestTvShow(SearchTvShowViewModel tv); - Task DenyChildRequest(ChildRequests request); + Task DenyChildRequest(int requestId); Task ChangeAvailability(ChildRequests request); Task> SearchTvRequest(string search); Task>>> SearchTvRequestTree(string search); @@ -19,6 +19,6 @@ namespace Ombi.Core.Engine.Interfaces Task> GetAllChldren(int tvId); Task UpdateChildRequest(ChildRequests request); Task RemoveTvChild(int requestId); - Task ApproveChildRequest(ChildRequests request); + Task ApproveChildRequest(int id); } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/MovieRequestEngine.cs b/src/Ombi.Core/Engine/MovieRequestEngine.cs index 91fb44d63..7f2ee0599 100644 --- a/src/Ombi.Core/Engine/MovieRequestEngine.cs +++ b/src/Ombi.Core/Engine/MovieRequestEngine.cs @@ -191,6 +191,7 @@ namespace Ombi.Core.Engine }; } request.Approved = true; + request.Denied = false; await MovieRepository.Update(request); NotificationHelper.Notify(request, NotificationType.RequestApproved); diff --git a/src/Ombi.Core/Engine/TvRequestEngine.cs b/src/Ombi.Core/Engine/TvRequestEngine.cs index eb38ff1d1..fd6288098 100644 --- a/src/Ombi.Core/Engine/TvRequestEngine.cs +++ b/src/Ombi.Core/Engine/TvRequestEngine.cs @@ -178,9 +178,20 @@ namespace Ombi.Core.Engine return results; } - public async Task ApproveChildRequest(ChildRequests request) + public async Task ApproveChildRequest(int id) { + var request = await TvRepository.GetChild().FirstOrDefaultAsync(x => x.Id == id); + if (request == null) + { + return new RequestEngineResult + { + ErrorMessage = "Child Request does not exist" + }; + } + request.Approved = true; + request.Denied = false; await TvRepository.UpdateChild(request); + if (request.Approved) { NotificationHelper.Notify(request, NotificationType.RequestApproved); @@ -194,10 +205,23 @@ namespace Ombi.Core.Engine }; } - public async Task DenyChildRequest(ChildRequests request) + public async Task DenyChildRequest(int requestId) { + var request = await TvRepository.GetChild().FirstOrDefaultAsync(x => x.Id == requestId); + if (request == null) + { + return new RequestEngineResult + { + ErrorMessage = "Child Request does not exist" + }; + } + request.Denied = true; + await TvRepository.UpdateChild(request); NotificationHelper.Notify(request, NotificationType.RequestDeclined); - return await UpdateChildRequest(request); + return new RequestEngineResult + { + RequestAdded = true + }; } public async Task ChangeAvailability(ChildRequests request) diff --git a/src/Ombi/ClientApp/app/interfaces/IRequestModel.ts b/src/Ombi/ClientApp/app/interfaces/IRequestModel.ts index 161529049..888e8efff 100644 --- a/src/Ombi/ClientApp/app/interfaces/IRequestModel.ts +++ b/src/Ombi/ClientApp/app/interfaces/IRequestModel.ts @@ -130,6 +130,10 @@ export interface IChildRequests extends IBaseRequest { seasonRequests: INewSeasonRequests[]; } +export interface ITvUpdateModel { + id: number; +} + export interface INewSeasonRequests { id: number; seasonNumber: number; diff --git a/src/Ombi/ClientApp/app/requests/movierequests.component.ts b/src/Ombi/ClientApp/app/requests/movierequests.component.ts index fc715b021..aeb694158 100644 --- a/src/Ombi/ClientApp/app/requests/movierequests.component.ts +++ b/src/Ombi/ClientApp/app/requests/movierequests.component.ts @@ -80,7 +80,6 @@ export class MovieRequestsComponent implements OnInit { } public deny(request: IMovieRequests) { - request.approved = false; request.denied = true; this.updateRequest(request); } diff --git a/src/Ombi/ClientApp/app/requests/tvrequest-children.component.html b/src/Ombi/ClientApp/app/requests/tvrequest-children.component.html index 566bae7e9..5066a5b78 100644 --- a/src/Ombi/ClientApp/app/requests/tvrequest-children.component.html +++ b/src/Ombi/ClientApp/app/requests/tvrequest-children.component.html @@ -12,7 +12,7 @@
-
+
@@ -65,11 +65,13 @@ {{ep.airDate | date: 'dd/MM/yyyy' }} - Available - Processing Request -
+ Denied + Available + Processing Request +
Pending Approval
+ diff --git a/src/Ombi/ClientApp/app/requests/tvrequest-children.component.ts b/src/Ombi/ClientApp/app/requests/tvrequest-children.component.ts index 268e42410..798e63cc5 100644 --- a/src/Ombi/ClientApp/app/requests/tvrequest-children.component.ts +++ b/src/Ombi/ClientApp/app/requests/tvrequest-children.component.ts @@ -23,7 +23,6 @@ export class TvRequestChildrenComponent { } public deny(request: IChildRequests) { - request.approved = false; request.denied = true; request.seasonRequests.forEach((season) => { @@ -31,8 +30,16 @@ export class TvRequestChildrenComponent { ep.approved = false; }); }); - this.requestService.deleteChild(request) - .subscribe(); + this.requestService.denyChild({ id: request.id }) + .subscribe(x => { + if (x.requestAdded) { + this.notificationService.success("Request Denied", + `Request has been denied successfully`); + } else { + this.notificationService.warning("Request Denied", x.message ? x.message : x.errorMessage); + request.approved = false; + } + }); } public approve(request: IChildRequests) { @@ -43,7 +50,7 @@ export class TvRequestChildrenComponent { ep.approved = true; }); }); - this.requestService.approveChild(request) + this.requestService.approveChild({ id: request.id }) .subscribe(x => { if (x.requestAdded) { this.notificationService.success("Request Approved", diff --git a/src/Ombi/ClientApp/app/services/request.service.ts b/src/Ombi/ClientApp/app/services/request.service.ts index a8acab091..0d3167ea2 100644 --- a/src/Ombi/ClientApp/app/services/request.service.ts +++ b/src/Ombi/ClientApp/app/services/request.service.ts @@ -6,7 +6,7 @@ import { Observable } from "rxjs/Rx"; import { TreeNode } from "primeng/primeng"; import { IRequestEngineResult } from "../interfaces"; -import { IChildRequests, IMovieRequests, IMovieUpdateModel, IRequestCountModel, IRequestGrid, ITvRequests } from "../interfaces"; +import { IChildRequests, IMovieRequests, IMovieUpdateModel, IRequestCountModel, IRequestGrid, ITvRequests, ITvUpdateModel } from "../interfaces"; import { ISearchMovieResult } from "../interfaces"; import { ISearchTvResult } from "../interfaces"; import { ServiceAuthHelpers } from "./service.helpers"; @@ -29,6 +29,10 @@ export class RequestService extends ServiceAuthHelpers { return this.http.post(`${this.url}Movie/Approve`, JSON.stringify(movie), { headers: this.headers }).map(this.extractData); } + public denyMovie(movie: IMovieUpdateModel): Observable { + return this.http.put(`${this.url}Movie/Deny`, JSON.stringify(movie), { headers: this.headers }).map(this.extractData); + } + public getMovieRequests(count: number, position: number): Observable { return this.http.get(`${this.url}movie/${count}/${position}`).map(this.extractData); } @@ -78,14 +82,14 @@ export class RequestService extends ServiceAuthHelpers { public updateChild(child: IChildRequests): Observable { return this.http.put(`${this.url}tv/child`, JSON.stringify(child), { headers: this.headers }).map(this.extractData); } - public denyChild(child: IChildRequests): Observable { + public denyChild(child: ITvUpdateModel): Observable { return this.http.put(`${this.url}tv/deny`, JSON.stringify(child), { headers: this.headers }).map(this.extractData); } public changeAvailabilityChild(child: IChildRequests): Observable { return this.http.put(`${this.url}tv/changeavailability`, JSON.stringify(child), { headers: this.headers }).map(this.extractData); } - public approveChild(child: IChildRequests): Observable { - return this.http.post(`${this.url}tv/child/approve`, JSON.stringify(child), { headers: this.headers }).map(this.extractData); + public approveChild(child: ITvUpdateModel): Observable { + return this.http.post(`${this.url}tv/approve`, JSON.stringify(child), { headers: this.headers }).map(this.extractData); } public deleteChild(child: IChildRequests): Observable { return this.http.delete(`${this.url}tv/child/${child.id}`, { headers: this.headers }).map(this.extractData); diff --git a/src/Ombi/Controllers/RequestController.cs b/src/Ombi/Controllers/RequestController.cs index 89f82a85d..60fd9fe0c 100644 --- a/src/Ombi/Controllers/RequestController.cs +++ b/src/Ombi/Controllers/RequestController.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Ombi.Store.Entities.Requests; using System.Diagnostics; +using Ombi.Models; namespace Ombi.Controllers { @@ -81,7 +82,7 @@ namespace Ombi.Controllers /// /// Updates the specified movie request. /// - /// The model. + /// The Movie's ID /// [HttpPut("movie")] public async Task UpdateRequest([FromBody] MovieRequests model) @@ -92,7 +93,7 @@ namespace Ombi.Controllers /// /// Approves the specified movie request. /// - /// The model. + /// The Movie's ID /// [HttpPost("movie/approve")] public async Task ApproveMovie([FromBody] MovieUpdateModel model) @@ -103,9 +104,9 @@ namespace Ombi.Controllers /// /// Denies the specified movie request. /// - /// The model. + /// The Movie's ID /// - [HttpPost("movie/deny")] + [HttpPut("movie/deny")] public async Task DenyMovie([FromBody] MovieUpdateModel model) { return await MovieRequestEngine.DenyMovieById(model.Id); @@ -214,12 +215,12 @@ namespace Ombi.Controllers /// /// Denies the a specific child request /// - /// The model. + /// This is the child request's ID /// [HttpPut("tv/deny")] - public async Task DenyChild([FromBody] ChildRequests child) + public async Task DenyChild([FromBody] TvUpdateModel model) { - return await TvRequestEngine.DenyChildRequest(child); + return await TvRequestEngine.DenyChildRequest(model.Id); } /// @@ -236,12 +237,12 @@ namespace Ombi.Controllers /// /// Updates the a specific child request /// - /// The model. + /// This is the child request's ID /// - [HttpPost("tv/child/approve")] - public async Task ApproveChild([FromBody] ChildRequests child) + [HttpPost("tv/approve")] + public async Task ApproveChild([FromBody] TvUpdateModel model) { - return await TvRequestEngine.ApproveChildRequest(child); + return await TvRequestEngine.ApproveChildRequest(model.Id); } /// diff --git a/src/Ombi/Models/TvUpdateModel.cs b/src/Ombi/Models/TvUpdateModel.cs new file mode 100644 index 000000000..8bbdf38b2 --- /dev/null +++ b/src/Ombi/Models/TvUpdateModel.cs @@ -0,0 +1,33 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2017 Jamie Rees +// File: TvUpdateModel.cs +// Created By: Jamie Rees +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// ************************************************************************/ +#endregion +namespace Ombi.Models +{ + public class TvUpdateModel + { + public int Id { get; set; } + } +} \ No newline at end of file