mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-27 22:56:45 -04:00
New: Use ASP.NET Core instead of Nancy
This commit is contained in:
+18
-16
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user