You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.7 KiB
54 lines
1.7 KiB
using Flurl.Http;
|
|
using Recyclarr.Config.Models;
|
|
using Recyclarr.ServarrApi.Dto;
|
|
using Recyclarr.ServarrApi.Extensions;
|
|
using Recyclarr.ServarrApi.Http;
|
|
|
|
namespace Recyclarr.ServarrApi.Services;
|
|
|
|
internal class QualityProfileService : IQualityProfileService
|
|
{
|
|
private readonly IServiceRequestBuilder _service;
|
|
|
|
public QualityProfileService(IServiceRequestBuilder service)
|
|
{
|
|
_service = service;
|
|
}
|
|
|
|
public async Task<IList<QualityProfileDto>> GetQualityProfiles(IServiceConfiguration config)
|
|
{
|
|
var response = await _service.Request(config, "qualityprofile")
|
|
.GetJsonAsync<IList<QualityProfileDto>>();
|
|
|
|
return response.Select(x => x.ReverseItems()).ToList();
|
|
}
|
|
|
|
public async Task<QualityProfileDto> GetSchema(IServiceConfiguration config)
|
|
{
|
|
var response = await _service.Request(config, "qualityprofile", "schema")
|
|
.GetJsonAsync<QualityProfileDto>();
|
|
|
|
return response.ReverseItems();
|
|
}
|
|
|
|
public async Task UpdateQualityProfile(IServiceConfiguration config, QualityProfileDto profile)
|
|
{
|
|
if (profile.Id is null)
|
|
{
|
|
throw new ArgumentException($"Profile's ID property must not be null: {profile.Name}");
|
|
}
|
|
|
|
await _service.Request(config, "qualityprofile", profile.Id)
|
|
.PutJsonAsync(profile.ReverseItems());
|
|
}
|
|
|
|
public async Task CreateQualityProfile(IServiceConfiguration config, QualityProfileDto profile)
|
|
{
|
|
var response = await _service.Request(config, "qualityprofile")
|
|
.PostJsonAsync(profile.ReverseItems())
|
|
.ReceiveJson<QualityProfileDto>();
|
|
|
|
profile.Id = response.Id;
|
|
}
|
|
}
|