Skip to content

Commit 02a028a

Browse files
committed
Merge branch 'main' into cpi/enrich-swagger-metadata
2 parents 0280af9 + 6c59636 commit 02a028a

24 files changed

+22306
-945
lines changed

NorthwindCRUD/Controllers/CategoriesController.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public CategoriesController(CategoryService categoryService, ProductService prod
2525
}
2626

2727
[HttpGet]
28-
[Authorize]
2928
public ActionResult<CategoryDto[]> GetAll()
3029
{
3130
try
@@ -42,7 +41,6 @@ public ActionResult<CategoryDto[]> GetAll()
4241
}
4342

4443
[HttpGet("{id}")]
45-
[Authorize]
4644
public ActionResult<CategoryDto> GetById(int id)
4745
{
4846
try
@@ -64,7 +62,6 @@ public ActionResult<CategoryDto> GetById(int id)
6462

6563

6664
[HttpGet("{id}/Details")]
67-
[Authorize]
6865
public ActionResult<CategoryDetailsDto> GetDetailsById(int id)
6966
{
7067
try
@@ -85,7 +82,6 @@ public ActionResult<CategoryDetailsDto> GetDetailsById(int id)
8582
}
8683

8784
[HttpGet("{id}/Products")]
88-
[Authorize]
8985
public ActionResult<ProductDto[]> GetProductsByCategoryId(int id)
9086
{
9187
try

NorthwindCRUD/Controllers/CustomersController.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public CustomersController(CustomerService customerService, OrderService orderSe
2525
}
2626

2727
[HttpGet]
28-
[Authorize]
2928
public ActionResult<CustomerDto[]> GetAll()
3029
{
3130
try
@@ -41,7 +40,6 @@ public ActionResult<CustomerDto[]> GetAll()
4140
}
4241

4342
[HttpGet("{id}")]
44-
[Authorize]
4543
public ActionResult<CustomerDto> GetById(string id)
4644
{
4745
try
@@ -63,7 +61,6 @@ public ActionResult<CustomerDto> GetById(string id)
6361
}
6462

6563
[HttpGet("{id}/Orders")]
66-
[Authorize]
6764
public ActionResult<OrderDto[]> GetOrdersByCustomerId(string id)
6865
{
6966
try

NorthwindCRUD/Controllers/EmployeesController.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public EmployeesController(EmployeeService employeeService, EmployeeTerritorySer
2727
}
2828

2929
[HttpGet]
30-
[Authorize]
3130
public ActionResult<EmployeeDto[]> GetAll()
3231
{
3332
try
@@ -43,7 +42,6 @@ public ActionResult<EmployeeDto[]> GetAll()
4342
}
4443

4544
[HttpGet("{id}")]
46-
[Authorize]
4745
public ActionResult<EmployeeDto> GetById(int id)
4846
{
4947
try
@@ -65,7 +63,6 @@ public ActionResult<EmployeeDto> GetById(int id)
6563
}
6664

6765
[HttpGet("{id}/Superior")]
68-
[Authorize]
6966
public ActionResult<EmployeeDto> GetSuperiorById(int id)
7067
{
7168
try
@@ -92,7 +89,6 @@ public ActionResult<EmployeeDto> GetSuperiorById(int id)
9289
}
9390

9491
[HttpGet("{id}/Subordinates")]
95-
[Authorize]
9692
public ActionResult<EmployeeDto[]> GetSubordinatesById(int id)
9793
{
9894
try
@@ -107,7 +103,6 @@ public ActionResult<EmployeeDto[]> GetSubordinatesById(int id)
107103
}
108104

109105
[HttpGet("{id}/Orders")]
110-
[Authorize]
111106
public ActionResult<OrderDto[]> GetOrdersByEmployeeId(int id)
112107
{
113108
try
@@ -123,7 +118,6 @@ public ActionResult<OrderDto[]> GetOrdersByEmployeeId(int id)
123118
}
124119

125120
[HttpGet("{id}/Teritories")]
126-
[Authorize]
127121
public ActionResult<EmployeeDto[]> GetTeritoriesByEmployeeId(int id)
128122
{
129123
try

NorthwindCRUD/Controllers/OrdersController.cs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public OrdersController(OrderService orderService, EmployeeService employeeServi
3232
}
3333

3434
[HttpGet]
35-
[Authorize]
3635
public ActionResult<OrderDto[]> GetAll()
3736
{
3837
try
@@ -46,9 +45,8 @@ public ActionResult<OrderDto[]> GetAll()
4645
return StatusCode(500);
4746
}
4847
}
49-
48+
5049
[HttpGet("{id}")]
51-
[Authorize]
5250
public ActionResult<OrderDto> GetById(int id)
5351
{
5452
try
@@ -70,15 +68,14 @@ public ActionResult<OrderDto> GetById(int id)
7068
}
7169

7270
[HttpGet("{id}/Details")]
73-
[Authorize]
7471
public ActionResult<OrderDetailDto[]> GetDetailsByOrderId(int id)
7572
{
7673
try
7774
{
78-
var order = this.orderService.GetById(id);
79-
if (order != null)
75+
var orderDetail = this.orderService.GetOrderDetailsById(id);
76+
if (orderDetail != null)
8077
{
81-
return Ok(this.mapper.Map<OrderDetailDb[], OrderDetailDto[]>(order.Details.ToArray()));
78+
return Ok(this.mapper.Map<OrderDetailDb[], OrderDetailDto[]>(orderDetail));
8279
}
8380

8481
return NotFound();
@@ -91,7 +88,6 @@ public ActionResult<OrderDetailDto[]> GetDetailsByOrderId(int id)
9188
}
9289

9390
[HttpGet("{id}/Customer")]
94-
[Authorize]
9591
public ActionResult<CustomerDto> GetCustomerByOrderId(int id)
9692
{
9793
try
@@ -117,7 +113,6 @@ public ActionResult<CustomerDto> GetCustomerByOrderId(int id)
117113
}
118114

119115
[HttpGet("{id}/Employee")]
120-
[Authorize]
121116
public ActionResult<CustomerDto> GetEmployeeByOrderId(int id)
122117
{
123118
try
@@ -142,7 +137,6 @@ public ActionResult<CustomerDto> GetEmployeeByOrderId(int id)
142137
}
143138

144139
[HttpGet("{id}/Shipper")]
145-
[Authorize]
146140
public ActionResult<CustomerDto> GetShipperByOrderId(int id)
147141
{
148142
try
@@ -169,15 +163,14 @@ public ActionResult<CustomerDto> GetShipperByOrderId(int id)
169163

170164

171165
[HttpGet("{id}/Products")]
172-
[Authorize]
173166
public ActionResult<ProductDto[]> GetProductsByOrderId(int id)
174167
{
175168
try
176169
{
177-
var order = this.orderService.GetById(id);
178-
if (order != null)
170+
var orderDetails = this.orderService.GetOrderDetailsById(id);
171+
if (orderDetails != null)
179172
{
180-
var productIds = order.Details.Select(o => o.ProductId).ToArray();
173+
var productIds = orderDetails.Select(o => o.ProductId).ToArray();
181174
var products = this.productService.GetProductsByIds(productIds);
182175

183176
if (products != null)
@@ -196,6 +189,22 @@ public ActionResult<ProductDto[]> GetProductsByOrderId(int id)
196189
}
197190
}
198191

192+
[HttpGet("retrieve/{ordersToRetrieve}")]
193+
[Authorize]
194+
public ActionResult<OrderDto[]> OrdersToRetrieve(int ordersToRetrieve)
195+
{
196+
try
197+
{
198+
var orders = this.orderService.GetNOrders(ordersToRetrieve);
199+
return Ok(this.mapper.Map<OrderDb[], OrderDto[]>(orders));
200+
}
201+
catch (Exception error)
202+
{
203+
logger.LogError(error.Message);
204+
return StatusCode(500);
205+
}
206+
}
207+
199208
[HttpPost]
200209
[Authorize]
201210
public ActionResult<OrderDto> Create(OrderDto model)

NorthwindCRUD/Controllers/ProductsController.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public ProductsController(ProductService productService, CategoryService categor
2929
}
3030

3131
[HttpGet]
32-
[Authorize]
3332
public ActionResult<ProductDto[]> GetAll()
3433
{
3534
try
@@ -46,7 +45,6 @@ public ActionResult<ProductDto[]> GetAll()
4645
}
4746

4847
[HttpGet("{id}")]
49-
[Authorize]
5048
public ActionResult<ProductDto> GetById(int id)
5149
{
5250
try
@@ -67,7 +65,6 @@ public ActionResult<ProductDto> GetById(int id)
6765
}
6866

6967
[HttpGet("{id}/Category")]
70-
[Authorize]
7168
public ActionResult<CategoryDto> GetCategoryByProductId(int id)
7269
{
7370
try
@@ -93,7 +90,6 @@ public ActionResult<CategoryDto> GetCategoryByProductId(int id)
9390
}
9491

9592
[HttpGet("{id}/OrderDetails")]
96-
[Authorize]
9793
public ActionResult<OrderDetailDto[]> GetOrderDetailsByProductId(int id)
9894
{
9995
try
@@ -115,7 +111,6 @@ public ActionResult<OrderDetailDto[]> GetOrderDetailsByProductId(int id)
115111
}
116112

117113
[HttpGet("{id}/Supplier")]
118-
[Authorize]
119114
public ActionResult<SupplierDto> GetSupplierByProductId(int id)
120115
{
121116
try

NorthwindCRUD/Controllers/RegionsController.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public RegionsController(RegionService regionService, TerritoryService territory
2626
}
2727

2828
[HttpGet]
29-
[Authorize]
3029
public ActionResult<RegionDto[]> GetAll()
3130
{
3231
try
@@ -43,7 +42,6 @@ public ActionResult<RegionDto[]> GetAll()
4342
}
4443

4544
[HttpGet("{id}")]
46-
[Authorize]
4745
public ActionResult<RegionDto> GetById(int id)
4846
{
4947
try
@@ -64,7 +62,6 @@ public ActionResult<RegionDto> GetById(int id)
6462
}
6563

6664
[HttpGet("{id}/Territories")]
67-
[Authorize]
6865
public ActionResult<CustomerDto> GetTerritoryByRegionId(int id)
6966
{
7067
try
@@ -86,7 +83,6 @@ public ActionResult<CustomerDto> GetTerritoryByRegionId(int id)
8683
}
8784

8885
[HttpPost]
89-
[Authorize]
9086
public ActionResult<RegionDto> Create(RegionDto model)
9187
{
9288
try
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
namespace NorthwindCRUD.Controllers
2+
{
3+
using AutoMapper;
4+
using Microsoft.AspNetCore.Authorization;
5+
using Microsoft.AspNetCore.Mvc;
6+
using NorthwindCRUD.Models.Dtos;
7+
using NorthwindCRUD.Services;
8+
using System.ComponentModel.DataAnnotations;
9+
10+
[ApiController]
11+
[Route("[controller]")]
12+
public class SalesController : ControllerBase
13+
{
14+
private readonly SalesService salesService;
15+
private readonly IMapper mapper;
16+
private readonly ILogger logger;
17+
18+
public SalesController(SalesService salesService, IMapper mapper, ILogger logger)
19+
{
20+
this.salesService = salesService;
21+
this.mapper = mapper;
22+
this.logger = logger;
23+
}
24+
25+
[HttpGet("ByCategory")]
26+
[Authorize]
27+
public ActionResult<SalesDto[]> GetSalesByCategoryAndYear([FromQuery] [Required] string categoryName, [FromQuery] int? orderYear = null)
28+
{
29+
try {
30+
var response = this.salesService.GetSalesDataByCategoryAndYear(categoryName, orderYear);
31+
return Ok(response);
32+
}
33+
catch
34+
{
35+
return BadRequest();
36+
}
37+
}
38+
39+
[HttpGet("ByCountry/{country}")]
40+
[Authorize]
41+
public ActionResult<SalesDto[]> GetSalesByCountry(
42+
string country,
43+
[FromQuery] [Required] string startDate,
44+
[FromQuery] [Required] string endDate)
45+
{
46+
47+
try
48+
{
49+
var salesData = this.salesService.RetrieveSalesDataByCountry(startDate, endDate, country);
50+
51+
if (salesData == null)
52+
{
53+
return NotFound("No sales data found for the specified parameters.");
54+
}
55+
56+
return Ok(salesData);
57+
}
58+
catch (ArgumentException exception)
59+
{
60+
return StatusCode(400, exception.Message);
61+
}
62+
catch (Exception error)
63+
{
64+
logger.LogError(error.Message);
65+
return StatusCode(500);
66+
}
67+
}
68+
69+
[HttpGet("ByYear/{year}")]
70+
[Authorize]
71+
public ActionResult<SalesDto[]> GetSalesByYear(
72+
int year,
73+
[FromQuery] int startMounth,
74+
[FromQuery] int endMounth)
75+
{
76+
77+
try
78+
{
79+
var salesData = this.salesService.RetrieveSalesDataByYear(year, startMounth, endMounth);
80+
81+
if (salesData == null)
82+
{
83+
return NotFound("No sales data found for the specified parameters.");
84+
}
85+
86+
return Ok(salesData);
87+
}
88+
catch (ArgumentException exception)
89+
{
90+
return StatusCode(400, exception.Message);
91+
}
92+
catch (Exception error)
93+
{
94+
logger.LogError(error.Message);
95+
return StatusCode(500);
96+
}
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)