Skip to content

Commit d6cb19c

Browse files
authored
Merge pull request #33 from IgniteUI/add-remote-paging-capabilities
Update remote paging endpoint
2 parents f657d8d + 4e5d5f9 commit d6cb19c

21 files changed

+638
-44
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Swashbuckle.AspNetCore.Annotations;
2+
3+
namespace NorthwindCRUD.Attributes
4+
{
5+
public class SwaggerPageParameterAttribute : SwaggerParameterAttribute
6+
{
7+
public SwaggerPageParameterAttribute()
8+
: base("The page index of records to fetch. If this parameter is not provided, fetching starts from the beginning (page 0).")
9+
{
10+
}
11+
}
12+
13+
public class SwaggerSizeParameterAttribute : SwaggerParameterAttribute
14+
{
15+
public SwaggerSizeParameterAttribute()
16+
: base("The maximum number of records to fetch per page. If this parameter is not provided, all records are fetched.")
17+
{
18+
}
19+
}
20+
21+
public class SwaggerOrderByParameterAttribute : SwaggerParameterAttribute
22+
{
23+
public SwaggerOrderByParameterAttribute()
24+
: base("A comma-separated list of fields to order the records by, along with the sort direction (e.g., 'field1 asc, field2 desc').")
25+
{
26+
}
27+
}
28+
29+
public class SwaggerSkipParameterAttribute : SwaggerParameterAttribute
30+
{
31+
public SwaggerSkipParameterAttribute()
32+
: base("The number of records to skip before starting to fetch them. If this parameter is not provided, fetching starts from the beginning.")
33+
{
34+
}
35+
}
36+
37+
public class SwaggerTopParameterAttribute : SwaggerParameterAttribute
38+
{
39+
public SwaggerTopParameterAttribute()
40+
: base("The maximum number of records to fetch. If this parameter is not provided, all records are fetched.")
41+
{
42+
}
43+
}
44+
}

NorthwindCRUD/Controllers/CategoriesController.cs

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace NorthwindCRUD.Controllers
66
using NorthwindCRUD.Models.DbModels;
77
using NorthwindCRUD.Models.Dtos;
88
using NorthwindCRUD.Services;
9+
using Swashbuckle.AspNetCore.Annotations;
910

