parent
8024f4658c
commit
13224f03cc
@ -1,160 +0,0 @@
|
|||||||
import PropTypes from 'prop-types';
|
|
||||||
import React, { Component } from 'react';
|
|
||||||
import { connect } from 'react-redux';
|
|
||||||
import { createSelector } from 'reselect';
|
|
||||||
import * as commandNames from 'Commands/commandNames';
|
|
||||||
import withCurrentPage from 'Components/withCurrentPage';
|
|
||||||
import * as blacklistActions from 'Store/Actions/blacklistActions';
|
|
||||||
import { executeCommand } from 'Store/Actions/commandActions';
|
|
||||||
import createCommandExecutingSelector from 'Store/Selectors/createCommandExecutingSelector';
|
|
||||||
import { registerPagePopulator, unregisterPagePopulator } from 'Utilities/pagePopulator';
|
|
||||||
import Blacklist from './Blacklist';
|
|
||||||
|
|
||||||
function createMapStateToProps() {
|
|
||||||
return createSelector(
|
|
||||||
(state) => state.blacklist,
|
|
||||||
createCommandExecutingSelector(commandNames.CLEAR_BLACKLIST),
|
|
||||||
(blacklist, isClearingBlacklistExecuting) => {
|
|
||||||
return {
|
|
||||||
isClearingBlacklistExecuting,
|
|
||||||
...blacklist
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const mapDispatchToProps = {
|
|
||||||
...blacklistActions,
|
|
||||||
executeCommand
|
|
||||||
};
|
|
||||||
|
|
||||||
class BlacklistConnector extends Component {
|
|
||||||
|
|
||||||
//
|
|
||||||
// Lifecycle
|
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
const {
|
|
||||||
useCurrentPage,
|
|
||||||
fetchBlacklist,
|
|
||||||
gotoBlacklistFirstPage
|
|
||||||
} = this.props;
|
|
||||||
|
|
||||||
registerPagePopulator(this.repopulate);
|
|
||||||
|
|
||||||
if (useCurrentPage) {
|
|
||||||
fetchBlacklist();
|
|
||||||
} else {
|
|
||||||
gotoBlacklistFirstPage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
|
||||||
if (prevProps.isClearingBlacklistExecuting && !this.props.isClearingBlacklistExecuting) {
|
|
||||||
this.props.gotoBlacklistFirstPage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
this.props.clearBlacklist();
|
|
||||||
unregisterPagePopulator(this.repopulate);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Control
|
|
||||||
|
|
||||||
repopulate = () => {
|
|
||||||
this.props.fetchBlacklist();
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Listeners
|
|
||||||
|
|
||||||
onFirstPagePress = () => {
|
|
||||||
this.props.gotoBlacklistFirstPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
onPreviousPagePress = () => {
|
|
||||||
this.props.gotoBlacklistPreviousPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
onNextPagePress = () => {
|
|
||||||
this.props.gotoBlacklistNextPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
onLastPagePress = () => {
|
|
||||||
this.props.gotoBlacklistLastPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
onPageSelect = (page) => {
|
|
||||||
this.props.gotoBlacklistPage({ page });
|
|
||||||
}
|
|
||||||
|
|
||||||
onRemoveSelected = (ids) => {
|
|
||||||
this.props.removeBlacklistItems({ ids });
|
|
||||||
}
|
|
||||||
|
|
||||||
onSortPress = (sortKey) => {
|
|
||||||
this.props.setBlacklistSort({ sortKey });
|
|
||||||
}
|
|
||||||
|
|
||||||
onTableOptionChange = (payload) => {
|
|
||||||
this.props.setBlacklistTableOption(payload);
|
|
||||||
|
|
||||||
if (payload.pageSize) {
|
|
||||||
this.props.gotoBlacklistFirstPage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onClearBlacklistPress = () => {
|
|
||||||
this.props.executeCommand({ name: commandNames.CLEAR_BLACKLIST });
|
|
||||||
}
|
|
||||||
|
|
||||||
onTableOptionChange = (payload) => {
|
|
||||||
this.props.setBlacklistTableOption(payload);
|
|
||||||
|
|
||||||
if (payload.pageSize) {
|
|
||||||
this.props.gotoBlacklistFirstPage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Render
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return (
|
|
||||||
<Blacklist
|
|
||||||
onFirstPagePress={this.onFirstPagePress}
|
|
||||||
onPreviousPagePress={this.onPreviousPagePress}
|
|
||||||
onNextPagePress={this.onNextPagePress}
|
|
||||||
onLastPagePress={this.onLastPagePress}
|
|
||||||
onPageSelect={this.onPageSelect}
|
|
||||||
onRemoveSelected={this.onRemoveSelected}
|
|
||||||
onSortPress={this.onSortPress}
|
|
||||||
onTableOptionChange={this.onTableOptionChange}
|
|
||||||
onClearBlacklistPress={this.onClearBlacklistPress}
|
|
||||||
{...this.props}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BlacklistConnector.propTypes = {
|
|
||||||
useCurrentPage: PropTypes.bool.isRequired,
|
|
||||||
isClearingBlacklistExecuting: PropTypes.bool.isRequired,
|
|
||||||
items: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
||||||
fetchBlacklist: PropTypes.func.isRequired,
|
|
||||||
gotoBlacklistFirstPage: PropTypes.func.isRequired,
|
|
||||||
gotoBlacklistPreviousPage: PropTypes.func.isRequired,
|
|
||||||
gotoBlacklistNextPage: PropTypes.func.isRequired,
|
|
||||||
gotoBlacklistLastPage: PropTypes.func.isRequired,
|
|
||||||
gotoBlacklistPage: PropTypes.func.isRequired,
|
|
||||||
removeBlacklistItems: PropTypes.func.isRequired,
|
|
||||||
setBlacklistSort: PropTypes.func.isRequired,
|
|
||||||
setBlacklistTableOption: PropTypes.func.isRequired,
|
|
||||||
clearBlacklist: PropTypes.func.isRequired,
|
|
||||||
executeCommand: PropTypes.func.isRequired
|
|
||||||
};
|
|
||||||
|
|
||||||
export default withCurrentPage(
|
|
||||||
connect(createMapStateToProps, mapDispatchToProps)(BlacklistConnector)
|
|
||||||
);
|
|
@ -0,0 +1,152 @@
|
|||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { createSelector } from 'reselect';
|
||||||
|
import * as commandNames from 'Commands/commandNames';
|
||||||
|
import withCurrentPage from 'Components/withCurrentPage';
|
||||||
|
import * as blocklistActions from 'Store/Actions/blocklistActions';
|
||||||
|
import { executeCommand } from 'Store/Actions/commandActions';
|
||||||
|
import createCommandExecutingSelector from 'Store/Selectors/createCommandExecutingSelector';
|
||||||
|
import { registerPagePopulator, unregisterPagePopulator } from 'Utilities/pagePopulator';
|
||||||
|
import Blocklist from './Blocklist';
|
||||||
|
|
||||||
|
function createMapStateToProps() {
|
||||||
|
return createSelector(
|
||||||
|
(state) => state.blocklist,
|
||||||
|
createCommandExecutingSelector(commandNames.CLEAR_BLOCKLIST),
|
||||||
|
(blocklist, isClearingBlocklistExecuting) => {
|
||||||
|
return {
|
||||||
|
isClearingBlocklistExecuting,
|
||||||
|
...blocklist
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapDispatchToProps = {
|
||||||
|
...blocklistActions,
|
||||||
|
executeCommand
|
||||||
|
};
|
||||||
|
|
||||||
|
class BlocklistConnector extends Component {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Lifecycle
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
const {
|
||||||
|
useCurrentPage,
|
||||||
|
fetchBlocklist,
|
||||||
|
gotoBlocklistFirstPage
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
registerPagePopulator(this.repopulate);
|
||||||
|
|
||||||
|
if (useCurrentPage) {
|
||||||
|
fetchBlocklist();
|
||||||
|
} else {
|
||||||
|
gotoBlocklistFirstPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps) {
|
||||||
|
if (prevProps.isClearingBlocklistExecuting && !this.props.isClearingBlocklistExecuting) {
|
||||||
|
this.props.gotoBlocklistFirstPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
this.props.clearBlocklist();
|
||||||
|
unregisterPagePopulator(this.repopulate);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Control
|
||||||
|
|
||||||
|
repopulate = () => {
|
||||||
|
this.props.fetchBlocklist();
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// Listeners
|
||||||
|
|
||||||
|
onFirstPagePress = () => {
|
||||||
|
this.props.gotoBlocklistFirstPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
onPreviousPagePress = () => {
|
||||||
|
this.props.gotoBlocklistPreviousPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
onNextPagePress = () => {
|
||||||
|
this.props.gotoBlocklistNextPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
onLastPagePress = () => {
|
||||||
|
this.props.gotoBlocklistLastPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
onPageSelect = (page) => {
|
||||||
|
this.props.gotoBlocklistPage({ page });
|
||||||
|
}
|
||||||
|
|
||||||
|
onRemoveSelected = (ids) => {
|
||||||
|
this.props.removeBlocklistItems({ ids });
|
||||||
|
}
|
||||||
|
|
||||||
|
onSortPress = (sortKey) => {
|
||||||
|
this.props.setBlocklistSort({ sortKey });
|
||||||
|
}
|
||||||
|
|
||||||
|
onTableOptionChange = (payload) => {
|
||||||
|
this.props.setBlocklistTableOption(payload);
|
||||||
|
|
||||||
|
if (payload.pageSize) {
|
||||||
|
this.props.gotoBlocklistFirstPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onClearBlocklistPress = () => {
|
||||||
|
this.props.executeCommand({ name: commandNames.CLEAR_BLOCKLIST });
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Render
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Blocklist
|
||||||
|
onFirstPagePress={this.onFirstPagePress}
|
||||||
|
onPreviousPagePress={this.onPreviousPagePress}
|
||||||
|
onNextPagePress={this.onNextPagePress}
|
||||||
|
onLastPagePress={this.onLastPagePress}
|
||||||
|
onPageSelect={this.onPageSelect}
|
||||||
|
onRemoveSelected={this.onRemoveSelected}
|
||||||
|
onSortPress={this.onSortPress}
|
||||||
|
onTableOptionChange={this.onTableOptionChange}
|
||||||
|
onClearBlocklistPress={this.onClearBlocklistPress}
|
||||||
|
{...this.props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BlocklistConnector.propTypes = {
|
||||||
|
useCurrentPage: PropTypes.bool.isRequired,
|
||||||
|
isClearingBlocklistExecuting: PropTypes.bool.isRequired,
|
||||||
|
items: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||||
|
fetchBlocklist: PropTypes.func.isRequired,
|
||||||
|
gotoBlocklistFirstPage: PropTypes.func.isRequired,
|
||||||
|
gotoBlocklistPreviousPage: PropTypes.func.isRequired,
|
||||||
|
gotoBlocklistNextPage: PropTypes.func.isRequired,
|
||||||
|
gotoBlocklistLastPage: PropTypes.func.isRequired,
|
||||||
|
gotoBlocklistPage: PropTypes.func.isRequired,
|
||||||
|
removeBlocklistItems: PropTypes.func.isRequired,
|
||||||
|
setBlocklistSort: PropTypes.func.isRequired,
|
||||||
|
setBlocklistTableOption: PropTypes.func.isRequired,
|
||||||
|
clearBlocklist: PropTypes.func.isRequired,
|
||||||
|
executeCommand: PropTypes.func.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
export default withCurrentPage(
|
||||||
|
connect(createMapStateToProps, mapDispatchToProps)(BlocklistConnector)
|
||||||
|
);
|
@ -0,0 +1,5 @@
|
|||||||
|
import migrateBlacklistToBlocklist from './migrateBlacklistToBlocklist';
|
||||||
|
|
||||||
|
export default function migrate(persistedState) {
|
||||||
|
migrateBlacklistToBlocklist(persistedState);
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
import _, { get } from 'lodash';
|
||||||
|
|
||||||
|
export default function migrateBlacklistToBlocklist(persistedState) {
|
||||||
|
const blocklist = get(persistedState, 'blacklist');
|
||||||
|
|
||||||
|
if (!blocklist) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
persistedState.blocklist = blocklist;
|
||||||
|
_.remove(persistedState, 'blacklist');
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
using FluentMigrator;
|
||||||
|
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Datastore.Migration
|
||||||
|
{
|
||||||
|
[Migration(197)]
|
||||||
|
public class rename_blacklist_to_blocklist : NzbDroneMigrationBase
|
||||||
|
{
|
||||||
|
protected override void MainDbUpgrade()
|
||||||
|
{
|
||||||
|
Rename.Table("Blacklist").To("Blocklist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,48 +0,0 @@
|
|||||||
using FluentAssertions;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using Radarr.Api.V3.Movies;
|
|
||||||
|
|
||||||
namespace NzbDrone.Integration.Test.ApiTests
|
|
||||||
{
|
|
||||||
[TestFixture]
|
|
||||||
public class BlacklistFixture : IntegrationTest
|
|
||||||
{
|
|
||||||
private MovieResource _movie;
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
[Ignore("Adding to blacklist not supported")]
|
|
||||||
public void should_be_able_to_add_to_blacklist()
|
|
||||||
{
|
|
||||||
_movie = EnsureMovie(11, "The Blacklist");
|
|
||||||
|
|
||||||
Blacklist.Post(new Radarr.Api.V3.Blacklist.BlacklistResource
|
|
||||||
{
|
|
||||||
MovieId = _movie.Id,
|
|
||||||
SourceTitle = "Blacklist.S01E01.Brought.To.You.By-BoomBoxHD"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
[Ignore("Adding to blacklist not supported")]
|
|
||||||
public void should_be_able_to_get_all_blacklisted()
|
|
||||||
{
|
|
||||||
var result = Blacklist.GetPaged(0, 1000, "date", "desc");
|
|
||||||
|
|
||||||
result.Should().NotBeNull();
|
|
||||||
result.TotalRecords.Should().Be(1);
|
|
||||||
result.Records.Should().NotBeNullOrEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
[Ignore("Adding to blacklist not supported")]
|
|
||||||
public void should_be_able_to_remove_from_blacklist()
|
|
||||||
{
|
|
||||||
Blacklist.Delete(1);
|
|
||||||
|
|
||||||
var result = Blacklist.GetPaged(0, 1000, "date", "desc");
|
|
||||||
|
|
||||||
result.Should().NotBeNull();
|
|
||||||
result.TotalRecords.Should().Be(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,48 @@
|
|||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using Radarr.Api.V3.Movies;
|
||||||
|
|
||||||
|
namespace NzbDrone.Integration.Test.ApiTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class BlocklistFixture : IntegrationTest
|
||||||
|
{
|
||||||
|
private MovieResource _movie;
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[Ignore("Adding to blocklist not supported")]
|
||||||
|
public void should_be_able_to_add_to_blocklist()
|
||||||
|
{
|
||||||
|
_movie = EnsureMovie(11, "The Blocklist");
|
||||||
|
|
||||||
|
Blocklist.Post(new Radarr.Api.V3.Blocklist.BlocklistResource
|
||||||
|
{
|
||||||
|
MovieId = _movie.Id,
|
||||||
|
SourceTitle = "Blocklist.S01E01.Brought.To.You.By-BoomBoxHD"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[Ignore("Adding to blocklist not supported")]
|
||||||
|
public void should_be_able_to_get_all_blocklisted()
|
||||||
|
{
|
||||||
|
var result = Blocklist.GetPaged(0, 1000, "date", "desc");
|
||||||
|
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.TotalRecords.Should().Be(1);
|
||||||
|
result.Records.Should().NotBeNullOrEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[Ignore("Adding to blocklist not supported")]
|
||||||
|
public void should_be_able_to_remove_from_blocklist()
|
||||||
|
{
|
||||||
|
Blocklist.Delete(1);
|
||||||
|
|
||||||
|
var result = Blocklist.GetPaged(0, 1000, "date", "desc");
|
||||||
|
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.TotalRecords.Should().Be(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,66 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using NzbDrone.Core.Blacklisting;
|
|
||||||
using NzbDrone.Core.CustomFormats;
|
|
||||||
using NzbDrone.Core.Datastore;
|
|
||||||
using Radarr.Http;
|
|
||||||
using Radarr.Http.Extensions;
|
|
||||||
using Radarr.Http.REST;
|
|
||||||
|
|
||||||
namespace Radarr.Api.V3.Blacklist
|
|
||||||
{
|
|
||||||
public class BlacklistModule : RadarrRestModule<BlacklistResource>
|
|
||||||
{
|
|
||||||
private readonly IBlacklistService _blacklistService;
|
|
||||||
private readonly ICustomFormatCalculationService _formatCalculator;
|
|
||||||
|
|
||||||
public BlacklistModule(IBlacklistService blacklistService,
|
|
||||||
ICustomFormatCalculationService formatCalculator)
|
|
||||||
{
|
|
||||||
_blacklistService = blacklistService;
|
|
||||||
_formatCalculator = formatCalculator;
|
|
||||||
|
|
||||||
GetResourcePaged = GetBlacklist;
|
|
||||||
DeleteResource = DeleteBlacklist;
|
|
||||||
|
|
||||||
Get("/movie", x => GetMovieBlacklist());
|
|
||||||
Delete("/bulk", x => Remove());
|
|
||||||
}
|
|
||||||
|
|
||||||
private PagingResource<BlacklistResource> GetBlacklist(PagingResource<BlacklistResource> pagingResource)
|
|
||||||
{
|
|
||||||
var pagingSpec = pagingResource.MapToPagingSpec<BlacklistResource, NzbDrone.Core.Blacklisting.Blacklist>("date", SortDirection.Descending);
|
|
||||||
|
|
||||||
return ApplyToPage(_blacklistService.Paged, pagingSpec, (blacklist) => BlacklistResourceMapper.MapToResource(blacklist, _formatCalculator));
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<BlacklistResource> GetMovieBlacklist()
|
|
||||||
{
|
|
||||||
var queryMovieId = Request.Query.MovieId;
|
|
||||||
|
|
||||||
if (!queryMovieId.HasValue)
|
|
||||||
{
|
|
||||||
throw new BadRequestException("movieId is missing");
|
|
||||||
}
|
|
||||||
|
|
||||||
int movieId = Convert.ToInt32(queryMovieId.Value);
|
|
||||||
|
|
||||||
return _blacklistService.GetByMovieId(movieId).Select(h => BlacklistResourceMapper.MapToResource(h, _formatCalculator)).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DeleteBlacklist(int id)
|
|
||||||
{
|
|
||||||
_blacklistService.Delete(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
private object Remove()
|
|
||||||
{
|
|
||||||
var resource = Request.Body.FromJson<BlacklistBulkResource>();
|
|
||||||
|
|
||||||
_blacklistService.Delete(resource.Ids);
|
|
||||||
|
|
||||||
return new object();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Radarr.Api.V3.Blacklist
|
namespace Radarr.Api.V3.Blocklist
|
||||||
{
|
{
|
||||||
public class BlacklistBulkResource
|
public class BlocklistBulkResource
|
||||||
{
|
{
|
||||||
public List<int> Ids { get; set; }
|
public List<int> Ids { get; set; }
|
||||||
}
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using NzbDrone.Core.Blocklisting;
|
||||||
|
using NzbDrone.Core.CustomFormats;
|
||||||
|
using NzbDrone.Core.Datastore;
|
||||||
|
using Radarr.Http;
|
||||||
|
using Radarr.Http.Extensions;
|
||||||
|
using Radarr.Http.REST;
|
||||||
|
|
||||||
|
namespace Radarr.Api.V3.Blocklist
|
||||||
|
{
|
||||||
|
public class BlocklistModule : RadarrRestModule<BlocklistResource>
|
||||||
|
{
|
||||||
|
private readonly IBlocklistService _blocklistService;
|
||||||
|
private readonly ICustomFormatCalculationService _formatCalculator;
|
||||||
|
|
||||||
|
public BlocklistModule(IBlocklistService blocklistService,
|
||||||
|
ICustomFormatCalculationService formatCalculator)
|
||||||
|
{
|
||||||
|
_blocklistService = blocklistService;
|
||||||
|
_formatCalculator = formatCalculator;
|
||||||
|
|
||||||
|
GetResourcePaged = GetBlocklist;
|
||||||
|
DeleteResource = DeleteBlocklist;
|
||||||
|
|
||||||
|
Get("/movie", x => GetMovieBlocklist());
|
||||||
|
Delete("/bulk", x => Remove());
|
||||||
|
}
|
||||||
|
|
||||||
|
private PagingResource<BlocklistResource> GetBlocklist(PagingResource<BlocklistResource> pagingResource)
|
||||||
|
{
|
||||||
|
var pagingSpec = pagingResource.MapToPagingSpec<BlocklistResource, NzbDrone.Core.Blocklisting.Blocklist>("date", SortDirection.Descending);
|
||||||
|
|
||||||
|
return ApplyToPage(_blocklistService.Paged, pagingSpec, (blocklist) => BlocklistResourceMapper.MapToResource(blocklist, _formatCalculator));
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<BlocklistResource> GetMovieBlocklist()
|
||||||
|
{
|
||||||
|
var queryMovieId = Request.Query.MovieId;
|
||||||
|
|
||||||
|
if (!queryMovieId.HasValue)
|
||||||
|
{
|
||||||
|
throw new BadRequestException("movieId is missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
int movieId = Convert.ToInt32(queryMovieId.Value);
|
||||||
|
|
||||||
|
return _blocklistService.GetByMovieId(movieId).Select(h => BlocklistResourceMapper.MapToResource(h, _formatCalculator)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DeleteBlocklist(int id)
|
||||||
|
{
|
||||||
|
_blocklistService.Delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private object Remove()
|
||||||
|
{
|
||||||
|
var resource = Request.Body.FromJson<BlocklistBulkResource>();
|
||||||
|
|
||||||
|
_blocklistService.Delete(resource.Ids);
|
||||||
|
|
||||||
|
return new object();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue