|
1 | 1 | namespace NorthwindCRUD.Controllers |
2 | 2 | { |
3 | | - using System.ComponentModel.DataAnnotations; |
4 | 3 | using AutoMapper; |
5 | 4 | using Microsoft.AspNetCore.Authorization; |
6 | 5 | using Microsoft.AspNetCore.Mvc; |
@@ -51,8 +50,8 @@ public ActionResult<CustomerDto[]> GetAll() |
51 | 50 | /// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns> |
52 | 51 | [HttpGet("GetCustomersWithSkip")] |
53 | 52 | public ActionResult<PagedResultDto<CustomerDto>> GetCustomersWithSkip( |
54 | | - [FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip, |
55 | | - [FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top, |
| 53 | + [FromQuery][Attributes.SwaggerSkipParameter] int? skip, |
| 54 | + [FromQuery][Attributes.SwaggerTopParameter] int? top, |
56 | 55 | [FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy) |
57 | 56 | { |
58 | 57 | try |
@@ -121,6 +120,21 @@ public ActionResult<CountResultDto> GetCustomersCount() |
121 | 120 | } |
122 | 121 | } |
123 | 122 |
|
| 123 | + [HttpGet("WithOrders")] |
| 124 | + public ActionResult<CustomerWithOrdersDto[]> GetAllCustomersWithOrders() |
| 125 | + { |
| 126 | + try |
| 127 | + { |
| 128 | + var customers = this.customerService.GetAllCustomersWithOrders(); |
| 129 | + return Ok(this.mapper.Map<CustomerDb[], CustomerWithOrdersDto[]>(customers)); |
| 130 | + } |
| 131 | + catch (Exception error) |
| 132 | + { |
| 133 | + logger.LogError(error.Message); |
| 134 | + return StatusCode(500); |
| 135 | + } |
| 136 | + } |
| 137 | + |
124 | 138 | [HttpGet("{id}")] |
125 | 139 | public ActionResult<CustomerDto> GetById(string id) |
126 | 140 | { |
@@ -157,6 +171,21 @@ public ActionResult<OrderDto[]> GetOrdersByCustomerId(string id) |
157 | 171 | } |
158 | 172 | } |
159 | 173 |
|
| 174 | + [HttpGet("{id}/Orders/WithDetails")] |
| 175 | + public ActionResult<OrderWithDetailsDto[]> GetOrdersAndOrderDetailsByCustomerId(string id) |
| 176 | + { |
| 177 | + try |
| 178 | + { |
| 179 | + var orders = this.orderService.GetOrdersWithDetailsByCustomerId(id); |
| 180 | + return Ok(this.mapper.Map<OrderDb[], OrderWithDetailsDto[]>(orders)); |
| 181 | + } |
| 182 | + catch (Exception error) |
| 183 | + { |
| 184 | + logger.LogError(error.Message); |
| 185 | + return StatusCode(500); |
| 186 | + } |
| 187 | + } |
| 188 | + |
160 | 189 | [HttpPost] |
161 | 190 | [Authorize] |
162 | 191 | public ActionResult<CustomerDto> Create(CustomerDto model) |
|
0 commit comments