私はこの短いテストコードを実行しました。ただし、他のすべてのルートを無視し、最初のルートにのみヒットします。
http://localhost:55109/api/customers
大丈夫です
http://localhost:55109/api/customers/page/1
動作しません
http://localhost:55109/api/customers/page/1/size/20
動作しません
ページとサイズのパラメータを使用してルートを呼び出すと、次のように表示されます。"Handler for Request not found".
何が間違っているのかわからないのですか?ヒントを投げてください。
[Route("/api/customers", "GET")] //works okay
[Route("/api/customers/page/{Page}", "GET")] //doesn't work
[Route("/api/customers/page/{Page}/size/{PageSize}", "GET")] //doesn't work
public class Customers {
public Customers() { Page = 1; PageSize = 20; } //by default 1st page 20 records
public int Page { get; set; }
public int PageSize { get; set; }
}
//----------------------------------------------------
public class CustomersService : Service {
public ICustomersManager CustomersManager { get; set; }
public dynamic Get(Customers req) {
return new { Customers = CustomersManager.GetCustomers(req) };
}
}
//----------------------------------------------------
public interface ICustomersManager : IBaseManager {
IList<Customer> GetCustomers(Customers req);
}
public class CustomersManager : BaseManager, ICustomersManager {
public IList<Customer> GetCustomers(Customers req) {
if (req.Page < 1) ThrowHttpError(HttpStatusCode.BadRequest, "Bad page number");
if (req.PageSize < 1) ThrowHttpError(HttpStatusCode.BadRequest, "Bad page size number");
var customers = Db.Select<Customer>().Skip((req.Page - 1) * req.PageSize).Take(req.PageSize).ToList();
if (customers.Count <= 0) ThrowHttpError(HttpStatusCode.NotFound, "Data not found");
return customers;
}
}