Skip to content

Commit bc22a61

Browse files
committed
Merge branch 'main' into jcoitino/query-builder-poc
2 parents aebb959 + 296ebac commit bc22a61

35 files changed

+15925
-15058
lines changed

NorthwindCRUD/Controllers/CategoriesController.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
namespace NorthwindCRUD.Controllers
22
{
3-
using System.ComponentModel.DataAnnotations;
43
using AutoMapper;
54
using Microsoft.AspNetCore.Authorization;
65
using Microsoft.AspNetCore.Mvc;
76
using NorthwindCRUD.Models.DbModels;
87
using NorthwindCRUD.Models.Dtos;
98
using NorthwindCRUD.Services;
10-
using Swashbuckle.AspNetCore.Annotations;
119

1210
[ApiController]
1311
[Route("[controller]")]
@@ -52,8 +50,8 @@ public ActionResult<CategoryDto[]> GetAll()
5250
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5351
[HttpGet("GetCategoriesWithSkip")]
5452
public ActionResult<PagedResultDto<CategoryDto>> GetCategoriesWithSkip(
55-
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
56-
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
53+
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
54+
[FromQuery][Attributes.SwaggerTopParameter] int? top,
5755
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
5856
{
5957
try

NorthwindCRUD/Controllers/CustomersController.cs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace NorthwindCRUD.Controllers
22
{
3-
using System.ComponentModel.DataAnnotations;
43
using AutoMapper;
54
using Microsoft.AspNetCore.Authorization;
65
using Microsoft.AspNetCore.Mvc;
@@ -51,8 +50,8 @@ public ActionResult<CustomerDto[]> GetAll()
5150
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5251
[HttpGet("GetCustomersWithSkip")]
5352
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,
5655
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
5756
{
5857
try
@@ -121,6 +120,21 @@ public ActionResult<CountResultDto> GetCustomersCount()
121120
}
122121
}
123122

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+
124138
[HttpGet("{id}")]
125139
public ActionResult<CustomerDto> GetById(string id)
126140
{
@@ -157,6 +171,21 @@ public ActionResult<OrderDto[]> GetOrdersByCustomerId(string id)
157171
}
158172
}
159173

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+
160189
[HttpPost]
161190
[Authorize]
162191
public ActionResult<CustomerDto> Create(CustomerDto model)

NorthwindCRUD/Controllers/EmployeesController.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace NorthwindCRUD.Controllers
22
{
3-
using System.ComponentModel.DataAnnotations;
43
using AutoMapper;
54
using Microsoft.AspNetCore.Authorization;
65
using Microsoft.AspNetCore.Mvc;
@@ -69,8 +68,8 @@ public ActionResult<OrderDto[]> GetAllAuthorized()
6968
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
7069
[HttpGet("GetEmployeesWithSkip")]
7170
public ActionResult<PagedResultDto<EmployeeDto>> GetPagedEmployees(
72-
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
73-
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
71+
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
72+
[FromQuery][Attributes.SwaggerTopParameter] int? top,
7473
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
7574
{
7675
try

NorthwindCRUD/Controllers/OrdersController.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace NorthwindCRUD.Controllers
22
{
3-
using System.ComponentModel.DataAnnotations;
43
using AutoMapper;
54
using Microsoft.AspNetCore.Authorization;
65
using Microsoft.AspNetCore.Mvc;
@@ -57,8 +56,8 @@ public ActionResult<OrderDto[]> GetAll()
5756
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5857
[HttpGet("GetPagedOrders")]
5958
public ActionResult<PagedResultDto<OrderDto>> GetAllOrders(
60-
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
61-
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
59+
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
60+
[FromQuery][Attributes.SwaggerTopParameter] int? top,
6261
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
6362
{
6463
try

NorthwindCRUD/Controllers/ProductsController.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace NorthwindCRUD.Controllers
22
{
3-
using System.ComponentModel.DataAnnotations;
43
using AutoMapper;
54
using Microsoft.AspNetCore.Authorization;
65
using Microsoft.AspNetCore.Mvc;
@@ -71,8 +70,8 @@ public ActionResult<OrderDto[]> GetAllAuthorized()
7170
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
7271
[HttpGet("GetPagedProducts")]
7372
public ActionResult<PagedResultDto<ProductDto>> GetAllProducts(
74-
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
75-
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
73+
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
74+
[FromQuery][Attributes.SwaggerTopParameter] int? top,
7675
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
7776
{
7877
try

NorthwindCRUD/Controllers/RegionsController.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace NorthwindCRUD.Controllers
22
{
3-
using System.ComponentModel.DataAnnotations;
43
using AutoMapper;
54
using Microsoft.AspNetCore.Authorization;
65
using Microsoft.AspNetCore.Mvc;
@@ -51,8 +50,8 @@ public ActionResult<RegionDto[]> GetAll()
5150
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5251
[HttpGet("GetPagedRegions")]
5352
public ActionResult<PagedResultDto<RegionDto>> GetAllRegions(
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,
5655
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
5756
{
5857
try
@@ -142,7 +141,7 @@ public ActionResult<RegionDto> GetById(int id)
142141
}
143142

144143
[HttpGet("{id}/Territories")]
145-
public ActionResult<CustomerDto> GetTerritoryByRegionId(int id)
144+
public ActionResult<TerritoryDto[]> GetTerritoryByRegionId(int id)
146145
{
147146
try
148147
{

NorthwindCRUD/Controllers/ShippersController.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace NorthwindCRUD.Controllers
22
{
3-
using System.ComponentModel.DataAnnotations;
43
using AutoMapper;
54
using Microsoft.AspNetCore.Authorization;
65
using Microsoft.AspNetCore.Mvc;
@@ -51,8 +50,8 @@ public ActionResult<ShipperDto[]> GetAll()
5150
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5251
[HttpGet("GetPagedShippersWithSkip")]
5352
public ActionResult<PagedResultDto<ShipperDto>> GetPagedShippersWithSkip(
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,
5655
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
5756
{
5857
try

NorthwindCRUD/Controllers/SuppliersController.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace NorthwindCRUD.Controllers
22
{
3-
using System.ComponentModel.DataAnnotations;
43
using AutoMapper;
54
using Microsoft.AspNetCore.Authorization;
65
using Microsoft.AspNetCore.Mvc;
@@ -51,8 +50,8 @@ public ActionResult<SupplierDto[]> GetAll()
5150
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5251
[HttpGet("GetPagedSuppliers")]
5352
public ActionResult<PagedResultDto<SupplierDto>> GetAllSuppliers(
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,
5655
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
5756
{
5857
try

NorthwindCRUD/Controllers/TerritoriesController.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace NorthwindCRUD.Controllers
22
{
3-
using System.ComponentModel.DataAnnotations;
43
using AutoMapper;
54
using Microsoft.AspNetCore.Authorization;
65
using Microsoft.AspNetCore.Mvc;
@@ -53,8 +52,8 @@ public ActionResult<TerritoryDto[]> GetAll()
5352
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
5453
[HttpGet("GetPagedTerritories")]
5554
public ActionResult<PagedResultDto<TerritoryDto>> GetAllTerritories(
56-
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
57-
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
55+
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
56+
[FromQuery][Attributes.SwaggerTopParameter] int? top,
5857
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
5958
{
6059
try

NorthwindCRUD/Helpers/MappingProfiles.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public MappingProfiles()
1818
CreateMap<TerritoryDto, TerritoryDb>().ReverseMap();
1919
CreateMap<CustomerDto, CustomerDb>().ReverseMap();
2020
CreateMap<OrderDto, OrderDb>().ReverseMap();
21+
CreateMap<CustomerWithOrdersDto, CustomerDb>().ReverseMap();
22+
CreateMap<OrderWithDetailsDto, OrderDb>().ReverseMap();
2123
CreateMap<OrderDetailDto, OrderDetailDb>().ReverseMap();
2224
CreateMap<AddressDto, AddressDb>().ReverseMap();
2325
CreateMap<LoginDto, UserDb>().ReverseMap();

0 commit comments

Comments
 (0)