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

@ -1,35 +1,24 @@
using System;
using System.Collections.Generic;
using Radarr.Http.REST;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
using System.Linq;
using Nancy;
using NzbDrone.Core.Qualities;
using Radarr.Http;
using Radarr.Http.Extensions;
namespace Radarr.Api.V2.Qualities
{
public class QualityDefinitionModule : RadarrRestModule<QualityDefinitionResource>
{
private readonly IQualityDefinitionService _qualityDefinitionService;
private readonly IParsingService _parsingService;
public QualityDefinitionModule(IQualityDefinitionService qualityDefinitionService, IParsingService parsingService)
public QualityDefinitionModule(IQualityDefinitionService qualityDefinitionService)
{
_qualityDefinitionService = qualityDefinitionService;
_parsingService = parsingService;
GetResourceAll = GetAll;
GetResourceById = GetById;
UpdateResource = Update;
CreateResource = Create;
}
private int Create(QualityDefinitionResource qualityDefinitionResource)
{
throw new BadRequestException("Not allowed!");
Put("/update", d => UpdateMany());
}
private void Update(QualityDefinitionResource resource)
@ -47,5 +36,19 @@ namespace Radarr.Api.V2.Qualities
{
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();
}
public static List<QualityDefinition> ToModel(this IEnumerable<QualityDefinitionResource> resources)
{
return resources.Select(ToModel).ToList();
}
}
}

Loading…
Cancel
Save