Browse Source

add features api

pull/851/head
Erik Pique 6 years ago
parent
commit
deb3d38ebe
25 changed files with 170 additions and 151 deletions
  1. +9
    -7
      src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/BasketController.cs
  2. +2
    -4
      src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/OrderController.cs
  3. +9
    -2
      src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs
  4. +9
    -6
      src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs
  5. +5
    -4
      src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/OrderController.cs
  6. +9
    -2
      src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs
  7. +9
    -10
      src/Services/Basket/Basket.API/Controllers/BasketController.cs
  8. +7
    -4
      src/Services/Basket/Basket.API/Startup.cs
  9. +4
    -4
      src/Services/Basket/Basket.UnitTests/Application/BasketWebApiTest.cs
  10. +17
    -33
      src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs
  11. +4
    -3
      src/Services/Catalog/Catalog.API/Controllers/PicController.cs
  12. +5
    -3
      src/Services/Catalog/Catalog.API/Startup.cs
  13. +4
    -1
      src/Services/Identity/Identity.API/Startup.cs
  14. +9
    -11
      src/Services/Location/Locations.API/Controllers/LocationsController.cs
  15. +6
    -3
      src/Services/Location/Locations.API/Startup.cs
  16. +12
    -19
      src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs
  17. +8
    -12
      src/Services/Marketing/Marketing.API/Controllers/LocationsController.cs
  18. +3
    -3
      src/Services/Marketing/Marketing.API/Controllers/PicController.cs
  19. +4
    -1
      src/Services/Marketing/Marketing.API/Startup.cs
  20. +7
    -9
      src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs
  21. +5
    -3
      src/Services/Ordering/Ordering.API/Startup.cs
  22. +4
    -4
      src/Services/Ordering/Ordering.UnitTests/Application/OrdersWebApiTest.cs
  23. +5
    -1
      src/Web/WebMVC/Startup.cs
  24. +7
    -0
      src/Web/WebSPA/Startup.cs
  25. +7
    -2
      src/Web/WebStatus/Startup.cs

+ 9
- 7
src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/BasketController.cs View File

