mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-08 05:51:47 -07:00
New: Use ASP.NET Core instead of Nancy
This commit is contained in:
parent
fe956f340c
commit
c247d07e84
161 changed files with 2893 additions and 3665 deletions
|
@ -0,0 +1,70 @@
|
|||
using System.Collections.Generic;
|
||||
using FluentValidation;
|
||||
using Lidarr.Http;
|
||||
using Lidarr.Http.REST;
|
||||
using Lidarr.Http.REST.Attributes;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.RemotePathMappings;
|
||||
using NzbDrone.Core.Validation.Paths;
|
||||
|
||||
namespace Lidarr.Api.V1.RemotePathMappings
|
||||
{
|
||||
[V1ApiController]
|
||||
public class RemotePathMappingController : RestController<RemotePathMappingResource>
|
||||
{
|
||||
private readonly IRemotePathMappingService _remotePathMappingService;
|
||||
|
||||
public RemotePathMappingController(IRemotePathMappingService remotePathMappingService,
|
||||
PathExistsValidator pathExistsValidator,
|
||||
MappedNetworkDriveValidator mappedNetworkDriveValidator)
|
||||
{
|
||||
_remotePathMappingService = remotePathMappingService;
|
||||
|
||||
SharedValidator.RuleFor(c => c.Host)
|
||||
.NotEmpty();
|
||||
|
||||
// We cannot use IsValidPath here, because it's a remote path, possibly other OS.
|
||||
SharedValidator.RuleFor(c => c.RemotePath)
|
||||
.NotEmpty();
|
||||
|
||||
SharedValidator.RuleFor(c => c.LocalPath)
|
||||
.Cascade(CascadeMode.StopOnFirstFailure)
|
||||
.IsValidPath()
|
||||
.SetValidator(mappedNetworkDriveValidator)
|
||||
.SetValidator(pathExistsValidator);
|
||||
}
|
||||
|
||||
public override RemotePathMappingResource GetResourceById(int id)
|
||||
{
|
||||
return _remotePathMappingService.Get(id).ToResource();
|
||||
}
|
||||
|
||||
[RestPostById]
|
||||
public ActionResult<RemotePathMappingResource> CreateMapping(RemotePathMappingResource resource)
|
||||
{
|
||||
var model = resource.ToModel();
|
||||
|
||||
return Created(_remotePathMappingService.Add(model).Id);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<RemotePathMappingResource> GetMappings()
|
||||
{
|
||||
return _remotePathMappingService.All().ToResource();
|
||||
}
|
||||
|
||||
[RestDeleteById]
|
||||
public void DeleteMapping(int id)
|
||||
{
|
||||
_remotePathMappingService.Remove(id);
|
||||
}
|
||||
|
||||
[RestPutById]
|
||||
public ActionResult<RemotePathMappingResource> UpdateMapping(RemotePathMappingResource resource)
|
||||
{
|
||||
var mapping = resource.ToModel();
|
||||
|
||||
return Accepted(_remotePathMappingService.Update(mapping));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue