Skip to content

Commit 007db29

Browse files
committed
Adding the rest of the entities
1 parent b6843a1 commit 007db29

File tree

7 files changed

+212
-7
lines changed

7 files changed

+212
-7
lines changed

NorthwindCRUD/Controllers/CustomersController.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ public class CustomersController : Controller
1313
{
1414
private readonly CustomerService customerService;
1515
private readonly OrderService orderService;
16+
private readonly PagingService pagingService;
1617
private readonly IMapper mapper;
1718
private readonly ILogger<CustomersController> logger;
1819

19-
public CustomersController(CustomerService customerService, OrderService orderService, IMapper mapper, ILogger<CustomersController> logger)
20+
public CustomersController(CustomerService customerService, OrderService orderService, PagingService pagingService, IMapper mapper, ILogger<CustomersController> logger)
2021
{
2122
this.customerService = customerService;
2223
this.orderService = orderService;
24+
this.pagingService = pagingService;
2325
this.mapper = mapper;
2426
this.logger = logger;
2527
}
@@ -39,6 +41,33 @@ public ActionResult<CustomerDto[]> GetAll()
3941
}
4042
}
4143

44+
/// <summary>
45+
/// Fetches all customers or a page of customers based on the provided parameters.
46+
/// </summary>
47+
/// <param name="skip">The number of records to skip before starting to fetch the customers. If this parameter is not provided, fetching starts from the beginning.</param>
48+
/// <param name="top">The maximum number of customers to fetch. If this parameter is not provided, all customers are fetched.</param>
49+
/// <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>
50+
/// <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)
53+
{
54+
try
55+
{
56+
// Retrieve all customers
57+
var customers = this.customerService.GetAll();
58+
59+
// Get paged data
60+
var pagedResult = pagingService.GetPagedData<CustomerDb, CustomerDto>(customers, skip, top, orderBy);
61+
62+
return Ok(pagedResult);
63+
}
64+
catch (Exception error)
65+
{
66+
logger.LogError(error.Message);
67+
return StatusCode(500);
68+
}
69+
}
70+
4271
[HttpGet("{id}")]
4372
public ActionResult<CustomerDto> GetById(string id)
4473
{

NorthwindCRUD/Controllers/EmployeesController.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ public class EmployeesController : Controller
1414
private readonly EmployeeService employeeService;
1515
private readonly EmployeeTerritoryService employeeTerritoryService;
1616
private readonly OrderService ordersService;
17+
private readonly PagingService pagingService;
1718
private readonly IMapper mapper;
1819
private readonly ILogger<EmployeesController> logger;
1920

20-
public EmployeesController(EmployeeService employeeService, EmployeeTerritoryService employeeTerritoryService, OrderService ordersService, IMapper mapper, ILogger<EmployeesController> logger)
21+
public EmployeesController(EmployeeService employeeService, EmployeeTerritoryService employeeTerritoryService, OrderService ordersService, PagingService pagingService, IMapper mapper, ILogger<EmployeesController> logger)
2122
{
2223
this.employeeService = employeeService;
2324
this.employeeTerritoryService = employeeTerritoryService;
25+
this.pagingService = pagingService;
2426
this.ordersService = ordersService;
2527
this.mapper = mapper;
2628
this.logger = logger;
@@ -41,6 +43,34 @@ public ActionResult<EmployeeDto[]> GetAll()
4143
}
4244
}
4345

