From 3b9560c26e1ce464e72b0417b23e79003399417f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 14 Jun 2023 20:56:52 -0700 Subject: [PATCH] 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> --- .../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, 47 insertions(+), 98 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 a3cf4f03c..03d744555 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 class BasketController : ControllerBase [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 class BasketController : ControllerBase [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 class BasketController : ControllerBase [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 5328f308d..000000000 --- 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 55b4dd70b..23c3df40d 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 class OrderController : ControllerBase [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 549873d8d..65efabf33 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.Models; 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 143ff9a2b..59550621b 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs @@ -16,8 +16,7 @@ public class BasketController : ControllerBase [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()) @@ -74,8 +73,7 @@ public class BasketController : ControllerBase [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()) @@ -109,8 +107,8 @@ public class BasketController : ControllerBase [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 448bbec85..b0b62c1e3 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 class OrderController : ControllerBase [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 9db883101..000000000 --- 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 b971c96e9..adb1f1f13 100644 --- a/src/Services/Basket/Basket.API/Controllers/BasketController.cs +++ b/src/Services/Basket/Basket.API/Controllers/BasketController.cs @@ -23,7 +23,6 @@ public class BasketController : ControllerBase } [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 class BasketController : ControllerBase } [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 class BasketController : ControllerBase [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 class BasketController : ControllerBase // 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 9a8376d4d..e66f8b36f 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 66dcd99c1..0679534ae 100644 --- a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs +++ b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs @@ -20,9 +20,9 @@ public class CatalogController : ControllerBase // GET api/v1/[controller]/items[?pageSize=3&pageIndex=10] [HttpGet] [Route("items")] - [ProducesResponseType(typeof(PaginatedItemsViewModel), (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 @@ public class CatalogController : ControllerBase [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 class CatalogController : ControllerBase // 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 class CatalogController : ControllerBase // 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 class CatalogController : ControllerBase // 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 class CatalogController : ControllerBase // 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 class CatalogController : ControllerBase // 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 class CatalogController : ControllerBase //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 class CatalogController : ControllerBase //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 class CatalogController : ControllerBase //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 e521114b2..43ebd0392 100644 --- a/src/Services/Catalog/Catalog.API/GlobalUsings.cs +++ b/src/Services/Catalog/Catalog.API/GlobalUsings.cs @@ -6,7 +6,6 @@ global using System.Globalization; 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 29913b086..61e56c314 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 5b9ca5f70..df7572bb7 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 class OrdersController : ControllerBase [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 class OrdersController : ControllerBase [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 class OrdersController : ControllerBase [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 class OrdersController : ControllerBase //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 class OrdersController : ControllerBase } [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 class OrdersController : ControllerBase [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 918780f4a..4e8ab1b15 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 70255b36a..d36189d2a 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.Common; 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 bb8f8844b..0235c94b6 100644 --- a/src/Services/Ordering/Ordering.UnitTests/Application/OrdersWebApiTest.cs +++ b/src/Services/Ordering/Ordering.UnitTests/Application/OrdersWebApiTest.cs @@ -110,10 +110,10 @@ public class OrdersWebApiTest //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 5f9513480..18c283256 100644 --- a/src/Services/Webhooks/Webhooks.API/Controllers/WebhooksController.cs +++ b/src/Services/Webhooks/Webhooks.API/Controllers/WebhooksController.cs @@ -17,7 +17,7 @@ public class WebhooksController : ControllerBase [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 class WebhooksController : ControllerBase [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 class WebhooksController : ControllerBase [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 class WebhooksController : ControllerBase } else { - return StatusCode(418, "Grant url can't be validated"); + return StatusCode(StatusCodes.Status418ImATeapot, "Grant URL invalid"); } } [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();