Fixed: Quality Definitions Don't Allow Save

pull/2/head
Qstick 5 years ago
parent 066bf1220f
commit 33d012cfc0

@ -11,6 +11,7 @@ namespace NzbDrone.Core.Qualities
public interface IQualityDefinitionService public interface IQualityDefinitionService
{ {
void Update(QualityDefinition qualityDefinition); void Update(QualityDefinition qualityDefinition);
void UpdateMany(List<QualityDefinition> qualityDefinitions);
List<QualityDefinition> All(); List<QualityDefinition> All();
QualityDefinition GetById(int id); QualityDefinition GetById(int id);
QualityDefinition Get(Quality quality); QualityDefinition Get(Quality quality);
@ -41,6 +42,11 @@ namespace NzbDrone.Core.Qualities
_cache.Clear(); _cache.Clear();
} }
public void UpdateMany(List<QualityDefinition> qualityDefinitions)
{
_repo.UpdateMany(qualityDefinitions);
}
public List<QualityDefinition> All() public List<QualityDefinition> All()
{ {
return GetAll().Values.OrderBy(d => d.Weight).ToList(); return GetAll().Values.OrderBy(d => d.Weight).ToList();

@ -1,35 +1,24 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Radarr.Http.REST; using System.Linq;
using NzbDrone.Core.Parser; using Nancy;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
using Radarr.Http; using Radarr.Http;
using Radarr.Http.Extensions;
namespace Radarr.Api.V2.Qualities namespace Radarr.Api.V2.Qualities
{ {
public class QualityDefinitionModule : RadarrRestModule<QualityDefinitionResource> public class QualityDefinitionModule : RadarrRestModule<QualityDefinitionResource>
{ {
private readonly IQualityDefinitionService _qualityDefinitionService; private readonly IQualityDefinitionService _qualityDefinitionService;
private readonly IParsingService _parsingService;
public QualityDefinitionModule(IQualityDefinitionService qualityDefinitionService, IParsingService parsingService) public QualityDefinitionModule(IQualityDefinitionService qualityDefinitionService)
{ {
_qualityDefinitionService = qualityDefinitionService; _qualityDefinitionService = qualityDefinitionService;
_parsingService = parsingService;
GetResourceAll = GetAll; GetResourceAll = GetAll;
GetResourceById = GetById; GetResourceById = GetById;
UpdateResource = Update; UpdateResource = Update;
Put("/update", d => UpdateMany());
CreateResource = Create;
}
private int Create(QualityDefinitionResource qualityDefinitionResource)
{
throw new BadRequestException("Not allowed!");
} }
private void Update(QualityDefinitionResource resource) private void Update(QualityDefinitionResource resource)
@ -47,5 +36,19 @@ namespace Radarr.Api.V2.Qualities
{ {
return _qualityDefinitionService.All().ToResource(); return _qualityDefinitionService.All().ToResource();
} }
private object UpdateMany()
{
//Read from request
var qualityDefinitions = Request.Body.FromJson<List<QualityDefinitionResource>>()
.ToModel()
.ToList();
_qualityDefinitionService.UpdateMany(qualityDefinitions);
return ResponseWithCode(_qualityDefinitionService.All()
.ToResource()
, HttpStatusCode.Accepted);
}
} }
} }

@ -61,5 +61,10 @@ namespace Radarr.Api.V2.Qualities
{ {
return models.Select(ToResource).ToList(); return models.Select(ToResource).ToList();
} }
public static List<QualityDefinition> ToModel(this IEnumerable<QualityDefinitionResource> resources)
{
return resources.Select(ToModel).ToList();
}
} }
} }

Loading…
Cancel
Save