Clean up usings and controller attributes (#2124)
* Clean up usings and controller attributes - Removed redundant attributes when the controllers already specifies what the result type is. - Use StatusCodes instead of HttpStatusCode. - Clean up namespaces and use type aliases to disambiguate the many DTOs defined. * Forgot one * Update src/Services/Webhooks/Webhooks.API/Controllers/WebhooksController.cs Co-authored-by: Reuben Bond <203839+ReubenBond@users.noreply.github.com> --------- Co-authored-by: Reuben Bond <203839+ReubenBond@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									c7c2d1ca2f
								
							
						
					
					
						commit
						3b9560c26e
					
				| @ -16,8 +16,7 @@ public class BasketController : ControllerBase | |||||||
| 
 | 
 | ||||||
|     [HttpPost] |     [HttpPost] | ||||||
|     [HttpPut] |     [HttpPut] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.BadRequest)] |     [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|     [ProducesResponseType(typeof(BasketData), (int)HttpStatusCode.OK)] |  | ||||||
|     public async Task<ActionResult<BasketData>> UpdateAllBasketAsync([FromBody] UpdateBasketRequest data) |     public async Task<ActionResult<BasketData>> UpdateAllBasketAsync([FromBody] UpdateBasketRequest data) | ||||||
|     { |     { | ||||||
|         if (data.Items == null || !data.Items.Any()) |         if (data.Items == null || !data.Items.Any()) | ||||||
| @ -73,8 +72,7 @@ public class BasketController : ControllerBase | |||||||
| 
 | 
 | ||||||
|     [HttpPut] |     [HttpPut] | ||||||
|     [Route("items")] |     [Route("items")] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.BadRequest)] |     [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|     [ProducesResponseType(typeof(BasketData), (int)HttpStatusCode.OK)] |  | ||||||
|     public async Task<ActionResult<BasketData>> UpdateQuantitiesAsync([FromBody] UpdateBasketItemsRequest data) |     public async Task<ActionResult<BasketData>> UpdateQuantitiesAsync([FromBody] UpdateBasketItemsRequest data) | ||||||
|     { |     { | ||||||
|         if (!data.Updates.Any()) |         if (!data.Updates.Any()) | ||||||
| @ -110,8 +108,8 @@ public class BasketController : ControllerBase | |||||||
| 
 | 
 | ||||||
|     [HttpPost] |     [HttpPost] | ||||||
|     [Route("items")] |     [Route("items")] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.BadRequest)] |     [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.OK)] |     [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|     public async Task<ActionResult> AddBasketItemAsync([FromBody] AddBasketItemRequest data) |     public async Task<ActionResult> AddBasketItemAsync([FromBody] AddBasketItemRequest data) | ||||||
|     { |     { | ||||||
|         if (data == null || data.Quantity == 0) |         if (data == null || data.Quantity == 0) | ||||||
|  | |||||||
| @ -1,11 +0,0 @@ | |||||||
| namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers; |  | ||||||
| 
 |  | ||||||
| [Route("")] |  | ||||||
| public class HomeController : Controller |  | ||||||
| { |  | ||||||
|     [HttpGet] |  | ||||||
|     public IActionResult Index() |  | ||||||
|     { |  | ||||||
|         return new RedirectResult("~/swagger"); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -16,8 +16,7 @@ public class OrderController : ControllerBase | |||||||
| 
 | 
 | ||||||
|     [Route("draft/{basketId}")] |     [Route("draft/{basketId}")] | ||||||
|     [HttpGet] |     [HttpGet] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.BadRequest)] |     [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|     [ProducesResponseType(typeof(OrderData), (int)HttpStatusCode.OK)] |  | ||||||
|     public async Task<ActionResult<OrderData>> GetOrderDraftAsync(string basketId) |     public async Task<ActionResult<OrderData>> GetOrderDraftAsync(string basketId) | ||||||
|     { |     { | ||||||
|         if (string.IsNullOrEmpty(basketId)) |         if (string.IsNullOrEmpty(basketId)) | ||||||
|  | |||||||
| @ -2,12 +2,8 @@ | |||||||
| global using Grpc.Core.Interceptors; | global using Grpc.Core.Interceptors; | ||||||
| global using Grpc.Core; | global using Grpc.Core; | ||||||
| global using GrpcBasket; | global using GrpcBasket; | ||||||
| global using HealthChecks.UI.Client; |  | ||||||
| global using Microsoft.AspNetCore.Authentication.JwtBearer; |  | ||||||
| global using Microsoft.AspNetCore.Authentication; |  | ||||||
| global using Microsoft.AspNetCore.Authorization; | global using Microsoft.AspNetCore.Authorization; | ||||||
| global using Microsoft.AspNetCore.Builder; | global using Microsoft.AspNetCore.Builder; | ||||||
| global using Microsoft.AspNetCore.Diagnostics.HealthChecks; |  | ||||||
| global using Microsoft.AspNetCore.Http; | global using Microsoft.AspNetCore.Http; | ||||||
| global using Microsoft.AspNetCore.Mvc; | global using Microsoft.AspNetCore.Mvc; | ||||||
| global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config; | global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config; | ||||||
| @ -16,19 +12,13 @@ global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models; | |||||||
| global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services; | global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services; | ||||||
| global using Microsoft.Extensions.Configuration; | global using Microsoft.Extensions.Configuration; | ||||||
| global using Microsoft.Extensions.DependencyInjection; | global using Microsoft.Extensions.DependencyInjection; | ||||||
| global using Microsoft.Extensions.Diagnostics.HealthChecks; |  | ||||||
| global using Microsoft.Extensions.Logging; | global using Microsoft.Extensions.Logging; | ||||||
| global using Microsoft.Extensions.Options; | global using Microsoft.Extensions.Options; | ||||||
| global using Microsoft.OpenApi.Models; |  | ||||||
| global using System.Collections.Generic; | global using System.Collections.Generic; | ||||||
| global using System.IdentityModel.Tokens.Jwt; |  | ||||||
| global using System.Linq; | global using System.Linq; | ||||||
| global using System.Net.Http.Headers; |  | ||||||
| global using System.Net.Http; | global using System.Net.Http; | ||||||
| global using System.Net; | global using System.Net; | ||||||
| global using System.Text.Json; | global using System.Text.Json; | ||||||
| global using System.Threading.Tasks; | global using System.Threading.Tasks; | ||||||
| global using System.Threading; |  | ||||||
| global using System; | global using System; | ||||||
| global using Microsoft.IdentityModel.Tokens; |  | ||||||
| global using Services.Common; | global using Services.Common; | ||||||
|  | |||||||
| @ -16,8 +16,7 @@ public class BasketController : ControllerBase | |||||||
| 
 | 
 | ||||||
|     [HttpPost] |     [HttpPost] | ||||||
|     [HttpPut] |     [HttpPut] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.BadRequest)] |     [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|     [ProducesResponseType(typeof(BasketData), (int)HttpStatusCode.OK)] |  | ||||||
|     public async Task<ActionResult<BasketData>> UpdateAllBasketAsync([FromBody] UpdateBasketRequest data) |     public async Task<ActionResult<BasketData>> UpdateAllBasketAsync([FromBody] UpdateBasketRequest data) | ||||||
|     { |     { | ||||||
|         if (data.Items == null || !data.Items.Any()) |         if (data.Items == null || !data.Items.Any()) | ||||||
| @ -74,8 +73,7 @@ public class BasketController : ControllerBase | |||||||
| 
 | 
 | ||||||
|     [HttpPut] |     [HttpPut] | ||||||
|     [Route("items")] |     [Route("items")] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.BadRequest)] |     [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|     [ProducesResponseType(typeof(BasketData), (int)HttpStatusCode.OK)] |  | ||||||
|     public async Task<ActionResult<BasketData>> UpdateQuantitiesAsync([FromBody] UpdateBasketItemsRequest data) |     public async Task<ActionResult<BasketData>> UpdateQuantitiesAsync([FromBody] UpdateBasketItemsRequest data) | ||||||
|     { |     { | ||||||
|         if (!data.Updates.Any()) |         if (!data.Updates.Any()) | ||||||
| @ -109,8 +107,8 @@ public class BasketController : ControllerBase | |||||||
| 
 | 
 | ||||||
|     [HttpPost] |     [HttpPost] | ||||||
|     [Route("items")] |     [Route("items")] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.BadRequest)] |     [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.OK)] |     [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|     public async Task<ActionResult> AddBasketItemAsync([FromBody] AddBasketItemRequest data) |     public async Task<ActionResult> AddBasketItemAsync([FromBody] AddBasketItemRequest data) | ||||||
|     { |     { | ||||||
|         if (data == null || data.Quantity == 0) |         if (data == null || data.Quantity == 0) | ||||||
|  | |||||||
| @ -16,8 +16,7 @@ public class OrderController : ControllerBase | |||||||
| 
 | 
 | ||||||
|     [Route("draft/{basketId}")] |     [Route("draft/{basketId}")] | ||||||
|     [HttpGet] |     [HttpGet] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.BadRequest)] |     [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|     [ProducesResponseType(typeof(OrderData), (int)HttpStatusCode.OK)] |  | ||||||
|     public async Task<ActionResult<OrderData>> GetOrderDraftAsync(string basketId) |     public async Task<ActionResult<OrderData>> GetOrderDraftAsync(string basketId) | ||||||
|     { |     { | ||||||
|         if (string.IsNullOrWhiteSpace(basketId)) |         if (string.IsNullOrWhiteSpace(basketId)) | ||||||
|  | |||||||
| @ -1,7 +0,0 @@ | |||||||
| namespace Microsoft.eShopOnContainers.Services.Basket.API; |  | ||||||
| 
 |  | ||||||
| public class BasketSettings |  | ||||||
| { |  | ||||||
|     public string ConnectionString { get; set; } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| @ -23,7 +23,6 @@ public class BasketController : ControllerBase | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     [HttpGet("{id}")] |     [HttpGet("{id}")] | ||||||
|     [ProducesResponseType(typeof(CustomerBasket), (int)HttpStatusCode.OK)] |  | ||||||
|     public async Task<ActionResult<CustomerBasket>> GetBasketByIdAsync(string id) |     public async Task<ActionResult<CustomerBasket>> GetBasketByIdAsync(string id) | ||||||
|     { |     { | ||||||
|         var basket = await _repository.GetBasketAsync(id); |         var basket = await _repository.GetBasketAsync(id); | ||||||
| @ -32,7 +31,6 @@ public class BasketController : ControllerBase | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     [HttpPost] |     [HttpPost] | ||||||
|     [ProducesResponseType(typeof(CustomerBasket), (int)HttpStatusCode.OK)] |  | ||||||
|     public async Task<ActionResult<CustomerBasket>> UpdateBasketAsync([FromBody] CustomerBasket value) |     public async Task<ActionResult<CustomerBasket>> UpdateBasketAsync([FromBody] CustomerBasket value) | ||||||
|     { |     { | ||||||
|         return Ok(await _repository.UpdateBasketAsync(value)); |         return Ok(await _repository.UpdateBasketAsync(value)); | ||||||
| @ -40,8 +38,8 @@ public class BasketController : ControllerBase | |||||||
| 
 | 
 | ||||||
|     [Route("checkout")] |     [Route("checkout")] | ||||||
|     [HttpPost] |     [HttpPost] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.Accepted)] |     [ProducesResponseType(StatusCodes.Status202Accepted)] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.BadRequest)] |     [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|     public async Task<ActionResult> CheckoutAsync([FromBody] BasketCheckout basketCheckout, [FromHeader(Name = "x-requestid")] string requestId) |     public async Task<ActionResult> CheckoutAsync([FromBody] BasketCheckout basketCheckout, [FromHeader(Name = "x-requestid")] string requestId) | ||||||
|     { |     { | ||||||
|         var userId = _identityService.GetUserIdentity(); |         var userId = _identityService.GetUserIdentity(); | ||||||
| @ -81,7 +79,7 @@ public class BasketController : ControllerBase | |||||||
| 
 | 
 | ||||||
|     // DELETE api/values/5 |     // DELETE api/values/5 | ||||||
|     [HttpDelete("{id}")] |     [HttpDelete("{id}")] | ||||||
|     [ProducesResponseType(typeof(void), (int)HttpStatusCode.OK)] |     [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|     public async Task DeleteBasketByIdAsync(string id) |     public async Task DeleteBasketByIdAsync(string id) | ||||||
|     { |     { | ||||||
|         await _repository.DeleteBasketAsync(id); |         await _repository.DeleteBasketAsync(id); | ||||||
|  | |||||||
| @ -2,7 +2,6 @@ | |||||||
| global using System.Collections.Generic; | global using System.Collections.Generic; | ||||||
| global using System.ComponentModel.DataAnnotations; | global using System.ComponentModel.DataAnnotations; | ||||||
| global using System.Linq; | global using System.Linq; | ||||||
| global using System.Net; |  | ||||||
| global using System.Security.Claims; | global using System.Security.Claims; | ||||||
| global using System.Text.Json; | global using System.Text.Json; | ||||||
| global using System.Threading.Tasks; | global using System.Threading.Tasks; | ||||||
|  | |||||||
| @ -20,9 +20,9 @@ public class CatalogController : ControllerBase | |||||||
|     // GET api/v1/[controller]/items[?pageSize=3&pageIndex=10] |     // GET api/v1/[controller]/items[?pageSize=3&pageIndex=10] | ||||||
|     [HttpGet] |     [HttpGet] | ||||||
|     [Route("items")] |     [Route("items")] | ||||||
|     [ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)] |     [ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), StatusCodes.Status200OK)] | ||||||
|     [ProducesResponseType(typeof(IEnumerable<CatalogItem>), (int)HttpStatusCode.OK)] |     [ProducesResponseType(typeof(IEnumerable<CatalogItem>), StatusCodes.Status200OK)] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.BadRequest)] |     [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|     public async Task<IActionResult> ItemsAsync([FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0, string ids = null) |     public async Task<IActionResult> ItemsAsync([FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0, string ids = null) | ||||||
|     { |     { | ||||||
|         if (!string.IsNullOrEmpty(ids)) |         if (!string.IsNullOrEmpty(ids)) | ||||||
| @ -74,9 +74,8 @@ public class CatalogController : ControllerBase | |||||||
| 
 | 
 | ||||||
|     [HttpGet] |     [HttpGet] | ||||||
|     [Route("items/{id:int}")] |     [Route("items/{id:int}")] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.NotFound)] |     [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.BadRequest)] |     [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|     [ProducesResponseType(typeof(CatalogItem), (int)HttpStatusCode.OK)] |  | ||||||
|     public async Task<ActionResult<CatalogItem>> ItemByIdAsync(int id) |     public async Task<ActionResult<CatalogItem>> ItemByIdAsync(int id) | ||||||
|     { |     { | ||||||
|         if (id <= 0) |         if (id <= 0) | ||||||
| @ -102,7 +101,6 @@ public class CatalogController : ControllerBase | |||||||
|     // GET api/v1/[controller]/items/withname/samplename[?pageSize=3&pageIndex=10] |     // GET api/v1/[controller]/items/withname/samplename[?pageSize=3&pageIndex=10] | ||||||
|     [HttpGet] |     [HttpGet] | ||||||
|     [Route("items/withname/{name:minlength(1)}")] |     [Route("items/withname/{name:minlength(1)}")] | ||||||
|     [ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)] |  | ||||||
|     public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> ItemsWithNameAsync(string name, [FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) |     public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> ItemsWithNameAsync(string name, [FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) | ||||||
|     { |     { | ||||||
|         var totalItems = await _catalogContext.CatalogItems |         var totalItems = await _catalogContext.CatalogItems | ||||||
| @ -123,7 +121,6 @@ public class CatalogController : ControllerBase | |||||||
|     // GET api/v1/[controller]/items/type/1/brand[?pageSize=3&pageIndex=10] |     // GET api/v1/[controller]/items/type/1/brand[?pageSize=3&pageIndex=10] | ||||||
|     [HttpGet] |     [HttpGet] | ||||||
|     [Route("items/type/{catalogTypeId}/brand/{catalogBrandId:int?}")] |     [Route("items/type/{catalogTypeId}/brand/{catalogBrandId:int?}")] | ||||||
|     [ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)] |  | ||||||
|     public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> ItemsByTypeIdAndBrandIdAsync(int catalogTypeId, int? catalogBrandId, [FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) |     public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> ItemsByTypeIdAndBrandIdAsync(int catalogTypeId, int? catalogBrandId, [FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) | ||||||
|     { |     { | ||||||
|         var root = (IQueryable<CatalogItem>)_catalogContext.CatalogItems; |         var root = (IQueryable<CatalogItem>)_catalogContext.CatalogItems; | ||||||
| @ -151,7 +148,6 @@ public class CatalogController : ControllerBase | |||||||
|     // GET api/v1/[controller]/items/type/all/brand[?pageSize=3&pageIndex=10] |     // GET api/v1/[controller]/items/type/all/brand[?pageSize=3&pageIndex=10] | ||||||
|     [HttpGet] |     [HttpGet] | ||||||
|     [Route("items/type/all/brand/{catalogBrandId:int?}")] |     [Route("items/type/all/brand/{catalogBrandId:int?}")] | ||||||
|     [ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)] |  | ||||||
|     public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> ItemsByBrandIdAsync(int? catalogBrandId, [FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) |     public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> ItemsByBrandIdAsync(int? catalogBrandId, [FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) | ||||||
|     { |     { | ||||||
|         var root = (IQueryable<CatalogItem>)_catalogContext.CatalogItems; |         var root = (IQueryable<CatalogItem>)_catalogContext.CatalogItems; | ||||||
| @ -177,7 +173,6 @@ public class CatalogController : ControllerBase | |||||||
|     // GET api/v1/[controller]/CatalogTypes |     // GET api/v1/[controller]/CatalogTypes | ||||||
|     [HttpGet] |     [HttpGet] | ||||||
|     [Route("catalogtypes")] |     [Route("catalogtypes")] | ||||||
|     [ProducesResponseType(typeof(List<CatalogType>), (int)HttpStatusCode.OK)] |  | ||||||
|     public async Task<ActionResult<List<CatalogType>>> CatalogTypesAsync() |     public async Task<ActionResult<List<CatalogType>>> CatalogTypesAsync() | ||||||
|     { |     { | ||||||
|         return await _catalogContext.CatalogTypes.ToListAsync(); |         return await _catalogContext.CatalogTypes.ToListAsync(); | ||||||
| @ -186,7 +181,6 @@ public class CatalogController : ControllerBase | |||||||
|     // GET api/v1/[controller]/CatalogBrands |     // GET api/v1/[controller]/CatalogBrands | ||||||
|     [HttpGet] |     [HttpGet] | ||||||
|     [Route("catalogbrands")] |     [Route("catalogbrands")] | ||||||
|     [ProducesResponseType(typeof(List<CatalogBrand>), (int)HttpStatusCode.OK)] |  | ||||||
|     public async Task<ActionResult<List<CatalogBrand>>> CatalogBrandsAsync() |     public async Task<ActionResult<List<CatalogBrand>>> CatalogBrandsAsync() | ||||||
|     { |     { | ||||||
|         return await _catalogContext.CatalogBrands.ToListAsync(); |         return await _catalogContext.CatalogBrands.ToListAsync(); | ||||||
| @ -195,8 +189,8 @@ public class CatalogController : ControllerBase | |||||||
|     //PUT api/v1/[controller]/items |     //PUT api/v1/[controller]/items | ||||||
|     [Route("items")] |     [Route("items")] | ||||||
|     [HttpPut] |     [HttpPut] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.NotFound)] |     [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.Created)] |     [ProducesResponseType(StatusCodes.Status201Created)] | ||||||
|     public async Task<ActionResult> UpdateProductAsync([FromBody] CatalogItem productToUpdate) |     public async Task<ActionResult> UpdateProductAsync([FromBody] CatalogItem productToUpdate) | ||||||
|     { |     { | ||||||
|         var catalogItem = await _catalogContext.CatalogItems.SingleOrDefaultAsync(i => i.Id == productToUpdate.Id); |         var catalogItem = await _catalogContext.CatalogItems.SingleOrDefaultAsync(i => i.Id == productToUpdate.Id); | ||||||
| @ -235,7 +229,7 @@ public class CatalogController : ControllerBase | |||||||
|     //POST api/v1/[controller]/items |     //POST api/v1/[controller]/items | ||||||
|     [Route("items")] |     [Route("items")] | ||||||
|     [HttpPost] |     [HttpPost] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.Created)] |     [ProducesResponseType(StatusCodes.Status201Created)] | ||||||
|     public async Task<ActionResult> CreateProductAsync([FromBody] CatalogItem product) |     public async Task<ActionResult> CreateProductAsync([FromBody] CatalogItem product) | ||||||
|     { |     { | ||||||
|         var item = new CatalogItem |         var item = new CatalogItem | ||||||
| @ -258,8 +252,8 @@ public class CatalogController : ControllerBase | |||||||
|     //DELETE api/v1/[controller]/id |     //DELETE api/v1/[controller]/id | ||||||
|     [Route("{id}")] |     [Route("{id}")] | ||||||
|     [HttpDelete] |     [HttpDelete] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.NoContent)] |     [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.NotFound)] |     [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||||
|     public async Task<ActionResult> DeleteProductAsync(int id) |     public async Task<ActionResult> DeleteProductAsync(int id) | ||||||
|     { |     { | ||||||
|         var product = _catalogContext.CatalogItems.SingleOrDefault(x => x.Id == id); |         var product = _catalogContext.CatalogItems.SingleOrDefault(x => x.Id == id); | ||||||
|  | |||||||
| @ -6,7 +6,6 @@ global using System.Globalization; | |||||||
| global using System.IO; | global using System.IO; | ||||||
| global using System.IO.Compression; | global using System.IO.Compression; | ||||||
| global using System.Linq; | global using System.Linq; | ||||||
| global using System.Net; |  | ||||||
| global using System.Text.RegularExpressions; | global using System.Text.RegularExpressions; | ||||||
| global using System.Threading.Tasks; | global using System.Threading.Tasks; | ||||||
| global using Grpc.Core; | global using Grpc.Core; | ||||||
|  | |||||||
| @ -2,7 +2,6 @@ | |||||||
| using static CatalogApi.Catalog; | using static CatalogApi.Catalog; | ||||||
| 
 | 
 | ||||||
| namespace Microsoft.eShopOnContainers.Services.Catalog.API.Grpc; | namespace Microsoft.eShopOnContainers.Services.Catalog.API.Grpc; | ||||||
| using Microsoft.Extensions.Logging; |  | ||||||
| 
 | 
 | ||||||
| public class CatalogService : CatalogBase | public class CatalogService : CatalogBase | ||||||
| { | { | ||||||
|  | |||||||
| @ -1,9 +1,7 @@ | |||||||
| namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers; | using CardType = Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries.CardType; | ||||||
|  | using Order = Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries.Order; | ||||||
| 
 | 
 | ||||||
| using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions; | namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers; | ||||||
| using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; |  | ||||||
| using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries; |  | ||||||
| using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services; |  | ||||||
| 
 | 
 | ||||||
| [Route("api/v1/[controller]")]
 | [Route("api/v1/[controller]")]
 | ||||||
| [Authorize] | [Authorize] | ||||||
| @ -29,8 +27,8 @@ public class OrdersController : ControllerBase | |||||||
| 
 | 
 | ||||||
|     [Route("cancel")] |     [Route("cancel")] | ||||||
|     [HttpPut] |     [HttpPut] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.OK)] |     [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.BadRequest)] |     [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|     public async Task<IActionResult> CancelOrderAsync([FromBody] CancelOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId) |     public async Task<IActionResult> CancelOrderAsync([FromBody] CancelOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId) | ||||||
|     { |     { | ||||||
|         bool commandResult = false; |         bool commandResult = false; | ||||||
| @ -59,8 +57,8 @@ public class OrdersController : ControllerBase | |||||||
| 
 | 
 | ||||||
|     [Route("ship")] |     [Route("ship")] | ||||||
|     [HttpPut] |     [HttpPut] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.OK)] |     [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.BadRequest)] |     [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|     public async Task<IActionResult> ShipOrderAsync([FromBody] ShipOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId) |     public async Task<IActionResult> ShipOrderAsync([FromBody] ShipOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId) | ||||||
|     { |     { | ||||||
|         bool commandResult = false; |         bool commandResult = false; | ||||||
| @ -89,9 +87,9 @@ public class OrdersController : ControllerBase | |||||||
| 
 | 
 | ||||||
|     [Route("{orderId:int}")] |     [Route("{orderId:int}")] | ||||||
|     [HttpGet] |     [HttpGet] | ||||||
|     [ProducesResponseType(typeof(Order), (int)HttpStatusCode.OK)] |     [ProducesResponseType(typeof(Order), StatusCodes.Status200OK)] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.NotFound)] |     [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||||
|     public async Task<ActionResult> GetOrderAsync(int orderId) |     public async Task<ActionResult<Order>> GetOrderAsync(int orderId) | ||||||
|     { |     { | ||||||
|         try |         try | ||||||
|         { |         { | ||||||
| @ -99,7 +97,7 @@ public class OrdersController : ControllerBase | |||||||
|             //var order customer = await _mediator.Send(new GetOrderByIdQuery(orderId)); |             //var order customer = await _mediator.Send(new GetOrderByIdQuery(orderId)); | ||||||
|             var order = await _orderQueries.GetOrderAsync(orderId); |             var order = await _orderQueries.GetOrderAsync(orderId); | ||||||
| 
 | 
 | ||||||
|             return Ok(order); |             return order; | ||||||
|         } |         } | ||||||
|         catch |         catch | ||||||
|         { |         { | ||||||
| @ -108,7 +106,7 @@ public class OrdersController : ControllerBase | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     [HttpGet] |     [HttpGet] | ||||||
|     [ProducesResponseType(typeof(IEnumerable<OrderSummary>), (int)HttpStatusCode.OK)] |     [ProducesResponseType(typeof(IEnumerable<OrderSummary>), StatusCodes.Status200OK)] | ||||||
|     public async Task<ActionResult<IEnumerable<OrderSummary>>> GetOrdersAsync() |     public async Task<ActionResult<IEnumerable<OrderSummary>>> GetOrdersAsync() | ||||||
|     { |     { | ||||||
|         var userid = _identityService.GetUserIdentity(); |         var userid = _identityService.GetUserIdentity(); | ||||||
| @ -119,7 +117,7 @@ public class OrdersController : ControllerBase | |||||||
| 
 | 
 | ||||||
|     [Route("cardtypes")] |     [Route("cardtypes")] | ||||||
|     [HttpGet] |     [HttpGet] | ||||||
|     [ProducesResponseType(typeof(IEnumerable<CardType>), (int)HttpStatusCode.OK)] |     [ProducesResponseType(typeof(IEnumerable<CardType>), StatusCodes.Status200OK)] | ||||||
|     public async Task<ActionResult<IEnumerable<CardType>>> GetCardTypesAsync() |     public async Task<ActionResult<IEnumerable<CardType>>> GetCardTypesAsync() | ||||||
|     { |     { | ||||||
|         var cardTypes = await _orderQueries.GetCardTypesAsync(); |         var cardTypes = await _orderQueries.GetCardTypesAsync(); | ||||||
|  | |||||||
| @ -1,8 +1,5 @@ | |||||||
| namespace Microsoft.eShopOnContainers.Services.Ordering.API.Extensions; | namespace Microsoft.eShopOnContainers.Services.Ordering.API.Extensions; | ||||||
| 
 | 
 | ||||||
| using System.Collections.Generic; |  | ||||||
| using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Models; |  | ||||||
| 
 |  | ||||||
| public static class BasketItemExtensions | public static class BasketItemExtensions | ||||||
| { | { | ||||||
|     public static IEnumerable<OrderItemDTO> ToOrderItemsDTO(this IEnumerable<BasketItem> basketItems) |     public static IEnumerable<OrderItemDTO> ToOrderItemsDTO(this IEnumerable<BasketItem> basketItems) | ||||||
|  | |||||||
| @ -4,7 +4,6 @@ global using System.Data.Common; | |||||||
| global using System.Data.SqlClient; | global using System.Data.SqlClient; | ||||||
| global using System.IO; | global using System.IO; | ||||||
| global using System.Linq; | global using System.Linq; | ||||||
| global using System.Net; |  | ||||||
| global using System.Runtime.Serialization; | global using System.Runtime.Serialization; | ||||||
| global using System.Threading; | global using System.Threading; | ||||||
| global using System.Threading.Tasks; | global using System.Threading.Tasks; | ||||||
|  | |||||||
| @ -110,10 +110,10 @@ public class OrdersWebApiTest | |||||||
| 
 | 
 | ||||||
|         //Act |         //Act | ||||||
|         var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object, _loggerMock.Object); |         var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object, _loggerMock.Object); | ||||||
|         var actionResult = await orderController.GetOrderAsync(fakeOrderId) as OkObjectResult; |         var actionResult = await orderController.GetOrderAsync(fakeOrderId); | ||||||
| 
 | 
 | ||||||
|         //Assert |         //Assert | ||||||
|         Assert.Equal(actionResult.StatusCode, (int)System.Net.HttpStatusCode.OK); |         Assert.Same(actionResult.Value, fakeDynamicResult); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     [Fact] |     [Fact] | ||||||
|  | |||||||
| @ -17,7 +17,7 @@ public class WebhooksController : ControllerBase | |||||||
| 
 | 
 | ||||||
|     [Authorize] |     [Authorize] | ||||||
|     [HttpGet] |     [HttpGet] | ||||||
|     [ProducesResponseType(typeof(IEnumerable<WebhookSubscription>), (int)HttpStatusCode.OK)] |     [ProducesResponseType(typeof(IEnumerable<WebhookSubscription>), StatusCodes.Status200OK)] | ||||||
|     public async Task<IActionResult> ListByUser() |     public async Task<IActionResult> ListByUser() | ||||||
|     { |     { | ||||||
|         var userId = _identityService.GetUserIdentity(); |         var userId = _identityService.GetUserIdentity(); | ||||||
| @ -27,8 +27,8 @@ public class WebhooksController : ControllerBase | |||||||
| 
 | 
 | ||||||
|     [Authorize] |     [Authorize] | ||||||
|     [HttpGet("{id:int}")] |     [HttpGet("{id:int}")] | ||||||
|     [ProducesResponseType(typeof(WebhookSubscription), (int)HttpStatusCode.OK)] |     [ProducesResponseType(typeof(WebhookSubscription), StatusCodes.Status200OK)] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.NotFound)] |     [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||||
|     public async Task<IActionResult> GetByUserAndId(int id) |     public async Task<IActionResult> GetByUserAndId(int id) | ||||||
|     { |     { | ||||||
|         var userId = _identityService.GetUserIdentity(); |         var userId = _identityService.GetUserIdentity(); | ||||||
| @ -42,9 +42,9 @@ public class WebhooksController : ControllerBase | |||||||
| 
 | 
 | ||||||
|     [Authorize] |     [Authorize] | ||||||
|     [HttpPost] |     [HttpPost] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.Created)] |     [ProducesResponseType(StatusCodes.Status201Created)] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.BadRequest)] |     [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|     [ProducesResponseType(418)] |     [ProducesResponseType(StatusCodes.Status418ImATeapot)] | ||||||
|     public async Task<IActionResult> SubscribeWebhook(WebhookSubscriptionRequest request) |     public async Task<IActionResult> SubscribeWebhook(WebhookSubscriptionRequest request) | ||||||
|     { |     { | ||||||
|         if (!ModelState.IsValid) |         if (!ModelState.IsValid) | ||||||
| @ -71,14 +71,14 @@ public class WebhooksController : ControllerBase | |||||||
|         } |         } | ||||||
|         else |         else | ||||||
|         { |         { | ||||||
|             return StatusCode(418, "Grant url can't be validated"); |             return StatusCode(StatusCodes.Status418ImATeapot, "Grant URL invalid"); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     [Authorize] |     [Authorize] | ||||||
|     [HttpDelete("{id:int}")] |     [HttpDelete("{id:int}")] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.Accepted)] |     [ProducesResponseType(StatusCodes.Status202Accepted)] | ||||||
|     [ProducesResponseType((int)HttpStatusCode.NotFound)] |     [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||||
|     public async Task<IActionResult> UnsubscribeWebhook(int id) |     public async Task<IActionResult> UnsubscribeWebhook(int id) | ||||||
|     { |     { | ||||||
|         var userId = _identityService.GetUserIdentity(); |         var userId = _identityService.GetUserIdentity(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user