New: Use ASP.NET Core instead of Nancy

This commit is contained in:
ta264
2021-03-11 20:56:24 +00:00
parent d348232e0d
commit 58ddbcd77e
158 changed files with 2747 additions and 3544 deletions
@@ -1,27 +1,25 @@
using System.Collections.Generic;
using System.Collections.Generic;
using FluentValidation;
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Core.RemotePathMappings;
using NzbDrone.Core.Validation.Paths;
using NzbDrone.Http.REST.Attributes;
using Readarr.Http;
using Readarr.Http.REST;
namespace Readarr.Api.V1.RemotePathMappings
{
public class RemotePathMappingModule : ReadarrRestModule<RemotePathMappingResource>
[V1ApiController]
public class RemotePathMappingController : RestController<RemotePathMappingResource>
{
private readonly IRemotePathMappingService _remotePathMappingService;
public RemotePathMappingModule(IRemotePathMappingService remotePathMappingService,
public RemotePathMappingController(IRemotePathMappingService remotePathMappingService,
PathExistsValidator pathExistsValidator,
MappedNetworkDriveValidator mappedNetworkDriveValidator)
{
_remotePathMappingService = remotePathMappingService;
GetResourceAll = GetMappings;
GetResourceById = GetMappingById;
CreateResource = CreateMapping;
DeleteResource = DeleteMapping;
UpdateResource = UpdateMapping;
SharedValidator.RuleFor(c => c.Host)
.NotEmpty();
@@ -36,33 +34,37 @@ namespace Readarr.Api.V1.RemotePathMappings
.SetValidator(pathExistsValidator);
}
private RemotePathMappingResource GetMappingById(int id)
public override RemotePathMappingResource GetResourceById(int id)
{
return _remotePathMappingService.Get(id).ToResource();
}
private int CreateMapping(RemotePathMappingResource resource)
[RestPostById]
public ActionResult<RemotePathMappingResource> CreateMapping(RemotePathMappingResource resource)
{
var model = resource.ToModel();
return _remotePathMappingService.Add(model).Id;
return Created(_remotePathMappingService.Add(model).Id);
}
private List<RemotePathMappingResource> GetMappings()
[HttpGet]
public List<RemotePathMappingResource> GetMappings()
{
return _remotePathMappingService.All().ToResource();
}
private void DeleteMapping(int id)
[RestDeleteById]
public void DeleteMapping(int id)
{
_remotePathMappingService.Remove(id);
}
private void UpdateMapping(RemotePathMappingResource resource)
[RestPutById]
public ActionResult<RemotePathMappingResource> UpdateMapping(RemotePathMappingResource resource)
{
var mapping = resource.ToModel();
_remotePathMappingService.Update(mapping);
return Accepted(_remotePathMappingService.Update(mapping));
}
}
}