From cea48cb15120b89f56dec190bd06057d373aac02 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 14 Jun 2023 20:44:25 -0700 Subject: [PATCH 1/3] 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. --- .../Controllers/BasketController.cs | 10 +++---- .../aggregator/Controllers/HomeController.cs | 11 -------- .../aggregator/Controllers/OrderController.cs | 3 +- .../aggregator/GlobalUsings.cs | 10 ------- .../Controllers/BasketController.cs | 10 +++---- .../aggregator/Controllers/OrderController.cs | 3 +- .../Basket/Basket.API/BasketSettings.cs | 7 ----- .../Controllers/BasketController.cs | 8 ++---- .../Basket/Basket.API/GlobalUsings.cs | 1 - .../Controllers/CatalogController.cs | 26 +++++++---------- .../Catalog/Catalog.API/GlobalUsings.cs | 1 - .../Catalog.API/Grpc/CatalogService.cs | 1 - .../Controllers/OrdersController.cs | 28 +++++++++---------- .../Extensions/BasketItemExtensions.cs | 3 -- .../Ordering/Ordering.API/GlobalUsings.cs | 1 - .../Application/OrdersWebApiTest.cs | 4 +-- .../Controllers/WebhooksController.cs | 18 ++++++------ 17 files changed, 48 insertions(+), 97 deletions(-) delete mode 100644 src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/HomeController.cs delete mode 100644 src/Services/Basket/Basket.API/BasketSettings.cs diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/BasketController.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/BasketController.cs index a3cf4f03c6..03d744555e 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/BasketController.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/BasketController.cs @@ -16,8 +16,7 @@ public BasketController(ICatalogService catalogService, IBasketService basketSer [HttpPost] [HttpPut] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] - [ProducesResponseType(typeof(BasketData), (int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task> UpdateAllBasketAsync([FromBody] UpdateBasketRequest data) { if (data.Items == null || !data.Items.Any()) @@ -73,8 +72,7 @@ public async Task> UpdateAllBasketAsync([FromBody] Upda [HttpPut] [Route("items")] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] - [ProducesResponseType(typeof(BasketData), (int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task> UpdateQuantitiesAsync([FromBody] UpdateBasketItemsRequest data) { if (!data.Updates.Any()) @@ -110,8 +108,8 @@ public async Task> UpdateQuantitiesAsync([FromBody] Upd [HttpPost] [Route("items")] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status200OK)] public async Task AddBasketItemAsync([FromBody] AddBasketItemRequest data) { if (data == null || data.Quantity == 0) diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/HomeController.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/HomeController.cs deleted file mode 100644 index 5328f308d2..0000000000 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/HomeController.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers; - -[Route("")] -public class HomeController : Controller -{ - [HttpGet] - public IActionResult Index() - { - return new RedirectResult("~/swagger"); - } -} diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/OrderController.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/OrderController.cs index 55b4dd70b2..23c3df40d3 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/OrderController.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/OrderController.cs @@ -16,8 +16,7 @@ public OrderController(IBasketService basketService, IOrderingService orderingSe [Route("draft/{basketId}")] [HttpGet] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] - [ProducesResponseType(typeof(OrderData), (int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task> GetOrderDraftAsync(string basketId) { if (string.IsNullOrEmpty(basketId)) diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/GlobalUsings.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/GlobalUsings.cs index 549873d8d1..65efabf33c 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/GlobalUsings.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/GlobalUsings.cs @@ -2,12 +2,8 @@ global using Grpc.Core.Interceptors; global using Grpc.Core; 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.Builder; -global using Microsoft.AspNetCore.Diagnostics.HealthChecks; global using Microsoft.AspNetCore.Http; global using Microsoft.AspNetCore.Mvc; global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config; @@ -16,19 +12,13 @@ global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services; global using Microsoft.Extensions.Configuration; global using Microsoft.Extensions.DependencyInjection; -global using Microsoft.Extensions.Diagnostics.HealthChecks; global using Microsoft.Extensions.Logging; global using Microsoft.Extensions.Options; -global using Microsoft.OpenApi.Models; global using System.Collections.Generic; -global using System.IdentityModel.Tokens.Jwt; global using System.Linq; -global using System.Net.Http.Headers; global using System.Net.Http; global using System.Net; global using System.Text.Json; global using System.Threading.Tasks; -global using System.Threading; global using System; -global using Microsoft.IdentityModel.Tokens; global using Services.Common; diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs index 143ff9a2b0..f2915694ad 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs @@ -16,8 +16,8 @@ public BasketController(ICatalogService catalogService, IBasketService basketSer [HttpPost] [HttpPut] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] - [ProducesResponseType(typeof(BasketData), (int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(BasketData), StatusCodes.Status200OK)] public async Task> UpdateAllBasketAsync([FromBody] UpdateBasketRequest data) { if (data.Items == null || !data.Items.Any()) @@ -74,7 +74,7 @@ public async Task> UpdateAllBasketAsync([FromBody] Upda [HttpPut] [Route("items")] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(BasketData), (int)HttpStatusCode.OK)] public async Task> UpdateQuantitiesAsync([FromBody] UpdateBasketItemsRequest data) { @@ -109,8 +109,8 @@ public async Task> UpdateQuantitiesAsync([FromBody] Upd [HttpPost] [Route("items")] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status200OK)] public async Task AddBasketItemAsync([FromBody] AddBasketItemRequest data) { if (data == null || data.Quantity == 0) diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/OrderController.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/OrderController.cs index 448bbec858..b0b62c1e31 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/OrderController.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/OrderController.cs @@ -16,8 +16,7 @@ public OrderController(IBasketService basketService, IOrderingService orderingSe [Route("draft/{basketId}")] [HttpGet] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] - [ProducesResponseType(typeof(OrderData), (int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task> GetOrderDraftAsync(string basketId) { if (string.IsNullOrWhiteSpace(basketId)) diff --git a/src/Services/Basket/Basket.API/BasketSettings.cs b/src/Services/Basket/Basket.API/BasketSettings.cs deleted file mode 100644 index 9db8831016..0000000000 --- a/src/Services/Basket/Basket.API/BasketSettings.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Microsoft.eShopOnContainers.Services.Basket.API; - -public class BasketSettings -{ - public string ConnectionString { get; set; } -} - diff --git a/src/Services/Basket/Basket.API/Controllers/BasketController.cs b/src/Services/Basket/Basket.API/Controllers/BasketController.cs index b971c96e96..adb1f1f13c 100644 --- a/src/Services/Basket/Basket.API/Controllers/BasketController.cs +++ b/src/Services/Basket/Basket.API/Controllers/BasketController.cs @@ -23,7 +23,6 @@ public BasketController( } [HttpGet("{id}")] - [ProducesResponseType(typeof(CustomerBasket), (int)HttpStatusCode.OK)] public async Task> GetBasketByIdAsync(string id) { var basket = await _repository.GetBasketAsync(id); @@ -32,7 +31,6 @@ public async Task> GetBasketByIdAsync(string id) } [HttpPost] - [ProducesResponseType(typeof(CustomerBasket), (int)HttpStatusCode.OK)] public async Task> UpdateBasketAsync([FromBody] CustomerBasket value) { return Ok(await _repository.UpdateBasketAsync(value)); @@ -40,8 +38,8 @@ public async Task> UpdateBasketAsync([FromBody] Cus [Route("checkout")] [HttpPost] - [ProducesResponseType((int)HttpStatusCode.Accepted)] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] + [ProducesResponseType(StatusCodes.Status202Accepted)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task CheckoutAsync([FromBody] BasketCheckout basketCheckout, [FromHeader(Name = "x-requestid")] string requestId) { var userId = _identityService.GetUserIdentity(); @@ -81,7 +79,7 @@ public async Task CheckoutAsync([FromBody] BasketCheckout basketCh // DELETE api/values/5 [HttpDelete("{id}")] - [ProducesResponseType(typeof(void), (int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK)] public async Task DeleteBasketByIdAsync(string id) { await _repository.DeleteBasketAsync(id); diff --git a/src/Services/Basket/Basket.API/GlobalUsings.cs b/src/Services/Basket/Basket.API/GlobalUsings.cs index 9a8376d4d8..e66f8b36f0 100644 --- a/src/Services/Basket/Basket.API/GlobalUsings.cs +++ b/src/Services/Basket/Basket.API/GlobalUsings.cs @@ -2,7 +2,6 @@ global using System.Collections.Generic; global using System.ComponentModel.DataAnnotations; global using System.Linq; -global using System.Net; global using System.Security.Claims; global using System.Text.Json; global using System.Threading.Tasks; diff --git a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs index 66dcd99c14..0679534ae7 100644 --- a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs +++ b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs @@ -20,9 +20,9 @@ public CatalogController(CatalogContext context, IOptionsSnapshot), (int)HttpStatusCode.OK)] - [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] + [ProducesResponseType(typeof(PaginatedItemsViewModel), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task ItemsAsync([FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0, string ids = null) { if (!string.IsNullOrEmpty(ids)) @@ -74,9 +74,8 @@ private async Task> GetItemsByIdsAsync(string ids) [HttpGet] [Route("items/{id:int}")] - [ProducesResponseType((int)HttpStatusCode.NotFound)] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] - [ProducesResponseType(typeof(CatalogItem), (int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task> ItemByIdAsync(int id) { if (id <= 0) @@ -102,7 +101,6 @@ public async Task> ItemByIdAsync(int id) // GET api/v1/[controller]/items/withname/samplename[?pageSize=3&pageIndex=10] [HttpGet] [Route("items/withname/{name:minlength(1)}")] - [ProducesResponseType(typeof(PaginatedItemsViewModel), (int)HttpStatusCode.OK)] public async Task>> ItemsWithNameAsync(string name, [FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) { var totalItems = await _catalogContext.CatalogItems @@ -123,7 +121,6 @@ public async Task>> ItemsWithN // GET api/v1/[controller]/items/type/1/brand[?pageSize=3&pageIndex=10] [HttpGet] [Route("items/type/{catalogTypeId}/brand/{catalogBrandId:int?}")] - [ProducesResponseType(typeof(PaginatedItemsViewModel), (int)HttpStatusCode.OK)] public async Task>> ItemsByTypeIdAndBrandIdAsync(int catalogTypeId, int? catalogBrandId, [FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) { var root = (IQueryable)_catalogContext.CatalogItems; @@ -151,7 +148,6 @@ public async Task>> ItemsByTyp // GET api/v1/[controller]/items/type/all/brand[?pageSize=3&pageIndex=10] [HttpGet] [Route("items/type/all/brand/{catalogBrandId:int?}")] - [ProducesResponseType(typeof(PaginatedItemsViewModel), (int)HttpStatusCode.OK)] public async Task>> ItemsByBrandIdAsync(int? catalogBrandId, [FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) { var root = (IQueryable)_catalogContext.CatalogItems; @@ -177,7 +173,6 @@ public async Task>> ItemsByBra // GET api/v1/[controller]/CatalogTypes [HttpGet] [Route("catalogtypes")] - [ProducesResponseType(typeof(List), (int)HttpStatusCode.OK)] public async Task>> CatalogTypesAsync() { return await _catalogContext.CatalogTypes.ToListAsync(); @@ -186,7 +181,6 @@ public async Task>> CatalogTypesAsync() // GET api/v1/[controller]/CatalogBrands [HttpGet] [Route("catalogbrands")] - [ProducesResponseType(typeof(List), (int)HttpStatusCode.OK)] public async Task>> CatalogBrandsAsync() { return await _catalogContext.CatalogBrands.ToListAsync(); @@ -195,8 +189,8 @@ public async Task>> CatalogBrandsAsync() //PUT api/v1/[controller]/items [Route("items")] [HttpPut] - [ProducesResponseType((int)HttpStatusCode.NotFound)] - [ProducesResponseType((int)HttpStatusCode.Created)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status201Created)] public async Task UpdateProductAsync([FromBody] CatalogItem productToUpdate) { var catalogItem = await _catalogContext.CatalogItems.SingleOrDefaultAsync(i => i.Id == productToUpdate.Id); @@ -235,7 +229,7 @@ public async Task UpdateProductAsync([FromBody] CatalogItem produc //POST api/v1/[controller]/items [Route("items")] [HttpPost] - [ProducesResponseType((int)HttpStatusCode.Created)] + [ProducesResponseType(StatusCodes.Status201Created)] public async Task CreateProductAsync([FromBody] CatalogItem product) { var item = new CatalogItem @@ -258,8 +252,8 @@ public async Task CreateProductAsync([FromBody] CatalogItem produc //DELETE api/v1/[controller]/id [Route("{id}")] [HttpDelete] - [ProducesResponseType((int)HttpStatusCode.NoContent)] - [ProducesResponseType((int)HttpStatusCode.NotFound)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task DeleteProductAsync(int id) { var product = _catalogContext.CatalogItems.SingleOrDefault(x => x.Id == id); diff --git a/src/Services/Catalog/Catalog.API/GlobalUsings.cs b/src/Services/Catalog/Catalog.API/GlobalUsings.cs index e521114b23..43ebd03927 100644 --- a/src/Services/Catalog/Catalog.API/GlobalUsings.cs +++ b/src/Services/Catalog/Catalog.API/GlobalUsings.cs @@ -6,7 +6,6 @@ global using System.IO; global using System.IO.Compression; global using System.Linq; -global using System.Net; global using System.Text.RegularExpressions; global using System.Threading.Tasks; global using Grpc.Core; diff --git a/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs b/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs index 29913b086b..61e56c3148 100644 --- a/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs +++ b/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs @@ -2,7 +2,6 @@ using static CatalogApi.Catalog; namespace Microsoft.eShopOnContainers.Services.Catalog.API.Grpc; -using Microsoft.Extensions.Logging; public class CatalogService : CatalogBase { diff --git a/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs b/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs index 5b9ca5f702..df7572bb7f 100644 --- a/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs +++ b/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs @@ -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; -using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; -using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries; -using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services; +namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers; [Route("api/v1/[controller]")] [Authorize] @@ -29,8 +27,8 @@ public OrdersController( [Route("cancel")] [HttpPut] - [ProducesResponseType((int)HttpStatusCode.OK)] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task CancelOrderAsync([FromBody] CancelOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId) { bool commandResult = false; @@ -59,8 +57,8 @@ public async Task CancelOrderAsync([FromBody] CancelOrderCommand [Route("ship")] [HttpPut] - [ProducesResponseType((int)HttpStatusCode.OK)] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task ShipOrderAsync([FromBody] ShipOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId) { bool commandResult = false; @@ -89,9 +87,9 @@ public async Task ShipOrderAsync([FromBody] ShipOrderCommand comm [Route("{orderId:int}")] [HttpGet] - [ProducesResponseType(typeof(Order), (int)HttpStatusCode.OK)] - [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task GetOrderAsync(int orderId) + [ProducesResponseType(typeof(Order), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task> GetOrderAsync(int orderId) { try { @@ -99,7 +97,7 @@ public async Task GetOrderAsync(int orderId) //var order customer = await _mediator.Send(new GetOrderByIdQuery(orderId)); var order = await _orderQueries.GetOrderAsync(orderId); - return Ok(order); + return order; } catch { @@ -108,7 +106,7 @@ public async Task GetOrderAsync(int orderId) } [HttpGet] - [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] public async Task>> GetOrdersAsync() { var userid = _identityService.GetUserIdentity(); @@ -119,7 +117,7 @@ public async Task>> GetOrdersAsync() [Route("cardtypes")] [HttpGet] - [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] public async Task>> GetCardTypesAsync() { var cardTypes = await _orderQueries.GetCardTypesAsync(); diff --git a/src/Services/Ordering/Ordering.API/Extensions/BasketItemExtensions.cs b/src/Services/Ordering/Ordering.API/Extensions/BasketItemExtensions.cs index 918780f4ae..4e8ab1b15f 100644 --- a/src/Services/Ordering/Ordering.API/Extensions/BasketItemExtensions.cs +++ b/src/Services/Ordering/Ordering.API/Extensions/BasketItemExtensions.cs @@ -1,8 +1,5 @@ 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 IEnumerable ToOrderItemsDTO(this IEnumerable basketItems) diff --git a/src/Services/Ordering/Ordering.API/GlobalUsings.cs b/src/Services/Ordering/Ordering.API/GlobalUsings.cs index 70255b36ac..d36189d2a6 100644 --- a/src/Services/Ordering/Ordering.API/GlobalUsings.cs +++ b/src/Services/Ordering/Ordering.API/GlobalUsings.cs @@ -4,7 +4,6 @@ global using System.Data.SqlClient; global using System.IO; global using System.Linq; -global using System.Net; global using System.Runtime.Serialization; global using System.Threading; global using System.Threading.Tasks; diff --git a/src/Services/Ordering/Ordering.UnitTests/Application/OrdersWebApiTest.cs b/src/Services/Ordering/Ordering.UnitTests/Application/OrdersWebApiTest.cs index bb8f8844bf..0235c94b62 100644 --- a/src/Services/Ordering/Ordering.UnitTests/Application/OrdersWebApiTest.cs +++ b/src/Services/Ordering/Ordering.UnitTests/Application/OrdersWebApiTest.cs @@ -110,10 +110,10 @@ public async Task Get_order_success() //Act 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.Equal(actionResult.StatusCode, (int)System.Net.HttpStatusCode.OK); + Assert.Same(actionResult.Value, fakeDynamicResult); } [Fact] diff --git a/src/Services/Webhooks/Webhooks.API/Controllers/WebhooksController.cs b/src/Services/Webhooks/Webhooks.API/Controllers/WebhooksController.cs index 5f9513480f..d403a6a74a 100644 --- a/src/Services/Webhooks/Webhooks.API/Controllers/WebhooksController.cs +++ b/src/Services/Webhooks/Webhooks.API/Controllers/WebhooksController.cs @@ -17,7 +17,7 @@ public WebhooksController(WebhooksContext dbContext, IIdentityService identitySe [Authorize] [HttpGet] - [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] public async Task ListByUser() { var userId = _identityService.GetUserIdentity(); @@ -27,8 +27,8 @@ public async Task ListByUser() [Authorize] [HttpGet("{id:int}")] - [ProducesResponseType(typeof(WebhookSubscription), (int)HttpStatusCode.OK)] - [ProducesResponseType((int)HttpStatusCode.NotFound)] + [ProducesResponseType(typeof(WebhookSubscription), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task GetByUserAndId(int id) { var userId = _identityService.GetUserIdentity(); @@ -42,9 +42,9 @@ public async Task GetByUserAndId(int id) [Authorize] [HttpPost] - [ProducesResponseType((int)HttpStatusCode.Created)] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] - [ProducesResponseType(418)] + [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status418ImATeapot)] public async Task SubscribeWebhook(WebhookSubscriptionRequest request) { if (!ModelState.IsValid) @@ -71,14 +71,14 @@ public async Task SubscribeWebhook(WebhookSubscriptionRequest req } else { - return StatusCode(418, "Grant url can't be validated"); + return StatusCode(StatusCodes.Status418ImATeapot, "Grant url can't be validated"); } } [Authorize] [HttpDelete("{id:int}")] - [ProducesResponseType((int)HttpStatusCode.Accepted)] - [ProducesResponseType((int)HttpStatusCode.NotFound)] + [ProducesResponseType(StatusCodes.Status202Accepted)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task UnsubscribeWebhook(int id) { var userId = _identityService.GetUserIdentity(); From 44345135b90c17be6b37f7f1d42bb6298447a263 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 14 Jun 2023 20:46:08 -0700 Subject: [PATCH 2/3] Forgot one --- .../Web.Bff.Shopping/aggregator/Controllers/BasketController.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs index f2915694ad..59550621b4 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs @@ -17,7 +17,6 @@ public BasketController(ICatalogService catalogService, IBasketService basketSer [HttpPost] [HttpPut] [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(typeof(BasketData), StatusCodes.Status200OK)] public async Task> UpdateAllBasketAsync([FromBody] UpdateBasketRequest data) { if (data.Items == null || !data.Items.Any()) @@ -75,7 +74,6 @@ public async Task> UpdateAllBasketAsync([FromBody] Upda [HttpPut] [Route("items")] [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(typeof(BasketData), (int)HttpStatusCode.OK)] public async Task> UpdateQuantitiesAsync([FromBody] UpdateBasketItemsRequest data) { if (!data.Updates.Any()) From 1d6ec6cf4523ab295709a534e44c0510ad35ec9b Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 14 Jun 2023 20:55:31 -0700 Subject: [PATCH 3/3] Update src/Services/Webhooks/Webhooks.API/Controllers/WebhooksController.cs Co-authored-by: Reuben Bond <203839+ReubenBond@users.noreply.github.com> --- .../Webhooks/Webhooks.API/Controllers/WebhooksController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/Webhooks/Webhooks.API/Controllers/WebhooksController.cs b/src/Services/Webhooks/Webhooks.API/Controllers/WebhooksController.cs index d403a6a74a..18c283256b 100644 --- a/src/Services/Webhooks/Webhooks.API/Controllers/WebhooksController.cs +++ b/src/Services/Webhooks/Webhooks.API/Controllers/WebhooksController.cs @@ -71,7 +71,7 @@ public async Task SubscribeWebhook(WebhookSubscriptionRequest req } else { - return StatusCode(StatusCodes.Status418ImATeapot, "Grant url can't be validated"); + return StatusCode(StatusCodes.Status418ImATeapot, "Grant URL invalid"); } }