46+
/// <summary>
47+
/// Fetches all employees or a page of employees based on the provided parameters.
48+
/// </summary>
49+
/// <param name="skip">The number of records to skip before starting to fetch the employees. If this parameter is not provided, fetching starts from the beginning.</param>
50+
/// <param name="top">The maximum number of employees to fetch. If this parameter is not provided, all employees are fetched.</param>
51+
/// <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>
52+
/// <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)
55+
{
56+
try
57+
{
58+
// Retrieve all employees
59+
var employees = this.employeeService.GetAll();
60+
61+
// Get paged data
62+
var pagedResult = pagingService.GetPagedData<EmployeeDb, EmployeeDto>(employees, skip, top, orderBy);
63+
64+
return Ok(pagedResult);
65+
}
66+
catch (Exception error)
67+
{
68+
logger.LogError(error.Message);
69+
return StatusCode(500);
70+
}
71+
}
72+
73+
4474
[HttpGet("{id}")]
4575
public ActionResult<EmployeeDto> GetById(int id)
4676
{

NorthwindCRUD/Controllers/OrdersController.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ public class OrdersController : ControllerBase
1717
private readonly CustomerService customerService;
1818
private readonly ShipperService shipperService;
1919
private readonly ProductService productService;
20+
private readonly PagingService pagingService;
2021
private readonly IMapper mapper;
2122
private readonly ILogger<OrdersController> logger;
2223

23-
public OrdersController(OrderService orderService, EmployeeService employeeService, CustomerService customerService, ShipperService shipperService, ProductService productService, IMapper mapper, ILogger<OrdersController> logger)
24+
public OrdersController(OrderService orderService, EmployeeService employeeService, CustomerService customerService, ShipperService shipperService, ProductService productService, PagingService pagingService, IMapper mapper, ILogger<OrdersController> logger)
2425
{
2526
this.orderService = orderService;
2627
this.employeeService = employeeService;
2728
this.customerService = customerService;
2829
this.shipperService = shipperService;
2930
this.productService = productService;
31+
this.pagingService = pagingService;
3032
this.mapper = mapper;
3133
this.logger = logger;
3234
}
@@ -46,6 +48,34 @@ public ActionResult<OrderDto[]> GetAll()
4648
}
4749
}
4850

51+
/// <summary>
52+
/// Fetches all orders or a page of orders based on the provided parameters.
53+
/// </summary>
54+
/// <param name="skip">The number of records to skip before starting to fetch the orders. If this parameter is not provided, fetching starts from the beginning.</param>
55+
/// <param name="top">The maximum number of orders to fetch. If this parameter is not provided, all orders are fetched.</param>
56+
/// <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>
57+
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
58+
[HttpGet("GetPagedOrders")]
59+
public ActionResult<PagedResultDto<OrderDto>> GetAllOrders(int? skip, int? top, string? orderBy)
60+
{
61+
try
62+
{
63+
// Retrieve all orders
64+
var orders = this.orderService.GetAll();
65+
66+
// Get paged data
67+
var pagedResult = pagingService.GetPagedData<OrderDb, OrderDto>(orders, skip, top, orderBy);
68+
69+
return Ok(pagedResult);
70+
}
71+
catch (Exception error)
72+
{
73+
logger.LogError(error.Message);
74+
return StatusCode(500);
75+
}
76+
}
77+
78+
4979
[HttpGet("{id}")]
5080
public ActionResult<OrderDto> GetById(int id)
5181
{

NorthwindCRUD/Controllers/RegionsController.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ public class RegionsController : ControllerBase
1414
{
1515
private readonly RegionService regionService;
1616
private readonly TerritoryService territoryService;
17+
private readonly PagingService pagingService;
1718
private readonly IMapper mapper;
1819
private readonly ILogger<RegionsController> logger;
1920

20-
public RegionsController(RegionService regionService, TerritoryService territoryService, IMapper mapper, ILogger<RegionsController> logger)
21+
public RegionsController(RegionService regionService, TerritoryService territoryService, PagingService pagingService, IMapper mapper, ILogger<RegionsController> logger)
2122
{
2223
this.regionService = regionService;
2324
this.territoryService = territoryService;
25+
this.pagingService = pagingService;
2426
this.mapper = mapper;
2527
this.logger = logger;
2628
}
@@ -40,6 +42,33 @@ public ActionResult<RegionDto[]> GetAll()
4042
}
4143
}
4244

