Skip to content

Commit 8d3739e

Browse files
authored
Merge pull request #28 from IgniteUI/dTsvetkov/add-swagger-anotations
Add swagger annotations and formats to SalesController
2 parents 90c3143 + a180b3c commit 8d3739e

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

NorthwindCRUD/Controllers/SalesController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.AspNetCore.Mvc;
55
using NorthwindCRUD.Models.Dtos;
66
using NorthwindCRUD.Services;
7+
using Swashbuckle.AspNetCore.Annotations;
78

89
namespace NorthwindCRUD.Controllers
910
{
@@ -41,8 +42,8 @@ public ActionResult<SalesDto[]> GetSalesByCategoryAndYear([FromQuery] [Required]
4142
[Authorize]
4243
public ActionResult<SalesDto[]> GetSalesByCountry(
4344
string country,
44-
[FromQuery] [Required] string startDate,
45-
[FromQuery] [Required] string endDate)
45+
[FromQuery] [Required] [DataType(DataType.Date)] [SwaggerParameter("Start date in YYYY-MM-DD format")] string startDate,
46+
[FromQuery] [Required] [DataType(DataType.Date)] [SwaggerParameter("End date in YYYY-MM-DD format")] string endDate)
4647
{
4748
try
4849
{

NorthwindCRUD/Services/OrderService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,17 @@ public OrderDb Create(OrderDb model)
7676
{
7777
if (this.dataContext.Customers.FirstOrDefault(c => c.CustomerId == model.CustomerId) == null)
7878
{
79-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Customer), model.CustomerId?.ToString()));
79+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Customer), model.CustomerId?.ToString(CultureInfo.InvariantCulture)));
8080
}
8181

8282
if (this.dataContext.Employees.FirstOrDefault(e => e.EmployeeId == model.EmployeeId) == null)
8383
{
84-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Employee), model.EmployeeId.ToString()));
84+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Employee), model.EmployeeId?.ToString(CultureInfo.InvariantCulture)));
8585
}
8686

8787
if (this.dataContext.Shippers.FirstOrDefault(s => s.ShipperId == model.ShipperId) == null)
8888
{
89-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Shipper), model.ShipperId.ToString()));
89+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Shipper), model.ShipperId?.ToString(CultureInfo.InvariantCulture)));
9090
}
9191

9292
var id = IdGenerator.CreateDigitsId();
@@ -123,12 +123,12 @@ public OrderDb Create(OrderDb model)
123123

124124
if (this.dataContext.Employees.FirstOrDefault(e => e.EmployeeId == model.EmployeeId) == null)
125125
{
126-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Employee), model.EmployeeId.ToString()));
126+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Employee), model.EmployeeId?.ToString(CultureInfo.InvariantCulture)));
127127
}
128128

129129
if (this.dataContext.Shippers.FirstOrDefault(s => s.ShipperId == model.ShipperId) == null)
130130
{
131-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Shipper), model.ShipperId.ToString()));
131+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Shipper), model.ShipperId?.ToString(CultureInfo.InvariantCulture)));
132132
}
133133

134134
var orderEntity = this.dataContext.Orders

NorthwindCRUD/Services/ProductService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public ProductDb Create(ProductDb model)
4545
{
4646
if (this.dataContext.Categories.FirstOrDefault(c => c.CategoryId == model.CategoryId) == null)
4747
{
48-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Category), model.CategoryId.ToString()));
48+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Category), model.CategoryId?.ToString(CultureInfo.InvariantCulture)));
4949
}
5050

5151
if (this.dataContext.Suppliers.FirstOrDefault(s => s.SupplierId == model.SupplierId) == null)
5252
{
53-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Supplier), model.SupplierId.ToString()));
53+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Supplier), model.SupplierId?.ToString(CultureInfo.InvariantCulture)));
5454
}
5555

5656
var id = IdGenerator.CreateDigitsId();
@@ -75,12 +75,12 @@ public ProductDb Create(ProductDb model)
7575
{
7676
if (this.dataContext.Categories.FirstOrDefault(c => c.CategoryId == model.CategoryId) == null)
7777
{
78-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Category), model.CategoryId.ToString()));
78+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Category), model.CategoryId?.ToString(CultureInfo.InvariantCulture)));
7979
}
8080

8181
if (this.dataContext.Suppliers.FirstOrDefault(s => s.SupplierId == model.SupplierId) == null)
8282
{
83-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Supplier), model.SupplierId.ToString()));
83+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Supplier), model.SupplierId?.ToString(CultureInfo.InvariantCulture)));
8484
}
8585

8686
var productEntity = this.dataContext.Products.FirstOrDefault(p => p.ProductId == model.ProductId);

NorthwindCRUD/Services/TerritoryService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public TerritoryDb Create(TerritoryDb model)
3333
{
3434
if (this.dataContext.Regions.FirstOrDefault(r => r.RegionId == model.RegionId) == null)
3535
{
36-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Region), model.RegionId.ToString()));
36+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Region), model.RegionId?.ToString(CultureInfo.InvariantCulture)));
3737
}
3838

3939
var id = IdGenerator.CreateDigitsId().ToString(CultureInfo.InvariantCulture);
@@ -58,7 +58,7 @@ public TerritoryDb Create(TerritoryDb model)
5858
{
5959
if (this.dataContext.Regions.FirstOrDefault(r => r.RegionId == model.RegionId) == null)
6060
{
61-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Region), model.RegionId.ToString()));
61+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Region), model.RegionId?.ToString(CultureInfo.InvariantCulture)));
6262
}
6363

6464
var territoryEntity = this.dataContext.Territories.FirstOrDefault(p => p.TerritoryId == model.TerritoryId);

0 commit comments

Comments
 (0)