mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-04-24 22:07:32 -04:00
parent
e0f6726a3d
commit
3963807c96
5 changed files with 37 additions and 37 deletions
|
@ -7,7 +7,7 @@ using NzbDrone.Core.Messaging.Events;
|
|||
|
||||
namespace NzbDrone.Core.Profiles
|
||||
{
|
||||
public interface IProfileService
|
||||
public interface IAppProfileService
|
||||
{
|
||||
AppSyncProfile Add(AppSyncProfile profile);
|
||||
void Update(AppSyncProfile profile);
|
||||
|
@ -18,7 +18,7 @@ namespace NzbDrone.Core.Profiles
|
|||
AppSyncProfile GetDefaultProfile(string name);
|
||||
}
|
||||
|
||||
public class AppSyncProfileService : IProfileService,
|
||||
public class AppSyncProfileService : IAppProfileService,
|
||||
IHandle<ApplicationStartedEvent>
|
||||
{
|
||||
private readonly IAppProfileRepository _profileRepository;
|
||||
|
|
22
src/NzbDrone.Core/Validation/AppProfileExistsValidator.cs
Normal file
22
src/NzbDrone.Core/Validation/AppProfileExistsValidator.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using FluentValidation.Validators;
|
||||
using NzbDrone.Core.Profiles;
|
||||
|
||||
namespace NzbDrone.Core.Validation
|
||||
{
|
||||
public class AppProfileExistsValidator : PropertyValidator
|
||||
{
|
||||
private readonly IAppProfileService _appProfileService;
|
||||
|
||||
public AppProfileExistsValidator(IAppProfileService appProfileService)
|
||||
{
|
||||
_appProfileService = appProfileService;
|
||||
}
|
||||
|
||||
protected override string GetDefaultMessageTemplate() => "App Profile does not exist";
|
||||
|
||||
protected override bool IsValid(PropertyValidatorContext context)
|
||||
{
|
||||
return context?.PropertyValue == null || _appProfileService.Exists((int)context.PropertyValue);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Validation;
|
||||
using Prowlarr.Http;
|
||||
|
||||
namespace Prowlarr.Api.V1.Indexers
|
||||
|
@ -6,9 +7,12 @@ namespace Prowlarr.Api.V1.Indexers
|
|||
[V1ApiController]
|
||||
public class IndexerController : ProviderControllerBase<IndexerResource, IndexerBulkResource, IIndexer, IndexerDefinition>
|
||||
{
|
||||
public IndexerController(IndexerFactory indexerFactory, IndexerResourceMapper resourceMapper, IndexerBulkResourceMapper bulkResourceMapper)
|
||||
public IndexerController(IndexerFactory indexerFactory, IndexerResourceMapper resourceMapper, IndexerBulkResourceMapper bulkResourceMapper, AppProfileExistsValidator appProfileExistsValidator)
|
||||
: base(indexerFactory, "indexer", resourceMapper, bulkResourceMapper)
|
||||
{
|
||||
Http.Validation.RuleBuilderExtensions.ValidId(SharedValidator.RuleFor(s => s.AppProfileId));
|
||||
|
||||
SharedValidator.RuleFor(c => c.AppProfileId).SetValidator(appProfileExistsValidator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,11 +11,11 @@ namespace Prowlarr.Api.V1.Profiles.App
|
|||
[V1ApiController]
|
||||
public class AppProfileController : RestController<AppProfileResource>
|
||||
{
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly IAppProfileService _appProfileService;
|
||||
|
||||
public AppProfileController(IProfileService profileService)
|
||||
public AppProfileController(IAppProfileService appProfileService)
|
||||
{
|
||||
_profileService = profileService;
|
||||
_appProfileService = appProfileService;
|
||||
SharedValidator.RuleFor(c => c.Name).NotEmpty();
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ namespace Prowlarr.Api.V1.Profiles.App
|
|||
public ActionResult<AppProfileResource> Create(AppProfileResource resource)
|
||||
{
|
||||
var model = resource.ToModel();
|
||||
model = _profileService.Add(model);
|
||||
model = _appProfileService.Add(model);
|
||||
return Created(model.Id);
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ namespace Prowlarr.Api.V1.Profiles.App
|
|||
[Produces("application/json")]
|
||||
public object DeleteProfile(int id)
|
||||
{
|
||||
_profileService.Delete(id);
|
||||
_appProfileService.Delete(id);
|
||||
return new { };
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ namespace Prowlarr.Api.V1.Profiles.App
|
|||
{
|
||||
var model = resource.ToModel();
|
||||
|
||||
_profileService.Update(model);
|
||||
_appProfileService.Update(model);
|
||||
|
||||
return Accepted(model.Id);
|
||||
}
|
||||
|
@ -55,14 +55,14 @@ namespace Prowlarr.Api.V1.Profiles.App
|
|||
[ProducesResponseType(500)]
|
||||
public override AppProfileResource GetResourceById(int id)
|
||||
{
|
||||
return _profileService.Get(id).ToResource();
|
||||
return _appProfileService.Get(id).ToResource();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Produces("application/json")]
|
||||
public List<AppProfileResource> GetAll()
|
||||
{
|
||||
return _profileService.All().ToResource();
|
||||
return _appProfileService.All().ToResource();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Profiles;
|
||||
using Prowlarr.Http;
|
||||
|
||||
namespace Prowlarr.Api.V1.Profiles.App
|
||||
{
|
||||
[V1ApiController("appprofile/schema")]
|
||||
public class QualityProfileSchemaController : Controller
|
||||
{
|
||||
private readonly IProfileService _profileService;
|
||||
|
||||
public QualityProfileSchemaController(IProfileService profileService)
|
||||
{
|
||||
_profileService = profileService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Produces("application/json")]
|
||||
public AppProfileResource GetSchema()
|
||||
{
|
||||
var qualityProfile = _profileService.GetDefaultProfile(string.Empty);
|
||||
|
||||
return qualityProfile.ToResource();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue