@@ -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 )
0 commit comments