45+
/// <summary>
46+
/// Fetches all regions or a page of regions based on the provided parameters.
47+
/// </summary>
48+
/// <param name="skip">The number of records to skip before starting to fetch the regions. If this parameter is not provided, fetching starts from the beginning.</param>
49+
/// <param name="top">The maximum number of regions to fetch. If this parameter is not provided, all regions are fetched.</param>
50+
/// <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>
51+
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
52+
[HttpGet("GetPagedRegions")]
53+
public ActionResult<PagedResultDto<RegionDto>> GetAllRegions(int? skip, int? top, string? orderBy)
54+
{
55+
try
56+
{
57+
// Retrieve all regions
58+
var regions = this.regionService.GetAll();
59+
60+
// Get paged data
61+
var pagedResult = pagingService.GetPagedData<RegionDb, RegionDto>(regions, skip, top, orderBy);
62+
63+
return Ok(pagedResult);
64+
}
65+
catch (Exception error)
66+
{
67+
logger.LogError(error.Message);
68+
return StatusCode(500);
69+
}
70+
}
71+
4372
[HttpGet("{id}")]
4473
public ActionResult<RegionDto> GetById(int id)
4574
{

NorthwindCRUD/Controllers/ShippersController.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ public class ShippersController : ControllerBase
1414
{
1515
private readonly ShipperService shipperService;
1616
private readonly OrderService orderService;
17+
private readonly PagingService pagingService;
1718
private readonly IMapper mapper;
1819
private readonly ILogger<ShippersController> logger;
1920

20-
public ShippersController(ShipperService shipperService, OrderService orderService, IMapper mapper, ILogger<ShippersController> logger)
21+
public ShippersController(ShipperService shipperService, OrderService orderService, PagingService pagingService, IMapper mapper, ILogger<ShippersController> logger)
2122
{
2223
this.shipperService = shipperService;
2324
this.orderService = orderService;
25+
this.pagingService = pagingService;
2426
this.mapper = mapper;
2527
this.logger = logger;
2628
}
@@ -40,6 +42,33 @@ public ActionResult<ShipperDto[]> GetAll()
4042
}
4143
}
4244

45+
/// <summary>
46+
/// Fetches all shippers or a page of shippers based on the provided parameters.
47+
/// </summary>
48+
/// <param name="skip">The number of records to skip before starting to fetch the shippers. If this parameter is not provided, fetching starts from the beginning.</param>
49+
/// <param name="top">The maximum number of shippers to fetch. If this parameter is not provided, all shippers are fetched.</param>
50+
/// <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>
51+
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
52+
[HttpGet("GetPagedShippers")]
53+
public ActionResult<PagedResultDto<ShipperDto>> GetAllShippers(int? skip, int? top, string? orderBy)
54+
{
55+
try
56+
{
57+
// Retrieve all shippers
58+
var shippers = this.shipperService.GetAll();
59+
60+
// Get paged data
61+
var pagedResult = pagingService.GetPagedData<ShipperDb, ShipperDto>(shippers, skip, top, orderBy);
62+
63+
return Ok(pagedResult);
64+
}
65+
catch (Exception error)
66+
{
67+
logger.LogError(error.Message);
68+
return StatusCode(500);
69+
}
70+
}
71+
4372
[HttpGet("{id}")]
4473
public ActionResult<ShipperDto> GetById(int id)
4574
{

NorthwindCRUD/Controllers/SuppliersController.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ public class SuppliersController : ControllerBase
1414
{
1515
private readonly SupplierService supplierService;
1616
private readonly ProductService productService;
17+
private readonly PagingService pagingService;
1718
private readonly IMapper mapper;
1819
private readonly ILogger<SuppliersController> logger;
1920

20-
public SuppliersController(SupplierService supplierService, ProductService productService, IMapper mapper, ILogger<SuppliersController> logger)
21+
public SuppliersController(SupplierService supplierService, ProductService productService, PagingService pagingService, IMapper mapper, ILogger<SuppliersController> logger)
2122
{
2223
this.supplierService = supplierService;
2324
this.productService = productService;
25+
this.pagingService = pagingService;
2426
this.mapper = mapper;
2527
this.logger = logger;
2628
}
@@ -40,6 +42,33 @@ public ActionResult<SupplierDto[]> GetAll()
4042
}
4143
}
4244

45+
/// <summary>
46+
/// Fetches all suppliers or a page of suppliers based on the provided parameters.
47+
/// </summary>
48+
/// <param name="skip">The number of records to skip before starting to fetch the suppliers. If this parameter is not provided, fetching starts from the beginning.</param>
49+
/// <param name="top">The maximum number of suppliers to fetch. If this parameter is not provided, all suppliers are fetched.</param>
50+
/// <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>
51+
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
52+
[HttpGet("GetPagedSuppliers")]
53+
public ActionResult<PagedResultDto<SupplierDto>> GetAllSuppliers(int? skip, int? top, string? orderBy)
54+
{
55+
try
56+
{
57+
// Retrieve all suppliers
58+
var suppliers = this.supplierService.GetAll();
59+
60+
// Get paged data
61+
var pagedResult = pagingService.GetPagedData<SupplierDb, SupplierDto>(suppliers, skip, top, orderBy);
62+
63+
return Ok(pagedResult);
64+
}
65+
catch (Exception error)
66+
{
67+
logger.LogError(error.Message);
68+
return StatusCode(500);
69+
}
70+
}
71+
4372
[HttpGet("{id}")]
4473
public ActionResult<SupplierDto> GetById(int id)
4574
{

NorthwindCRUD/Controllers/TerritoriesController.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ public class TerritoriesController : ControllerBase
1515
private readonly TerritoryService territoryService;
1616
private readonly RegionService regionService;
1717
private readonly EmployeeTerritoryService employeeTerritoryService;
18+
private readonly PagingService pagingService;
1819
private readonly IMapper mapper;
1920
private readonly ILogger<TerritoriesController> logger;
2021

21-
public TerritoriesController(TerritoryService territoryService, EmployeeTerritoryService employeeTerritoryService, RegionService regionService, IMapper mapper, ILogger<TerritoriesController> logger)
22+
public TerritoriesController(TerritoryService territoryService, EmployeeTerritoryService employeeTerritoryService, RegionService regionService, PagingService pagingService, IMapper mapper, ILogger<TerritoriesController> logger)
2223
{
2324
this.territoryService = territoryService;
2425
this.regionService = regionService;
2526
this.employeeTerritoryService = employeeTerritoryService;
27+
this.pagingService = pagingService;
2628
this.mapper = mapper;
2729
this.logger = logger;
2830
}
@@ -42,6 +44,33 @@ public ActionResult<TerritoryDto[]> GetAll()
4244
}
4345
}
4446

47+
/// <summary>
48+
/// Fetches all territories or a page of territories based on the provided parameters.
49+
/// </summary>
50+
/// <param name="skip">The number of records to skip before starting to fetch the territories. If this parameter is not provided, fetching starts from the beginning.</param>
51+
/// <param name="top">The maximum number of territories to fetch. If this parameter is not provided, all territories are fetched.</param>
52+
/// <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>
53+
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
54+
[HttpGet("GetPagedTerritories")]
55+
public ActionResult<PagedResultDto<TerritoryDto>> GetAllTerritories(int? skip, int? top, string? orderBy)
56+
{
57+
try
58+
{
59+
// Retrieve all territories
60+
var territories = this.territoryService.GetAll();
61+
62+
// Get paged data
63+
var pagedResult = pagingService.GetPagedData<TerritoryDb, TerritoryDto>(territories, skip, top, orderBy);
64+
65+
return Ok(pagedResult);
66+
}
67+
catch (Exception error)
68+
{
69+
logger.LogError(error.Message);
70+
return StatusCode(500);
71+
}
72+
}
73+
4574
[HttpGet("{id}")]
4675
public ActionResult<TerritoryDto> GetById(string id)
4776
{

0 commit comments

Comments
 (0)