New: Use ASP.NET Core instead of Nancy

This commit is contained in:
ta264 2021-08-04 21:42:40 +01:00 committed by Qstick
parent fe956f340c
commit c247d07e84
161 changed files with 2893 additions and 3665 deletions

View file

@ -1,68 +0,0 @@
using System.Collections.Generic;
using FluentValidation;
using Lidarr.Http;
using NzbDrone.Core.RemotePathMappings;
using NzbDrone.Core.Validation.Paths;
namespace Lidarr.Api.V1.RemotePathMappings
{
public class RemotePathMappingModule : LidarrRestModule<RemotePathMappingResource>
{
private readonly IRemotePathMappingService _remotePathMappingService;
public RemotePathMappingModule(IRemotePathMappingService remotePathMappingService,
PathExistsValidator pathExistsValidator,
MappedNetworkDriveValidator mappedNetworkDriveValidator)
{
_remotePathMappingService = remotePathMappingService;
GetResourceAll = GetMappings;
GetResourceById = GetMappingById;
CreateResource = CreateMapping;
DeleteResource = DeleteMapping;
UpdateResource = UpdateMapping;
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);
}
private RemotePathMappingResource GetMappingById(int id)
{
return _remotePathMappingService.Get(id).ToResource();
}
private int CreateMapping(RemotePathMappingResource resource)
{
var model = resource.ToModel();
return _remotePathMappingService.Add(model).Id;
}
private List<RemotePathMappingResource> GetMappings()
{
return _remotePathMappingService.All().ToResource();
}
private void DeleteMapping(int id)
{
_remotePathMappingService.Remove(id);
}
private void UpdateMapping(RemotePathMappingResource resource)
{
var mapping = resource.ToModel();
_remotePathMappingService.Update(mapping);
}
}
}