Skip to content

Commit 9869f85

Browse files
committed
Code improvements and param descriptions
1 parent f04b47b commit 9869f85

19 files changed

+157
-35
lines changed

NorthwindCRUD/Controllers/CategoriesController.cs

Lines changed: 8 additions & 4 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]")]
@@ -49,15 +50,18 @@ public ActionResult<CategoryDto[]> GetAll()
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>
5152
[HttpGet("GetPagedCategories")]
52-
public ActionResult<PagedResultDto<ProductDto>> GetPagedCategories(int? skip, int? top, string? orderBy)
53+
public ActionResult<PagedResultDto<ProductDto>> GetPagedCategories(
54+
[FromQuery][SwaggerParameter("The number of records to skip before starting to fetch the categories. If this parameter is not provided, fetching starts from the beginning.")] int? skip,
55+
[FromQuery][SwaggerParameter("The maximum number of categories to fetch. If this parameter is not provided, all categories are fetched.")] int? top,
56+
[FromQuery][SwaggerParameter("A comma-separated list of fields to order the categories by, along with the sort direction (e.g., 'field1 asc, field2 desc').")] 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.FetchPagedDataWithSkip<CategoryDb, CategoryDto>(categories, skip, top, orderBy);
6165

6266
return Ok(pagedResult);
6367
}

NorthwindCRUD/Controllers/CustomersController.cs

Lines changed: 7 additions & 3 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]")]
@@ -49,15 +50,18 @@ public ActionResult<CustomerDto[]> GetAll()
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>
5152
[HttpGet("GetPagedCustomers")]
52-
public ActionResult<PagedResultDto<CustomerDto>> GetAllCustomers(int? skip, int? top, string? orderBy)
53+
public ActionResult<PagedResultDto<CustomerDto>> GetAllCustomers(
54+
[FromQuery][SwaggerParameter("The number of records to skip before starting to fetch the customers. If this parameter is not provided, fetching starts from the beginning.")] int? skip,
55+
[FromQuery][SwaggerParameter("The maximum number of customers to fetch. If this parameter is not provided, all customers are fetched.")] int? top,
56+
[FromQuery][SwaggerParameter("A comma-separated list of fields to order the customers by, along with the sort direction (e.g., 'field1 asc, field2 desc').")] 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.FetchPagedDataWithSkip<CustomerDb, CustomerDto>(customers, skip, top, orderBy);
6165

6266
return Ok(pagedResult);
6367
}

NorthwindCRUD/Controllers/EmployeesController.cs

Lines changed: 8 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]")]
@@ -51,15 +52,18 @@ public ActionResult<EmployeeDto[]> GetAll()
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>
5354
[HttpGet("GetPagedEmployees")]
54-
public ActionResult<PagedResultDto<EmployeeDto>> GetAllEmployees(int? skip, int? top, string? orderBy)
55+
public ActionResult<PagedResultDto<EmployeeDto>> GetPagedEmployees(
56+
[FromQuery][SwaggerParameter("The number of records to skip before starting to fetch the employees. If this parameter is not provided, fetching starts from the beginning.")] int? skip,
57+
[FromQuery][SwaggerParameter("The maximum number of employees to fetch. If this parameter is not provided, all employees are fetched.")] int? top,
58+
[FromQuery][SwaggerParameter("A comma-separated list of fields to order the employees by, along with the sort direction (e.g., 'field1 asc, field2 desc').")] 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.FetchPagedDataWithSkip<EmployeeDb, EmployeeDto>(employees, skip, top, orderBy);
6367

6468
return Ok(pagedResult);
6569
}

NorthwindCRUD/Controllers/OrdersController.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using NorthwindCRUD.Models.Dtos;
88
using NorthwindCRUD.Models.InputModels;
99
using NorthwindCRUD.Services;
10+
using Swashbuckle.AspNetCore.Annotations;
1011

