mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-10 23:33:38 -07:00
New: Update Nancy to 2.0
This commit is contained in:
parent
425bd8964f
commit
17c9fc419c
44 changed files with 266 additions and 266 deletions
|
@ -6,6 +6,7 @@ using Nancy;
|
|||
using NzbDrone.Core.Datastore;
|
||||
using Lidarr.Http.Extensions;
|
||||
using Newtonsoft.Json;
|
||||
using Nancy.Responses.Negotiation;
|
||||
|
||||
namespace Lidarr.Http.REST
|
||||
{
|
||||
|
@ -72,13 +73,13 @@ namespace Lidarr.Http.REST
|
|||
set
|
||||
{
|
||||
_deleteResource = value;
|
||||
Delete[ID_ROUTE] = options =>
|
||||
Delete(ID_ROUTE, options =>
|
||||
{
|
||||
ValidateId(options.Id);
|
||||
DeleteResource((int)options.Id);
|
||||
|
||||
return new object().AsResponse();
|
||||
};
|
||||
return new object();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,7 +89,7 @@ namespace Lidarr.Http.REST
|
|||
set
|
||||
{
|
||||
_getResourceById = value;
|
||||
Get[ID_ROUTE] = options =>
|
||||
Get(ID_ROUTE, options =>
|
||||
{
|
||||
ValidateId(options.Id);
|
||||
try
|
||||
|
@ -100,13 +101,13 @@ namespace Lidarr.Http.REST
|
|||
return new NotFoundResponse();
|
||||
}
|
||||
|
||||
return resource.AsResponse();
|
||||
return resource;
|
||||
}
|
||||
catch (ModelNotFoundException)
|
||||
{
|
||||
return new NotFoundResponse();
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,11 +118,11 @@ namespace Lidarr.Http.REST
|
|||
{
|
||||
_getResourceAll = value;
|
||||
|
||||
Get[ROOT_ROUTE] = options =>
|
||||
Get(ROOT_ROUTE, options =>
|
||||
{
|
||||
var resource = GetResourceAll();
|
||||
return resource.AsResponse();
|
||||
};
|
||||
return resource;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,11 +133,11 @@ namespace Lidarr.Http.REST
|
|||
{
|
||||
_getResourcePaged = value;
|
||||
|
||||
Get[ROOT_ROUTE] = options =>
|
||||
Get(ROOT_ROUTE, options =>
|
||||
{
|
||||
var resource = GetResourcePaged(ReadPagingResourceFromRequest());
|
||||
return resource.AsResponse();
|
||||
};
|
||||
return resource;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,11 +148,11 @@ namespace Lidarr.Http.REST
|
|||
{
|
||||
_getResourceSingle = value;
|
||||
|
||||
Get[ROOT_ROUTE] = options =>
|
||||
Get(ROOT_ROUTE, options =>
|
||||
{
|
||||
var resource = GetResourceSingle();
|
||||
return resource.AsResponse();
|
||||
};
|
||||
return resource;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,11 +162,11 @@ namespace Lidarr.Http.REST
|
|||
set
|
||||
{
|
||||
_createResource = value;
|
||||
Post[ROOT_ROUTE] = options =>
|
||||
Post(ROOT_ROUTE, options =>
|
||||
{
|
||||
var id = CreateResource(ReadResourceFromRequest());
|
||||
return GetResourceById(id).AsResponse(HttpStatusCode.Created);
|
||||
};
|
||||
return ResponseWithCode(GetResourceById(id), HttpStatusCode.Created);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -176,23 +177,28 @@ namespace Lidarr.Http.REST
|
|||
set
|
||||
{
|
||||
_updateResource = value;
|
||||
Put[ROOT_ROUTE] = options =>
|
||||
Put(ROOT_ROUTE, options =>
|
||||
{
|
||||
var resource = ReadResourceFromRequest();
|
||||
UpdateResource(resource);
|
||||
return GetResourceById(resource.Id).AsResponse(HttpStatusCode.Accepted);
|
||||
};
|
||||
return ResponseWithCode(GetResourceById(resource.Id), HttpStatusCode.Accepted);
|
||||
});
|
||||
|
||||
Put[ID_ROUTE] = options =>
|
||||
Put(ID_ROUTE, options =>
|
||||
{
|
||||
var resource = ReadResourceFromRequest();
|
||||
resource.Id = options.Id;
|
||||
UpdateResource(resource);
|
||||
return GetResourceById(resource.Id).AsResponse(HttpStatusCode.Accepted);
|
||||
};
|
||||
return ResponseWithCode(GetResourceById(resource.Id), HttpStatusCode.Accepted);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected Negotiator ResponseWithCode(object model, HttpStatusCode statusCode)
|
||||
{
|
||||
return Negotiate.WithModel(model).WithStatusCode(statusCode);
|
||||
}
|
||||
|
||||
protected TResource ReadResourceFromRequest(bool skipValidate = false)
|
||||
{
|
||||
var resource = new TResource();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue