Skip to content

Commit

Permalink
Add extra count methods for all entities and remote Querable thats no…
Browse files Browse the repository at this point in the history
…t needed
  • Loading branch information
zdrawku committed Jul 2, 2024
1 parent 564d3fd commit 57315bf
Show file tree
Hide file tree
Showing 18 changed files with 182 additions and 9 deletions.
19 changes: 19 additions & 0 deletions NorthwindCRUD/Controllers/CategoriesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ public ActionResult<PagedResultDto<CategoryDto>> GetCategoriesWithPage(
}
}

/// <summary>
/// Retrieves the total number of categories.
/// </summary>
/// <returns>Total count of categories as an integer.</returns>
[HttpGet("GetCategoriesCount")]
public ActionResult<int> GetCategoriesCount()
{
try
{
var count = categoryService.GetAllAsQueryable().Count();
return Ok(count);
}
catch (Exception error)
{
logger.LogError(error.Message);
return StatusCode(500);
}
}

[HttpGet("{id}")]
public ActionResult<CategoryDto> GetById(int id)
{
Expand Down
19 changes: 19 additions & 0 deletions NorthwindCRUD/Controllers/CustomersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ public ActionResult<PagedResultDto<CustomerDto>> GetCustomersWithPage(
}
}

/// <summary>
/// Retrieves the total number of customers.
/// </summary>
/// <returns>Total count of customers as an integer.</returns>
[HttpGet("GetCustomersCount")]
public ActionResult<int> GetCustomersCount()
{
try
{
var count = customerService.GetAllAsQueryable().Count();
return Ok(count);
}
catch (Exception error)
{
logger.LogError(error.Message);
return StatusCode(500);
}
}

[HttpGet("{id}")]
public ActionResult<CustomerDto> GetById(string id)
{
Expand Down
21 changes: 21 additions & 0 deletions NorthwindCRUD/Controllers/EmployeesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,27 @@ public ActionResult<PagedResultDto<EmployeeDto>> GetPagedEmployeesWithPage(
}
}

Check failure on line 106 in NorthwindCRUD/Controllers/EmployeesController.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Check failure on line 106 in NorthwindCRUD/Controllers/EmployeesController.cs

View workflow job for this annotation

GitHub Actions / build-and-test


/// <summary>
/// Retrieves the total number of employees.
/// </summary>
/// <returns>Total count of employees as an integer.</returns>
[HttpGet("GetEmployeesCount")]
public ActionResult<int> GetEmployeesCount()
{
try
{
var count = employeeService.GetAllAsQueryable().Count();
return Ok(count);
}
catch (Exception error)
{
logger.LogError(error.Message);
return StatusCode(500);
}
}

Check failure on line 126 in NorthwindCRUD/Controllers/EmployeesController.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Check failure on line 126 in NorthwindCRUD/Controllers/EmployeesController.cs

View workflow job for this annotation

GitHub Actions / build-and-test


[HttpGet("{id}")]
public ActionResult<EmployeeDto> GetById(int id)
{
Expand Down
19 changes: 19 additions & 0 deletions NorthwindCRUD/Controllers/OrdersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,25 @@ public ActionResult<PagedResultDto<OrderDto>> GetPagedOrdersWithPage(
}
}

/// <summary>
/// Retrieves the total number of orders.
/// </summary>
/// <returns>Total count of orders as an integer.</returns>
[HttpGet("GetOrdersCount")]
public ActionResult<int> GetOrdersCount()
{
try
{
var count = orderService.GetAllAsQueryable().Count();
return Ok(count);
}
catch (Exception error)
{
logger.LogError(error.Message);
return StatusCode(500);
}
}

[HttpGet("{id}")]
public ActionResult<OrderDto> GetById(int id)
{
Expand Down
19 changes: 19 additions & 0 deletions NorthwindCRUD/Controllers/ProductsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,25 @@ public ActionResult<PagedResultDto<ProductDto>> GetPagedProductsWithPage(
}
}

/// <summary>
/// Retrieves the total number of products.
/// </summary>
/// <returns>Total count of products as an integer.</returns>
[HttpGet("GetProductsCount")]
public ActionResult<int> GetProductsCount()
{
try
{
var count = productService.GetAllAsQueryable().Count();
return Ok(count);
}
catch (Exception error)
{
logger.LogError(error.Message);
return StatusCode(500);
}
}

[HttpGet("{id}")]
public ActionResult<ProductDto> GetById(int id)
{
Expand Down
19 changes: 19 additions & 0 deletions NorthwindCRUD/Controllers/RegionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,25 @@ public ActionResult<PagedResultDto<RegionDto>> GetPagedRegionsWithPage(
}
}

/// <summary>
/// Retrieves the total number of regions.
/// </summary>
/// <returns>Total count of regions as an integer.</returns>
[HttpGet("GetRegionsCount")]
public ActionResult<int> GetRegionsCount()
{
try
{
var count = regionService.GetAllAsQueryable().Count();
return Ok(count);
}
catch (Exception error)
{
logger.LogError(error.Message);
return StatusCode(500);
}
}

[HttpGet("{id}")]
public ActionResult<RegionDto> GetById(int id)
{
Expand Down
19 changes: 19 additions & 0 deletions NorthwindCRUD/Controllers/ShippersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,25 @@ public ActionResult<PagedResultDto<ShipperDto>> GetPagedShippersWithPage(
}
}

/// <summary>
/// Retrieves the total number of shippers.
/// </summary>
/// <returns>Total count of shippers as an integer.</returns>
[HttpGet("GetShippersCount")]
public ActionResult<int> GetShippersCount()
{
try
{
var count = shipperService.GetAllAsQueryable().Count();
return Ok(count);
}
catch (Exception error)
{
logger.LogError(error.Message);
return StatusCode(500);
}
}

[HttpGet("{id}")]
public ActionResult<ShipperDto> GetById(int id)
{
Expand Down
19 changes: 19 additions & 0 deletions NorthwindCRUD/Controllers/SuppliersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,25 @@ public ActionResult<PagedResultDto<SupplierDto>> GetPagedSuppliersWithPage(
}
}

/// <summary>
/// Retrieves the total number of suppliers.
/// </summary>
/// <returns>Total count of suppliers as an integer.</returns>
[HttpGet("GetSuppliersCount")]
public ActionResult<int> GetSuppliersCount()
{
try
{
var count = supplierService.GetAllAsQueryable().Count();
return Ok(count);
}
catch (Exception error)
{
logger.LogError(error.Message);
return StatusCode(500);
}
}

[HttpGet("{id}")]
public ActionResult<SupplierDto> GetById(int id)
{
Expand Down
19 changes: 19 additions & 0 deletions NorthwindCRUD/Controllers/TerritoriesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@ public ActionResult<PagedResultDto<TerritoryDto>> GetPagedTerritoriesWithPage(
}
}

/// <summary>
/// Retrieves the total number of territories.
/// </summary>
/// <returns>Total count of territories as an integer.</returns>
[HttpGet("GetTerritoriesCount")]
public ActionResult<int> GetTerritoriesCount()
{
try
{
var count = territoryService.GetAllAsQueryable().Count();
return Ok(count);
}
catch (Exception error)
{
logger.LogError(error.Message);
return StatusCode(500);
}
}

[HttpGet("{id}")]
public ActionResult<TerritoryDto> GetById(string id)
{
Expand Down
2 changes: 1 addition & 1 deletion NorthwindCRUD/Services/CategoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public CategoryDb[] GetAll()

public IQueryable<CategoryDb> GetAllAsQueryable()
{
return this.dataContext.Categories.AsQueryable();
return this.dataContext.Categories;
}

public CategoryDb? GetById(int id)
Expand Down
2 changes: 1 addition & 1 deletion NorthwindCRUD/Services/CustomerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public CustomerDb[] GetAll()

public IQueryable<CustomerDb> GetAllAsQueryable()
{
return this.dataContext.Customers.AsQueryable();
return this.dataContext.Customers;
}

public CustomerDb? GetById(string id)
Expand Down
2 changes: 1 addition & 1 deletion NorthwindCRUD/Services/EmployeeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public EmployeeDb[] GetAll()

public IQueryable<EmployeeDb> GetAllAsQueryable()
{
return this.dataContext.Employees.AsQueryable();
return this.dataContext.Employees;
}

public EmployeeDb? GetById(int id)
Expand Down
2 changes: 1 addition & 1 deletion NorthwindCRUD/Services/OrderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public OrderDb[] GetAll()

public IQueryable<OrderDb> GetAllAsQueryable()
{
return this.dataContext.Orders.AsQueryable();
return this.dataContext.Orders;
}

public OrderDb[] GetNOrders(int numberOfOrdersToRetrieve)
Expand Down
2 changes: 1 addition & 1 deletion NorthwindCRUD/Services/ProductService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ProductDb[] GetAll()

public IQueryable<ProductDb> GetAllAsQueryable()
{
return this.dataContext.Products.AsQueryable();
return this.dataContext.Products;
}

public ProductDb? GetById(int id)
Expand Down
2 changes: 1 addition & 1 deletion NorthwindCRUD/Services/RegionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public RegionDb[] GetAll()

public IQueryable<RegionDb> GetAllAsQueryable()
{
return this.dataContext.Regions.AsQueryable();
return this.dataContext.Regions;
}

public RegionDb? GetById(int id)
Expand Down
2 changes: 1 addition & 1 deletion NorthwindCRUD/Services/ShipperService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ShipperDb[] GetAll()

public IQueryable<ShipperDb> GetAllAsQueryable()
{
return this.dataContext.Shippers.AsQueryable();
return this.dataContext.Shippers;
}

public ShipperDb? GetById(int id)
Expand Down
2 changes: 1 addition & 1 deletion NorthwindCRUD/Services/SupplierService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public SupplierDb[] GetAll()

public IQueryable<SupplierDb> GetAllAsQueryable()
{
return this.dataContext.Suppliers.AsQueryable();
return this.dataContext.Suppliers;
}

public SupplierDb? GetById(int id)
Expand Down
2 changes: 1 addition & 1 deletion NorthwindCRUD/Services/TerritoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public TerritoryDb[] GetAll()

public IQueryable<TerritoryDb> GetAllAsQueryable()
{
return this.dataContext.Territories.AsQueryable();
return this.dataContext.Territories;
}

public TerritoryDb? GetById(string id)
Expand Down

0 comments on commit 57315bf

Please sign in to comment.