1112
[ApiController]
1213
[Route("[controller]")]
@@ -56,15 +57,18 @@ public ActionResult<OrderDto[]> GetAll()
5657
/// <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>
5758
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5859
[HttpGet("GetPagedOrders")]
59-
public ActionResult<PagedResultDto<OrderDto>> GetAllOrders(int? skip, int? top, string? orderBy)
60+
public ActionResult<PagedResultDto<OrderDto>> GetAllOrders(
61+
[FromQuery][SwaggerParameter("The number of records to skip before starting to fetch the orders. If this parameter is not provided, fetching starts from the beginning.")] int? skip,
62+
[FromQuery][SwaggerParameter("The maximum number of orders to fetch. If this parameter is not provided, all orders are fetched.")] int? top,
63+
[FromQuery][SwaggerParameter("A comma-separated list of fields to order the orders by, along with the sort direction (e.g., 'field1 asc, field2 desc').")] string? orderBy)
6064
{
6165
try
6266
{
6367
// Retrieve all orders
64-
var orders = this.orderService.GetAll();
68+
var orders = this.orderService.GetAllAsQueryable();
6569

6670
// Get paged data
67-
var pagedResult = pagingService.GetPagedData<OrderDb, OrderDto>(orders, skip, top, orderBy);
71+
var pagedResult = pagingService.FetchPagedDataWithSkip<OrderDb, OrderDto>(orders, skip, top, orderBy);
6872

6973
return Ok(pagedResult);
7074
}

NorthwindCRUD/Controllers/ProductsController.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace NorthwindCRUD.Controllers
88
using NorthwindCRUD.Models.DbModels;
99
using NorthwindCRUD.Models.Dtos;
1010
using NorthwindCRUD.Services;
11+
using Swashbuckle.AspNetCore.Annotations;
1112

1213
[ApiController]
1314
[Route("[controller]")]
@@ -55,15 +56,18 @@ public ActionResult<ProductDto[]> GetAll()
5556
/// <param name="orderBy">A comma-separated list of fields to order the products by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
5657
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5758
[HttpGet("GetPagedProducts")]
58-
public ActionResult<PagedResultDto<ProductDto>> GetAllProducts(int? skip, int? top, string? orderBy)
59+
public ActionResult<PagedResultDto<ProductDto>> GetAllProducts(
60+
[FromQuery][SwaggerParameter("The number of records to skip before starting to fetch the products. If this parameter is not provided, fetching starts from the beginning.")] int? skip,
61+
[FromQuery][SwaggerParameter("The maximum number of products to fetch. If this parameter is not provided, all products are fetched.")] int? top,
62+
[FromQuery][SwaggerParameter("A comma-separated list of fields to order the products by, along with the sort direction (e.g., 'field1 asc, field2 desc').")] string? orderBy)
5963
{
6064
try
6165
{
6266
// Retrieve all products
63-
var products = this.productService.GetAll();
67+
var products = this.productService.GetAllAsQueryable();
6468

6569
// Get paged data
66-
var pagedResult = pagingService.GetPagedData<ProductDb, ProductDto>(products, skip, top, orderBy);
70+
var pagedResult = pagingService.FetchPagedDataWithSkip<ProductDb, ProductDto>(products, skip, top, orderBy);
6771

6872
return Ok(pagedResult);
6973
}

NorthwindCRUD/Controllers/RegionsController.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using NorthwindCRUD.Models.Dtos;
88
using NorthwindCRUD.Models.InputModels;
99
using NorthwindCRUD.Services;
10+
using Swashbuckle.AspNetCore.Annotations;
1011

1112
[ApiController]
1213
[Route("[controller]")]
@@ -50,15 +51,18 @@ public ActionResult<RegionDto[]> GetAll()
5051
/// <param name="orderBy">A comma-separated list of fields to order the regions by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
5152
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5253
[HttpGet("GetPagedRegions")]
53-
public ActionResult<PagedResultDto<RegionDto>> GetAllRegions(int? skip, int? top, string? orderBy)
54+
public ActionResult<PagedResultDto<RegionDto>> GetAllRegions(
55+
[FromQuery][SwaggerParameter("The number of records to skip before starting to fetch the regions. If this parameter is not provided, fetching starts from the beginning.")] int? skip,
56+
[FromQuery][SwaggerParameter("The maximum number of regions to fetch. If this parameter is not provided, all regions are fetched.")] int? top,
57+
[FromQuery][SwaggerParameter("A comma-separated list of fields to order the regions by, along with the sort direction (e.g., 'field1 asc, field2 desc').")] string? orderBy)
5458
{
5559
try
5660
{
5761
// Retrieve all regions
58-
var regions = this.regionService.GetAll();
62+
var regions = this.regionService.GetAllAsQueryable();
5963

6064
// Get paged data
61-
var pagedResult = pagingService.GetPagedData<RegionDb, RegionDto>(regions, skip, top, orderBy);
65+
var pagedResult = pagingService.FetchPagedDataWithSkip<RegionDb, RegionDto>(regions, skip, top, orderBy);
6266

6367
return Ok(pagedResult);
6468
}

NorthwindCRUD/Controllers/ShippersController.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using NorthwindCRUD.Models.Dtos;
88
using NorthwindCRUD.Models.InputModels;
99
using NorthwindCRUD.Services;
10+
using Swashbuckle.AspNetCore.Annotations;
1011

1112
[ApiController]
1213
[Route("[controller]")]
@@ -50,15 +51,18 @@ public ActionResult<ShipperDto[]> GetAll()
5051
/// <param name="orderBy">A comma-separated list of fields to order the shippers by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
5152
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5253
[HttpGet("GetPagedShippers")]
53-
public ActionResult<PagedResultDto<ShipperDto>> GetAllShippers(int? skip, int? top, string? orderBy)
54+
public ActionResult<PagedResultDto<ShipperDto>> GetAllShippers(
55+
[FromQuery][SwaggerParameter("The number of records to skip before starting to fetch the shippers. If this parameter is not provided, fetching starts from the beginning.")] int? skip,
56+
[FromQuery][SwaggerParameter("The maximum number of shippers to fetch. If this parameter is not provided, all shippers are fetched.")] int? top,
57+
[FromQuery][SwaggerParameter("A comma-separated list of fields to order the shippers by, along with the sort direction (e.g., 'field1 asc, field2 desc').")] string? orderBy)
5458
{
5559
try
5660
{
5761
// Retrieve all shippers
58-
var shippers = this.shipperService.GetAll();
62+
var shippers = this.shipperService.GetAllAsQueryable();
5963

6064
// Get paged data
61-
var pagedResult = pagingService.GetPagedData<ShipperDb, ShipperDto>(shippers, skip, top, orderBy);
65+
var pagedResult = pagingService.FetchPagedDataWithSkip<ShipperDb, ShipperDto>(shippers, skip, top, orderBy);
6266

6367
return Ok(pagedResult);
6468
}

NorthwindCRUD/Controllers/SuppliersController.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using NorthwindCRUD.Models.Dtos;
88
using NorthwindCRUD.Models.InputModels;
99
using NorthwindCRUD.Services;
10+
using Swashbuckle.AspNetCore.Annotations;
1011

1112
[ApiController]
1213
[Route("[controller]")]
@@ -50,15 +51,18 @@ public ActionResult<SupplierDto[]> GetAll()
5051
/// <param name="orderBy">A comma-separated list of fields to order the suppliers by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
5152
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5253
[HttpGet("GetPagedSuppliers")]
53-
public ActionResult<PagedResultDto<SupplierDto>> GetAllSuppliers(int? skip, int? top, string? orderBy)
54+
public ActionResult<PagedResultDto<SupplierDto>> GetAllSuppliers(
55+
[FromQuery][SwaggerParameter("The number of records to skip before starting to fetch the suppliers. If this parameter is not provided, fetching starts from the beginning.")] int? skip,
56+
[FromQuery][SwaggerParameter("The maximum number of suppliers to fetch. If this parameter is not provided, all suppliers are fetched.")] int? top,
57+
[FromQuery][SwaggerParameter("A comma-separated list of fields to order the suppliers by, along with the sort direction (e.g., 'field1 asc, field2 desc').")] string? orderBy)
5458
{
5559
try
5660
{
5761
// Retrieve all suppliers
58-
var suppliers = this.supplierService.GetAll();
62+
var suppliers = this.supplierService.GetAllAsQueryable();
5963

6064
// Get paged data
61-
var pagedResult = pagingService.GetPagedData<SupplierDb, SupplierDto>(suppliers, skip, top, orderBy);
65+
var pagedResult = pagingService.FetchPagedDataWithSkip<SupplierDb, SupplierDto>(suppliers, skip, top, orderBy);
6266

6367
return Ok(pagedResult);
6468
}

NorthwindCRUD/Controllers/TerritoriesController.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using NorthwindCRUD.Models.Dtos;
88
using NorthwindCRUD.Models.InputModels;
99
using NorthwindCRUD.Services;
10+
using Swashbuckle.AspNetCore.Annotations;
1011

1112
[ApiController]
1213
[Route("[controller]")]
@@ -52,15 +53,18 @@ public ActionResult<TerritoryDto[]> GetAll()
5253
/// <param name="orderBy">A comma-separated list of fields to order the territories by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
5354
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5455
[HttpGet("GetPagedTerritories")]
55-
public ActionResult<PagedResultDto<TerritoryDto>> GetAllTerritories(int? skip, int? top, string? orderBy)
56+
public ActionResult<PagedResultDto<TerritoryDto>> GetAllTerritories(
57+
[FromQuery][SwaggerParameter("The number of records to skip before starting to fetch the territories. If this parameter is not provided, fetching starts from the beginning.")] int? skip,
58+
[FromQuery][SwaggerParameter("The maximum number of territories to fetch. If this parameter is not provided, all territories are fetched.")] int? top,
59+
[FromQuery][SwaggerParameter("A comma-separated list of fields to order the territories by, along with the sort direction (e.g., 'field1 asc, field2 desc').")] string? orderBy)
5660
{
5761
try
5862
{
5963
// Retrieve all territories
60-
var territories = this.territoryService.GetAll();
64+
var territories = this.territoryService.GetAllAsQueryable();
6165

6266
// Get paged data
63-
var pagedResult = pagingService.GetPagedData<TerritoryDb, TerritoryDto>(territories, skip, top, orderBy);
67+
var pagedResult = pagingService.FetchPagedDataWithSkip<TerritoryDb, TerritoryDto>(territories, skip, top, orderBy);
6468

6569
return Ok(pagedResult);
6670
}

NorthwindCRUD/Services/CategoryService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace NorthwindCRUD.Services
22
{
3+
using Microsoft.EntityFrameworkCore;
34
using NorthwindCRUD.Helpers;
45
using NorthwindCRUD.Models.DbModels;
56

@@ -17,6 +18,11 @@ public CategoryDb[] GetAll()
1718
return this.dataContext.Categories.ToArray();
1819
}
1920

21+
public IQueryable<CategoryDb> GetAllAsQueryable()
22+
{
23+
return this.dataContext.Categories.AsQueryable();
24+
}
25+
2026
public CategoryDb? GetById(int id)
2127
{
2228
return this.dataContext.Categories.FirstOrDefault(c => c.CategoryId == id);

0 commit comments

Comments
 (0)