@ -11,7 +11,8 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
{
[Route("api/v1/[controller]")]
[Authorize]
public class BasketController : Controller
[ApiController]
public class BasketController : ControllerBase
{
private readonly ICatalogService _catalog;
private readonly IBasketService _basket;
@ -23,7 +24,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
[HttpPost]
[HttpPut]
public async Task<IActionResult> UpdateAllBasket([FromBody] UpdateBasketRequest data)
public async Task<ActionResult<BasketData>> UpdateAllBasket([FromBody] UpdateBasketRequest data)
{
if (data.Items == null || !data.Items.Any())
@ -61,12 +62,13 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
}
await _basket.Update(newBasket);
return Ok(newBasket);
return newBasket;
}
[HttpPut]
[Route("items")]
public async Task<IActionResult> UpdateQuantities([FromBody] UpdateBasketItemsRequest data)
public async Task<ActionResult<BasketData>> UpdateQuantities([FromBody] UpdateBasketItemsRequest data)
{
if (!data.Updates.Any())
{
@ -93,12 +95,13 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
// Save the updated basket
await _basket.Update(currentBasket);
return Ok(currentBasket);
return currentBasket;
}
[HttpPost]
[Route("items")]
public async Task<IActionResult> AddBasketItem([FromBody] AddBasketItemRequest data)
public async Task<ActionResult> AddBasketItem([FromBody] AddBasketItemRequest data)
{
if (data == null || data.Quantity == 0)
{
@ -126,7 +129,6 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
// Step 4: Update basket
await _basket.Update(currentBasket);
return Ok();
}
}


+ 2
- 4
src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/OrderController.cs View File

@ -1,16 +1,14 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
{
[Route("api/v1/[controller]")]
[Authorize]
public class OrderController : Controller
[ApiController]
public class OrderController : ControllerBase
{
private readonly IBasketService _basketService;
private readonly IOrderApiClient _orderClient;


+ 9
- 2
src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs View File

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config;
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Filters.Basket.API.Infrastructure.Filters;
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastructure;
@ -53,9 +54,14 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseAuthentication();
app.UseHttpsRedirection();
app.UseMvc();
app.UseSwagger().UseSwaggerUI(c =>
@ -77,7 +83,8 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
services.AddOptions();
services.Configure<UrlsConfig>(configuration.GetSection("urls"));
services.AddMvc();
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddSwaggerGen(options =>
{


+ 9
- 6
src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs View File

@ -11,7 +11,8 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
{
[Route("api/v1/[controller]")]
[Authorize]
public class BasketController : Controller
[ApiController]
public class BasketController : ControllerBase
{
private readonly ICatalogService _catalog;
private readonly IBasketService _basket;
@ -23,7 +24,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
[HttpPost]
[HttpPut]
public async Task<IActionResult> UpdateAllBasket([FromBody] UpdateBasketRequest data)
public async Task<ActionResult<BasketData>> UpdateAllBasket([FromBody] UpdateBasketRequest data)
{
if (data.Items == null || !data.Items.Any())
@ -61,12 +62,13 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
}
await _basket.Update(newBasket);
return Ok(newBasket);
return newBasket;
}
[HttpPut]
[Route("items")]
public async Task<IActionResult> UpdateQuantities([FromBody] UpdateBasketItemsRequest data)
public async Task<ActionResult<BasketData>> UpdateQuantities([FromBody] UpdateBasketItemsRequest data)
{
if (!data.Updates.Any())
{
@ -93,12 +95,13 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
// Save the updated basket
await _basket.Update(currentBasket);
return Ok(currentBasket);
return currentBasket;
}
[HttpPost]
[Route("items")]
public async Task<IActionResult> AddBasketItem([FromBody] AddBasketItemRequest data)
public async Task<ActionResult> AddBasketItem([FromBody] AddBasketItemRequest data)
{
if (data == null || data.Quantity == 0)
{


+ 5
- 4
src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/OrderController.cs View File

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
using System;
using System.Collections.Generic;
@ -10,7 +11,8 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
{
[Route("api/v1/[controller]")]
[Authorize]
public class OrderController : Controller
[ApiController]
public class OrderController : ControllerBase
{
private readonly IBasketService _basketService;
private readonly IOrderApiClient _orderClient;
@ -22,7 +24,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
[Route("draft/{basketId}")]
[HttpGet]
public async Task<IActionResult> GetOrderDraft(string basketId)
public async Task<ActionResult<OrderData>> GetOrderDraft(string basketId)
{
if (string.IsNullOrEmpty(basketId))
{
@ -35,8 +37,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
return BadRequest($"No basket found for id {basketId}");
}
var orderDraft = await _orderClient.GetOrderDraftFromBasket(basket);
return Ok(orderDraft);
return await _orderClient.GetOrderDraftFromBasket(basket);
}
}
}

+ 9
- 2
src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs View File

@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config;
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Filters.Basket.API.Infrastructure.Filters;
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure;
@ -53,9 +54,14 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseAuthentication();
app.UseHttpsRedirection();
app.UseMvc();
app.UseSwagger().UseSwaggerUI(c =>
@ -104,7 +110,8 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
services.AddOptions();
services.Configure<UrlsConfig>(configuration.GetSection("urls"));
services.AddMvc();
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddSwaggerGen(options =>
{


+ 9
- 10
src/Services/Basket/Basket.API/Controllers/BasketController.cs View File

@ -13,7 +13,8 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
{
[Route("api/v1/[controller]")]
[Authorize]
public class BasketController : Controller
[ApiController]
public class BasketController : ControllerBase
{
private readonly IBasketRepository _repository;
private readonly IIdentityService _identitySvc;
@ -31,32 +32,31 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
// GET /id
[HttpGet("{id}")]
[ProducesResponseType(typeof(CustomerBasket), (int)HttpStatusCode.OK)]
public async Task<IActionResult> Get(string id)
public async Task<ActionResult<CustomerBasket>> Get(string id)
{
var basket = await _repository.GetBasketAsync(id);
if (basket == null)
{
return Ok(new CustomerBasket(id) { });
return new CustomerBasket(id);
}
return Ok(basket);
return basket;
}
// POST /value
[HttpPost]
[ProducesResponseType(typeof(CustomerBasket), (int)HttpStatusCode.OK)]
public async Task<IActionResult> Post([FromBody]CustomerBasket value)
public async Task<ActionResult<CustomerBasket>> Post([FromBody]CustomerBasket value)
{
var basket = await _repository.UpdateBasketAsync(value);
return Ok(basket);
return await _repository.UpdateBasketAsync(value);
}
[Route("checkout")]
[HttpPost]
[ProducesResponseType((int)HttpStatusCode.Accepted)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
public async Task<IActionResult> Checkout([FromBody]BasketCheckout basketCheckout, [FromHeader(Name = "x-requestid")] string requestId)
public async Task<ActionResult> Checkout([FromBody]BasketCheckout basketCheckout, [FromHeader(Name = "x-requestid")] string requestId)
{
var userId = _identitySvc.GetUserIdentity();
@ -91,6 +91,5 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
{
_repository.DeleteBasketAsync(id);
}
}
}

+ 7
- 4
src/Services/Basket/Basket.API/Startup.cs View File

@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.ServiceBus;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
@ -51,11 +52,13 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
// Add framework services.
services.AddMvc(options =>
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
options.Filters.Add(typeof(ValidateModelStateFilter));
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
options.Filters.Add(typeof(ValidateModelStateFilter));
}).AddControllersAsServices();
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddControllersAsServices();
ConfigureAuthService(services);


+ 4
- 4
src/Services/Basket/Basket.UnitTests/Application/BasketWebApiTest.cs View File

@ -44,10 +44,10 @@ namespace UnitTest.Basket.Application
//Act
var basketController = new BasketController(
_basketRepositoryMock.Object, _identityServiceMock.Object, _serviceBusMock.Object);
var actionResult = await basketController.Get(fakeCustomerId) as OkObjectResult;
var actionResult = await basketController.Get(fakeCustomerId);
//Assert
Assert.Equal(actionResult.StatusCode, (int)System.Net.HttpStatusCode.OK);
Assert.Equal((actionResult.Result as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK);
Assert.Equal(((CustomerBasket)actionResult.Value).BuyerId, fakeCustomerId);
}
@ -67,10 +67,10 @@ namespace UnitTest.Basket.Application
var basketController = new BasketController(
_basketRepositoryMock.Object, _identityServiceMock.Object, _serviceBusMock.Object);
var actionResult = await basketController.Post(fakeCustomerBasket) as OkObjectResult;
var actionResult = await basketController.Post(fakeCustomerBasket);
//Assert
Assert.Equal(actionResult.StatusCode, (int)System.Net.HttpStatusCode.OK);
Assert.Equal((actionResult.Result as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK);
Assert.Equal(((CustomerBasket)actionResult.Value).BuyerId, fakeCustomerId);
}


+ 17
- 33
src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs View File

@ -84,7 +84,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
[Route("items/{id:int}")]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType(typeof(CatalogItem), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetItemById(int id)
public async Task<ActionResult<CatalogItem>> GetItemById(int id)
{
if (id <= 0)
{
@ -99,7 +99,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
if (item != null)
{
return Ok(item);
return item;
}
return NotFound();
@ -109,9 +109,8 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
[HttpGet]
[Route("[action]/withname/{name:minlength(1)}")]
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> Items(string name, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> Items(string name, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
{
var totalItems = await _catalogContext.CatalogItems
.Where(c => c.Name.StartsWith(name))
.LongCountAsync();
@ -124,17 +123,14 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
itemsOnPage = ChangeUriPlaceholder(itemsOnPage);
var model = new PaginatedItemsViewModel<CatalogItem>(
pageIndex, pageSize, totalItems, itemsOnPage);
return Ok(model);
return new PaginatedItemsViewModel<CatalogItem>(pageIndex, pageSize, totalItems, itemsOnPage);
}
// GET api/v1/[controller]/items/type/1/brand[?pageSize=3&pageIndex=10]
[HttpGet]
[Route("[action]/type/{catalogTypeId}/brand/{catalogBrandId:int?}")]
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> Items(int catalogTypeId, int? catalogBrandId, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> Items(int catalogTypeId, int? catalogBrandId, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
{
var root = (IQueryable<CatalogItem>)_catalogContext.CatalogItems;
@ -155,16 +151,13 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
itemsOnPage = ChangeUriPlaceholder(itemsOnPage);
var model = new PaginatedItemsViewModel<CatalogItem>(
pageIndex, pageSize, totalItems, itemsOnPage);
return Ok(model);
return new PaginatedItemsViewModel<CatalogItem>(pageIndex, pageSize, totalItems, itemsOnPage);
}
// GET api/v1/[controller]/items/type/all/brand[?pageSize=3&pageIndex=10]
[HttpGet]
[Route("[action]/type/all/brand/{catalogBrandId:int?}")]
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> Items(int? catalogBrandId, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> Items(int? catalogBrandId, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
{
var root = (IQueryable<CatalogItem>)_catalogContext.CatalogItems;
@ -183,34 +176,25 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
itemsOnPage = ChangeUriPlaceholder(itemsOnPage);
var model = new PaginatedItemsViewModel<CatalogItem>(
pageIndex, pageSize, totalItems, itemsOnPage);
return Ok(model);
return new PaginatedItemsViewModel<CatalogItem>(pageIndex, pageSize, totalItems, itemsOnPage);
}
// GET api/v1/[controller]/CatalogTypes
[HttpGet]
[Route("[action]")]
[ProducesResponseType(typeof(List<CatalogItem>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> CatalogTypes()
[ProducesResponseType(typeof(List<CatalogType>), (int)HttpStatusCode.OK)]
public async Task<ActionResult<List<CatalogType>>> CatalogTypes()
{
var items = await _catalogContext.CatalogTypes
.ToListAsync();
return Ok(items);
return await _catalogContext.CatalogTypes.ToListAsync();
}
// GET api/v1/[controller]/CatalogBrands
[HttpGet]
[Route("[action]")]
[ProducesResponseType(typeof(List<CatalogItem>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> CatalogBrands()
[ProducesResponseType(typeof(List<CatalogBrand>), (int)HttpStatusCode.OK)]
public async Task<ActionResult<List<CatalogBrand>>> CatalogBrands()
{
var items = await _catalogContext.CatalogBrands
.ToListAsync();
return Ok(items);
return await _catalogContext.CatalogBrands.ToListAsync();
}
//PUT api/v1/[controller]/items
@ -218,7 +202,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
[HttpPut]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType((int)HttpStatusCode.Created)]
public async Task<IActionResult> UpdateProduct([FromBody]CatalogItem productToUpdate)
public async Task<ActionResult> UpdateProduct([FromBody]CatalogItem productToUpdate)
{
var catalogItem = await _catalogContext.CatalogItems
.SingleOrDefaultAsync(i => i.Id == productToUpdate.Id);
@ -259,7 +243,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
[Route("items")]
[HttpPost]
[ProducesResponseType((int)HttpStatusCode.Created)]
public async Task<IActionResult> CreateProduct([FromBody]CatalogItem product)
public async Task<ActionResult> CreateProduct([FromBody]CatalogItem product)
{
var item = new CatalogItem
{
@ -281,7 +265,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
[Route("{id}")]
[HttpDelete]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
public async Task<IActionResult> DeleteProduct(int id)
public async Task<ActionResult> DeleteProduct(int id)
{
var product = _catalogContext.CatalogItems.SingleOrDefault(x => x.Id == id);


+ 4
- 3
src/Services/Catalog/Catalog.API/Controllers/PicController.cs View File

@ -9,8 +9,9 @@ using System.Threading.Tasks;
// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
{
public class PicController : Controller
{
[ApiController]
public class PicController : ControllerBase
{
private readonly IHostingEnvironment _env;
private readonly CatalogContext _catalogContext;
@ -27,7 +28,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
// GET: /<controller>/
public async Task<IActionResult> GetImage(int catalogItemId)
public async Task<ActionResult> GetImage(int catalogItemId)
{
if (catalogItemId <= 0)
{


+ 5
- 3
src/Services/Catalog/Catalog.API/Startup.cs View File

@ -139,9 +139,11 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
});
services.AddMvc(options =>
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
}).AddControllersAsServices();
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddControllersAsServices();
services.AddCors(options =>
{


+ 4
- 1
src/Services/Identity/Identity.API/Startup.cs View File

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.eShopOnContainers.Services.Identity.API.Certificates;
using Microsoft.eShopOnContainers.Services.Identity.API.Data;
@ -52,7 +53,8 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API
services.Configure<AppSettings>(Configuration);
services.AddMvc();
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
if (Configuration.GetValue<string>("IsClusterEnv") == bool.TrueString)
{
@ -159,6 +161,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API
// Adds IdentityServer
app.UseIdentityServer();
app.UseHttpsRedirection();
app.UseMvc(routes =>
{
routes.MapRoute(


+ 9
- 11
src/Services/Location/Locations.API/Controllers/LocationsController.cs View File

@ -12,6 +12,7 @@ namespace Locations.API.Controllers
{
[Route("api/v1/[controller]")]
[Authorize]
[ApiController]
public class LocationsController : ControllerBase
{
private readonly ILocationsService _locationsService;
@ -27,30 +28,27 @@ namespace Locations.API.Controllers
[Route("user/{userId:guid}")]
[HttpGet]
[ProducesResponseType(typeof(UserLocation), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetUserLocation(Guid userId)
public async Task<ActionResult<UserLocation>> GetUserLocation(Guid userId)
{
var userLocation = await _locationsService.GetUserLocation(userId.ToString());
return Ok(userLocation);
return await _locationsService.GetUserLocation(userId.ToString());
}
//GET api/v1/[controller]/
[Route("")]
[HttpGet]
//[ProducesResponseType(typeof(List<Locations>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetAllLocations()
[ProducesResponseType(typeof(List<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>), (int)HttpStatusCode.OK)]
public async Task<ActionResult<List<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>>> GetAllLocations()
{
var locations = await _locationsService.GetAllLocation();
return Ok(locations);
return await _locationsService.GetAllLocation();
}
//GET api/v1/[controller]/1
[Route("{locationId}")]
[HttpGet]
//[ProducesResponseType(typeof(List<Locations>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetLocation(int locationId)
[ProducesResponseType(typeof(Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations), (int)HttpStatusCode.OK)]
public async Task<ActionResult<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>> GetLocation(int locationId)
{
var location = await _locationsService.GetLocation(locationId);
return Ok(location);
return await _locationsService.GetLocation(locationId);
}
//POST api/v1/[controller]/


+ 6
- 3
src/Services/Location/Locations.API/Startup.cs View File

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.ServiceBus;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
@ -43,9 +44,11 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
RegisterAppInsights(services);
services.AddMvc(options =>
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
}).AddControllersAsServices();
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddControllersAsServices();
ConfigureAuthService(services);


+ 12
- 19
src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs View File

@ -20,7 +20,8 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
[Route("api/v1/[controller]")]
[Authorize]
public class CampaignsController : Controller
[ApiController]
public class CampaignsController : ControllerBase
{
private readonly MarketingContext _context;
private readonly MarketingSettings _settings;
@ -40,25 +41,22 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
[HttpGet]
[ProducesResponseType(typeof(List<CampaignDTO>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetAllCampaigns()
public async Task<ActionResult<List<CampaignDTO>>> GetAllCampaigns()
{
var campaignList = await _context.Campaigns
.ToListAsync();
var campaignList = await _context.Campaigns.ToListAsync();
if (campaignList is null)
{
return Ok();
}
var campaignDtoList = MapCampaignModelListToDtoList(campaignList);
return Ok(campaignDtoList);
return MapCampaignModelListToDtoList(campaignList);
}
[HttpGet("{id:int}")]
[ProducesResponseType(typeof(CampaignDTO), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> GetCampaignById(int id)
public async Task<ActionResult<CampaignDTO>> GetCampaignById(int id)
{
var campaign = await _context.Campaigns
.SingleOrDefaultAsync(c => c.Id == id);
@ -68,15 +66,13 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
return NotFound();
}
var campaignDto = MapCampaignModelToDto(campaign);
return Ok(campaignDto);
return MapCampaignModelToDto(campaign);
}
[HttpPost]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.Created)]
public async Task<IActionResult> CreateCampaign([FromBody] CampaignDTO campaignDto)
public async Task<ActionResult> CreateCampaign([FromBody] CampaignDTO campaignDto)
{
if (campaignDto is null)
{
@ -95,7 +91,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType((int)HttpStatusCode.Created)]
public async Task<IActionResult> UpdateCampaign(int id, [FromBody] CampaignDTO campaignDto)
public async Task<ActionResult> UpdateCampaign(int id, [FromBody] CampaignDTO campaignDto)
{
if (id < 1 || campaignDto is null)
{
@ -123,7 +119,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
public async Task<IActionResult> Delete(int id)
public async Task<ActionResult> Delete(int id)
{
if (id < 1)
{
@ -144,7 +140,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
[HttpGet("user")]
[ProducesResponseType(typeof(PaginatedItemsViewModel<CampaignDTO>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetCampaignsByUserId( int pageSize = 10, int pageIndex = 0)
public async Task<ActionResult<PaginatedItemsViewModel<CampaignDTO>>> GetCampaignsByUserId( int pageSize = 10, int pageIndex = 0)
{
var userId = _identityService.GetUserIdentity();
@ -177,10 +173,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
.Skip(pageSize * pageIndex)
.Take(pageSize).ToList();
var model = new PaginatedItemsViewModel<CampaignDTO>(
pageIndex, pageSize, totalItems, campaignDtoList);
return Ok(model);
return new PaginatedItemsViewModel<CampaignDTO>(pageIndex, pageSize, totalItems, campaignDtoList);
}


+ 8
- 12
src/Services/Marketing/Marketing.API/Controllers/LocationsController.cs View File

@ -11,7 +11,8 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
using System.Threading.Tasks;
[Authorize]
public class LocationsController : Controller
[ApiController]
public class LocationsController : ControllerBase
{
private readonly MarketingContext _context;
@ -25,7 +26,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType(typeof(UserLocationRuleDTO),(int)HttpStatusCode.OK)]
public IActionResult GetLocationByCampaignAndLocationRuleId(int campaignId,
public ActionResult<UserLocationRuleDTO> GetLocationByCampaignAndLocationRuleId(int campaignId,
int userLocationRuleId)
{
if (campaignId < 1 || userLocationRuleId < 1)
@ -42,9 +43,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
return NotFound();
}
var locationDto = MapUserLocationRuleModelToDto(location);
return Ok(locationDto);
return MapUserLocationRuleModelToDto(location);
}
[HttpGet]
@ -52,7 +51,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(List<UserLocationRuleDTO>), (int)HttpStatusCode.OK)]
public IActionResult GetAllLocationsByCampaignId(int campaignId)
public ActionResult<List<UserLocationRuleDTO>> GetAllLocationsByCampaignId(int campaignId)
{
if (campaignId < 1)
{
@ -69,17 +68,14 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
return Ok();
}
var locationDtoList = MapUserLocationRuleModelListToDtoList(locationList);
return Ok(locationDtoList);
return MapUserLocationRuleModelListToDtoList(locationList);
}
[HttpPost]
[Route("api/v1/campaigns/{campaignId:int}/locations")]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.Created)]
public async Task<IActionResult> CreateLocation(int campaignId,
[FromBody] UserLocationRuleDTO locationRuleDto)
public async Task<ActionResult> CreateLocation(int campaignId, [FromBody] UserLocationRuleDTO locationRuleDto)
{
if (campaignId < 1 || locationRuleDto is null)
{
@ -100,7 +96,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
[Route("api/v1/campaigns/{campaignId:int}/locations/{userLocationRuleId:int}")]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> DeleteLocationById(int campaignId, int userLocationRuleId)
public async Task<ActionResult> DeleteLocationById(int campaignId, int userLocationRuleId)
{
if (campaignId < 1 || userLocationRuleId < 1)
{


+ 3
- 3
src/Services/Marketing/Marketing.API/Controllers/PicController.cs View File

@ -4,8 +4,8 @@
using Microsoft.AspNetCore.Mvc;
using System.IO;
public class PicController : Controller
[ApiController]
public class PicController : ControllerBase
{
private readonly IHostingEnvironment _env;
public PicController(IHostingEnvironment env)
@ -15,7 +15,7 @@
[HttpGet]
[Route("api/v1/campaigns/{campaignId:int}/pic")]
public IActionResult GetImage(int campaignId)
public ActionResult GetImage(int campaignId)
{
var webRoot = _env.WebRootPath;
var path = Path.Combine(webRoot, campaignId + ".png");


+ 4
- 1
src/Services/Marketing/Marketing.API/Startup.cs View File

@ -24,6 +24,7 @@
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.ServiceFabric;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.Middlewares;
using RabbitMQ.Client;
@ -53,7 +54,9 @@
services.AddMvc(options =>
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
}).AddControllersAsServices(); //Injecting Controllers themselves thru DIFor further info see: http://docs.autofac.org/en/latest/integration/aspnetcore.html#controllers-as-services
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddControllersAsServices(); //Injecting Controllers themselves thru DIFor further info see: http://docs.autofac.org/en/latest/integration/aspnetcore.html#controllers-as-services
services.Configure<MarketingSettings>(Configuration);


+ 7
- 9
src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs View File

@ -15,7 +15,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
[Route("api/v1/[controller]")]
[Authorize]
[ApiController]
public class OrdersController : Controller
public class OrdersController : ControllerBase
{
private readonly IMediator _mediator;
private readonly IOrderQueries _orderQueries;
@ -67,12 +67,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
[HttpGet]
[ProducesResponseType(typeof(Order),(int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> GetOrder(int orderId)
public async Task<ActionResult> GetOrder(int orderId)
{
try
{
var order = await _orderQueries
.GetOrderAsync(orderId);
var order = await _orderQueries.GetOrderAsync(orderId);
return Ok(order);
}
@ -85,7 +84,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
[Route("")]
[HttpGet]
[ProducesResponseType(typeof(IEnumerable<OrderSummary>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetOrders()
public async Task<ActionResult<IEnumerable<OrderSummary>>> GetOrders()
{
var userid = _identityService.GetUserIdentity();
var orders = await _orderQueries.GetOrdersFromUserAsync(Guid.Parse(userid));
@ -95,7 +94,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
[Route("cardtypes")]
[HttpGet]
[ProducesResponseType(typeof(IEnumerable<CardType>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetCardTypes()
public async Task<ActionResult<IEnumerable<CardType>>> GetCardTypes()
{
var cardTypes = await _orderQueries
.GetCardTypesAsync();
@ -105,10 +104,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
[Route("draft")]
[HttpPost]
public async Task<IActionResult> GetOrderDraftFromBasketData([FromBody] CreateOrderDraftCommand createOrderDraftCommand)
public async Task<ActionResult<OrderDraftDTO>> GetOrderDraftFromBasketData([FromBody] CreateOrderDraftCommand createOrderDraftCommand)
{
var draft = await _mediator.Send(createOrderDraftCommand);
return Ok(draft);
return await _mediator.Send(createOrderDraftCommand);
}
}
}


+ 5
- 3
src/Services/Ordering/Ordering.API/Startup.cs View File

@ -154,9 +154,11 @@
{
// Add framework services.
services.AddMvc(options =>
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
}).AddControllersAsServices(); //Injecting Controllers themselves thru DI
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddControllersAsServices(); //Injecting Controllers themselves thru DI
//For further info see: http://docs.autofac.org/en/latest/integration/aspnetcore.html#controllers-as-services
services.AddCors(options =>


+ 4
- 4
src/Services/Ordering/Ordering.UnitTests/Application/OrdersWebApiTest.cs View File

@ -103,10 +103,10 @@ namespace UnitTest.Ordering.Application
//Act
var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object);
var actionResult = await orderController.GetOrders() as OkObjectResult;
var actionResult = await orderController.GetOrders();
//Assert
Assert.Equal(actionResult.StatusCode, (int)System.Net.HttpStatusCode.OK);
Assert.Equal((actionResult.Result as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK);
}
[Fact]
@ -136,10 +136,10 @@ namespace UnitTest.Ordering.Application
//Act
var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object);
var actionResult = await orderController.GetCardTypes() as OkObjectResult;
var actionResult = await orderController.GetCardTypes();
//Assert
Assert.Equal(actionResult.StatusCode, (int)System.Net.HttpStatusCode.OK);
Assert.Equal((actionResult.Result as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK);
}
}
}

+ 5
- 1
src/Web/WebMVC/Startup.cs View File

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopOnContainers.WebMVC.Services;
using Microsoft.eShopOnContainers.WebMVC.ViewModels;
using Microsoft.Extensions.Configuration;
@ -59,6 +60,7 @@ namespace Microsoft.eShopOnContainers.WebMVC
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
var pathBase = Configuration["PATH_BASE"];
@ -87,6 +89,7 @@ namespace Microsoft.eShopOnContainers.WebMVC
WebContextSeed.Seed(app, env, loggerFactory);
app.UseHttpsRedirection();
app.UseMvc(routes =>
{
routes.MapRoute(
@ -149,7 +152,8 @@ namespace Microsoft.eShopOnContainers.WebMVC
services.AddOptions();
services.Configure<AppSettings>(configuration);
services.AddMvc();
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddSession();


+ 7
- 0
src/Web/WebSPA/Startup.cs View File

@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Antiforgery;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.HealthChecks;
@ -71,6 +72,7 @@ namespace eShopConContainers.WebSPA
services.AddAntiforgery(options => options.HeaderName = "X-XSRF-TOKEN");
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
@ -89,6 +91,11 @@ namespace eShopConContainers.WebSPA
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
// Configure XSRF middleware, This pattern is for SPA style applications where XSRF token is added on Index page
// load and passed back token on every subsequent async request


+ 7
- 2
src/Web/WebStatus/Startup.cs View File

@ -10,6 +10,7 @@ using Microsoft.Extensions.Logging;
using WebStatus.Extensions;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.ServiceFabric;
using Microsoft.AspNetCore.Mvc;
namespace WebStatus
{
@ -50,7 +51,8 @@ namespace WebStatus
checks.AddUrlCheckIfNotNull(Configuration["spa"], TimeSpan.Zero); //No cache for this HealthCheck, better just for demos
});
services.AddMvc();
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@ -66,6 +68,8 @@ namespace WebStatus
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
var pathBase = Configuration["PATH_BASE"];
@ -74,13 +78,14 @@ namespace WebStatus
app.UsePathBase(pathBase);
}
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
app.Map("/liveness", lapp => lapp.Run(async ctx => ctx.Response.StatusCode = 200));
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
app.UseStaticFiles();
app.UseHttpsRedirection();
app.UseMvc(routes =>
{
routes.MapRoute(


Loading…
Cancel
Save