1011
[ApiController]
1112
[Route("[controller]")]
@@ -48,16 +49,19 @@ public ActionResult<CategoryDto[]> GetAll()
4849
/// <param name="top">The maximum number of categories to fetch. If this parameter is not provided, all categories are fetched.</param>
4950
/// <param name="orderBy">A comma-separated list of fields to order the categories by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
5051
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
51-
[HttpGet("GetPagedCategories")]
52-
public ActionResult<PagedResultDto<ProductDto>> GetPagedCategories(int? skip, int? top, string? orderBy)
52+
[HttpGet("GetCategoriesWithSkip")]
53+
public ActionResult<PagedResultDto<CategoryDto>> GetCategoriesWithSkip(
54+
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
55+
[FromQuery][Attributes.SwaggerTopParameter] int? top,
56+
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
5357
{
5458
try
5559
{
56-
// Retrieve all categories
57-
var categories = this.categoryService.GetAll();
60+
// Retrieve categories as Queryable
61+
var categories = this.categoryService.GetAllAsQueryable();
5862

5963
// Get paged data
60-
var pagedResult = pagingService.GetPagedData<CategoryDb, CategoryDto>(categories, skip, top, orderBy);
64+
var pagedResult = pagingService.FetchPagedData<CategoryDb, CategoryDto>(categories, skip, top, null, null, orderBy);
6165

6266
return Ok(pagedResult);
6367
}
@@ -68,6 +72,55 @@ public ActionResult<PagedResultDto<ProductDto>> GetPagedCategories(int? skip, in
6872
}
6973
}
7074

75+
/// <summary>
76+
/// Fetches all categories or a page of categories based on the provided parameters.
77+
/// </summary>
78+
/// <param name="pageIndex">The page index of records to fetch. If this parameter is not provided, fetching starts from the beginning (page 0).</param>
79+
/// <param name="size">The maximum number of records to fetch per page. If this parameter is not provided, all records are fetched.</param>
80+
/// <param name="orderBy">A comma-separated list of fields to order the records by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
81+
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
82+
[HttpGet("GetCategoriesWithPage")]
83+
public ActionResult<PagedResultDto<CategoryDto>> GetCategoriesWithPage(
84+
[FromQuery][Attributes.SwaggerPageParameter] int? pageIndex,
85+
[FromQuery][Attributes.SwaggerSizeParameter] int? size,
86+
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
87+
{
88+
try
89+
{
90+
// Retrieve categories as Queryable
91+
var categories = this.categoryService.GetAllAsQueryable();
92+
93+
// Get paged data
94+
var pagedResult = pagingService.FetchPagedData<CategoryDb, CategoryDto>(categories, null, null, pageIndex, size, orderBy);
95+
96+
return Ok(pagedResult);
97+
}
98+
catch (Exception error)
99+
{
100+
logger.LogError(error.Message);
101+
return StatusCode(500);
102+
}
103+
}
104+
105+
/// <summary>
106+
/// Retrieves the total number of categories.
107+
/// </summary>
108+
/// <returns>Total count of categories as an integer.</returns>
109+
[HttpGet("GetCategoriesCount")]
110+
public ActionResult<CountResultDto> GetCategoriesCount()
111+
{
112+
try
113+
{
114+
var count = categoryService.GetAllAsQueryable().Count();
115+
return new CountResultDto() { Count = count };
116+
}
117+
catch (Exception error)
118+
{
119+
logger.LogError(error.Message);
120+
return StatusCode(500);
121+
}
122+
}
123+
71124
[HttpGet("{id}")]
72125
public ActionResult<CategoryDto> GetById(int id)
73126
{

NorthwindCRUD/Controllers/CustomersController.cs

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using NorthwindCRUD.Models.DbModels;
77
using NorthwindCRUD.Models.Dtos;
88
using NorthwindCRUD.Services;
9+
using Swashbuckle.AspNetCore.Annotations;
910

1011
[ApiController]
1112
[Route("[controller]")]
@@ -48,16 +49,19 @@ public ActionResult<CustomerDto[]> GetAll()
4849
/// <param name="top">The maximum number of customers to fetch. If this parameter is not provided, all customers are fetched.</param>
4950
/// <param name="orderBy">A comma-separated list of fields to order the customers by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
5051
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
51-
[HttpGet("GetPagedCustomers")]
52-
public ActionResult<PagedResultDto<CustomerDto>> GetAllCustomers(int? skip, int? top, string? orderBy)
52+
[HttpGet("GetCustomersWithSkip")]
53+
public ActionResult<PagedResultDto<CustomerDto>> GetCustomersWithSkip(
54+
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
55+
[FromQuery][Attributes.SwaggerTopParameter] int? top,
56+
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
5357
{
5458
try
5559
{
5660
// Retrieve all customers
57-
var customers = this.customerService.GetAll();
61+
var customers = this.customerService.GetAllAsQueryable();
5862

5963
// Get paged data
60-
var pagedResult = pagingService.GetPagedData<CustomerDb, CustomerDto>(customers, skip, top, orderBy);
64+
var pagedResult = pagingService.FetchPagedData<CustomerDb, CustomerDto>(customers, skip, top, null, null, orderBy);
6165

6266
return Ok(pagedResult);
6367
}
@@ -68,6 +72,55 @@ public ActionResult<PagedResultDto<CustomerDto>> GetAllCustomers(int? skip, int?
6872
}
6973
}
7074

75+
/// <summary>
76+
/// Fetches all customers or a page of customers based on the provided parameters.
77+
/// </summary>
78+
/// <param name="pageIndex">The page index of records to fetch. If this parameter is not provided, fetching starts from the beginning (page 0).</param>
79+
/// <param name="size">The maximum number of records to fetch per page. If this parameter is not provided, all records are fetched.</param>
80+
/// <param name="orderBy">A comma-separated list of fields to order the records by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
81+
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
82+
[HttpGet("GetCustomersWithPage")]
83+
public ActionResult<PagedResultDto<CustomerDto>> GetCustomersWithPage(
84+
[FromQuery][Attributes.SwaggerPageParameter] int? pageIndex,
85+
[FromQuery][Attributes.SwaggerSizeParameter] int? size,
86+
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
87+
{
88+
try
89+
{
90+
// Retrieve customers as Queryable
91+
var customers = this.customerService.GetAllAsQueryable();
92+
93+
// Get paged data
94+
var pagedResult = pagingService.FetchPagedData<CustomerDb, CustomerDto>(customers, null, null, pageIndex, size, orderBy);
95+
96+
return Ok(pagedResult);
97+
}
98+
catch (Exception error)
99+
{
100+
logger.LogError(error.Message);
101+
return StatusCode(500);
102+
}
103+
}
104+
105+
/// <summary>
106+
/// Retrieves the total number of customers.
107+
/// </summary>
108+
/// <returns>Total count of customers as an integer.</returns>
109+
[HttpGet("GetCustomersCount")]
110+
public ActionResult<CountResultDto> GetCustomersCount()
111+
{
112+
try
113+
{
114+
var count = customerService.GetAllAsQueryable().Count();
115+
return new CountResultDto() { Count = count };
116+
}
117+
catch (Exception error)
118+
{
119+
logger.LogError(error.Message);
120+
return StatusCode(500);
121+
}
122+
}
123+
71124
[HttpGet("{id}")]
72125
public ActionResult<CustomerDto> GetById(string id)
73126
{

NorthwindCRUD/Controllers/EmployeesController.cs

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using NorthwindCRUD.Models.DbModels;
77
using NorthwindCRUD.Models.Dtos;
88
using NorthwindCRUD.Services;
9+
using Swashbuckle.AspNetCore.Annotations;
910

1011
[ApiController]
1112
[Route("[controller]")]
@@ -50,16 +51,19 @@ public ActionResult<EmployeeDto[]> GetAll()
5051
/// <param name="top">The maximum number of employees to fetch. If this parameter is not provided, all employees are fetched.</param>
5152
/// <param name="orderBy">A comma-separated list of fields to order the employees by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
5253
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
53-
[HttpGet("GetPagedEmployees")]
54-
public ActionResult<PagedResultDto<EmployeeDto>> GetAllEmployees(int? skip, int? top, string? orderBy)
54+
[HttpGet("GetEmployeesWithSkip")]
55+
public ActionResult<PagedResultDto<EmployeeDto>> GetPagedEmployees(
56+
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
57+
[FromQuery][Attributes.SwaggerTopParameter] int? top,
58+
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
5559
{
5660
try
5761
{
58-
// Retrieve all employees
59-
var employees = this.employeeService.GetAll();
62+
// Retrieve all employees as Queryable
63+
var employees = this.employeeService.GetAllAsQueryable();
6064

6165
// Get paged data
62-
var pagedResult = pagingService.GetPagedData<EmployeeDb, EmployeeDto>(employees, skip, top, orderBy);
66+
var pagedResult = pagingService.FetchPagedData<EmployeeDb, EmployeeDto>(employees, skip, top, null, null, orderBy);
6367

6468
return Ok(pagedResult);
6569
}
@@ -70,6 +74,55 @@ public ActionResult<PagedResultDto<EmployeeDto>> GetAllEmployees(int? skip, int?
7074
}
7175
}
7276

77+
/// <summary>
78+
/// Fetches all employees or a page of employees based on the provided parameters.
79+
/// </summary>
80+
/// <param name="pageIndex">The page index of records to fetch. If this parameter is not provided, fetching starts from the beginning (page 0).</param>
81+
/// <param name="size">The maximum number of records to fetch per page. If this parameter is not provided, all records are fetched.</param>
82+
/// <param name="orderBy">A comma-separated list of fields to order the records by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
83+
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
84+
[HttpGet("GetPagedEmployeesWithPage")]
85+
public ActionResult<PagedResultDto<EmployeeDto>> GetPagedEmployeesWithPage(
86+
[FromQuery][Attributes.SwaggerPageParameter] int? pageIndex,
87+
[FromQuery][Attributes.SwaggerSizeParameter] int? size,
88+
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
89+
{
90+
try
91+
{
92+
// Retrieve employees as Queryable
93+
var employees = this.employeeService.GetAllAsQueryable();
94+
95+
// Get paged data
96+
var pagedResult = pagingService.FetchPagedData<EmployeeDb, EmployeeDto>(employees, null, null, pageIndex, size, orderBy);
97+
98+
return Ok(pagedResult);
99+
}
100+
catch (Exception error)
101+
{
102+
logger.LogError(error.Message);
103+
return StatusCode(500);
104+
}
105+
}
106+
107+
/// <summary>
108+
/// Retrieves the total number of employees.
109+
/// </summary>
110+
/// <returns>Total count of employees as an integer.</returns>
111+
[HttpGet("GetEmployeesCount")]
112+
public ActionResult<CountResultDto> GetEmployeesCount()
113+
{
114+
try
115+
{
116+
var count = employeeService.GetAllAsQueryable().Count();
117+
return new CountResultDto() { Count = count };
118+
}
119+
catch (Exception error)
120+
{
121+
logger.LogError(error.Message);
122+
return StatusCode(500);
123+
}
124+
}
125+
73126
[HttpGet("{id}")]
74127
public ActionResult<EmployeeDto> GetById(int id)
75128
{

NorthwindCRUD/Controllers/OrdersController.cs

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Microsoft.AspNetCore.Mvc;
66
using NorthwindCRUD.Models.DbModels;
77
using NorthwindCRUD.Models.Dtos;
8-
using NorthwindCRUD.Models.InputModels;
98
using NorthwindCRUD.Services;
109

1110
[ApiController]
@@ -56,15 +55,18 @@ public ActionResult<OrderDto[]> GetAll()
5655
/// <param name="orderBy">A comma-separated list of fields to order the orders by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
5756
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5857
[HttpGet("GetPagedOrders")]
59-
public ActionResult<PagedResultDto<OrderDto>> GetAllOrders(int? skip, int? top, string? orderBy)
58+
public ActionResult<PagedResultDto<OrderDto>> GetAllOrders(
59+
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
60+
[FromQuery][Attributes.SwaggerTopParameter] int? top,
61+
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
6062
{
6163
try
6264
{
6365
// Retrieve all orders
64-
var orders = this.orderService.GetAll();
66+
var orders = this.orderService.GetAllAsQueryable();
6567

6668
// Get paged data
67-
var pagedResult = pagingService.GetPagedData<OrderDb, OrderDto>(orders, skip, top, orderBy);
69+
var pagedResult = pagingService.FetchPagedData<OrderDb, OrderDto>(orders, skip, top, null, null, orderBy);
6870

6971
return Ok(pagedResult);
7072
}
@@ -75,6 +77,55 @@ public ActionResult<PagedResultDto<OrderDto>> GetAllOrders(int? skip, int? top,
7577
}
7678
}
7779

80+
/// <summary>
81+
/// Fetches all orders or a page of orders based on the provided parameters.
82+
/// </summary>
83+
/// <param name="pageIndex">The page index of records to fetch. If this parameter is not provided, fetching starts from the beginning (page 0).</param>
84+
/// <param name="size">The maximum number of records to fetch per page. If this parameter is not provided, all records are fetched.</param>
85+
/// <param name="orderBy">A comma-separated list of fields to order the records by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
86+
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
87+
[HttpGet("GetPagedOrdersWithPage")]
88+
public ActionResult<PagedResultDto<OrderDto>> GetPagedOrdersWithPage(
89+
[FromQuery][Attributes.SwaggerPageParameter] int? pageIndex,
90+
[FromQuery][Attributes.SwaggerSizeParameter] int? size,
91+
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
92+
{
93+
try
94+
{
95+
// Retrieve orders as Queryable
96+
var orders = this.orderService.GetAllAsQueryable();
97+
98+
// Get paged data
99+
var pagedResult = pagingService.FetchPagedData<OrderDb, OrderDto>(orders, null, null, pageIndex, size, orderBy);
100+
101+
return Ok(pagedResult);
102+
}
103+
catch (Exception error)
104+
{
105+
logger.LogError(error.Message);
106+
return StatusCode(500);
107+
}
108+
}
109+
110+
/// <summary>
111+
/// Retrieves the total number of orders.
112+
/// </summary>
113+
/// <returns>Total count of orders as an integer.</returns>
114+
[HttpGet("GetOrdersCount")]
115+
public ActionResult<CountResultDto> GetOrdersCount()
116+
{
117+
try
118+
{
119+
var count = orderService.GetAllAsQueryable().Count();
120+
return new CountResultDto() { Count = count };
121+
}
122+
catch (Exception error)
123+
{
124+
logger.LogError(error.Message);
125+
return StatusCode(500);
126+
}
127+
}
128+
78129
[HttpGet("{id}")]
79130
public ActionResult<OrderDto> GetById(int id)
80131
{

0 commit comments

Comments
 (0)