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]")] [Route("api/v1/[controller]")]
[Authorize] [Authorize]
public class BasketController : Controller
[ApiController]
public class BasketController : ControllerBase
{ {
private readonly ICatalogService _catalog; private readonly ICatalogService _catalog;
private readonly IBasketService _basket; private readonly IBasketService _basket;
@ -23,7 +24,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
[HttpPost] [HttpPost]
[HttpPut] [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()) if (data.Items == null || !data.Items.Any())
@ -61,12 +62,13 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
} }
await _basket.Update(newBasket); await _basket.Update(newBasket);
return Ok(newBasket);
return newBasket;
} }
[HttpPut] [HttpPut]
[Route("items")] [Route("items")]
public async Task<IActionResult> UpdateQuantities([FromBody] UpdateBasketItemsRequest data)
public async Task<ActionResult<BasketData>> UpdateQuantities([FromBody] UpdateBasketItemsRequest data)
{ {
if (!data.Updates.Any()) if (!data.Updates.Any())
{ {
@ -93,12 +95,13 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
// Save the updated basket // Save the updated basket
await _basket.Update(currentBasket); await _basket.Update(currentBasket);
return Ok(currentBasket);
return currentBasket;
} }
[HttpPost] [HttpPost]
[Route("items")] [Route("items")]
public async Task<IActionResult> AddBasketItem([FromBody] AddBasketItemRequest data)
public async Task<ActionResult> AddBasketItem([FromBody] AddBasketItemRequest data)
{ {
if (data == null || data.Quantity == 0) if (data == null || data.Quantity == 0)
{ {
@ -126,7 +129,6 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
// Step 4: Update basket // Step 4: Update basket
await _basket.Update(currentBasket); await _basket.Update(currentBasket);
return Ok(); 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.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services; using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
{ {
[Route("api/v1/[controller]")] [Route("api/v1/[controller]")]
[Authorize] [Authorize]
public class OrderController : Controller
[ApiController]
public class OrderController : ControllerBase
{ {
private readonly IBasketService _basketService; private readonly IBasketService _basketService;
private readonly IOrderApiClient _orderClient; 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.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config; using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config;
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Filters.Basket.API.Infrastructure.Filters; using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Filters.Basket.API.Infrastructure.Filters;
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastructure; using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastructure;
@ -53,9 +54,14 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
{ {
app.UseDeveloperExceptionPage(); 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.UseAuthentication();
app.UseHttpsRedirection();
app.UseMvc(); app.UseMvc();
app.UseSwagger().UseSwaggerUI(c => app.UseSwagger().UseSwaggerUI(c =>
@ -77,7 +83,8 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
services.AddOptions(); services.AddOptions();
services.Configure<UrlsConfig>(configuration.GetSection("urls")); services.Configure<UrlsConfig>(configuration.GetSection("urls"));
services.AddMvc();
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddSwaggerGen(options => 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]")] [Route("api/v1/[controller]")]
[Authorize] [Authorize]
public class BasketController : Controller
[ApiController]
public class BasketController : ControllerBase
{ {
private readonly ICatalogService _catalog; private readonly ICatalogService _catalog;
private readonly IBasketService _basket; private readonly IBasketService _basket;
@ -23,7 +24,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
[HttpPost] [HttpPost]
[HttpPut] [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()) if (data.Items == null || !data.Items.Any())
@ -61,12 +62,13 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
} }
await _basket.Update(newBasket); await _basket.Update(newBasket);
return Ok(newBasket);
return newBasket;
} }
[HttpPut] [HttpPut]
[Route("items")] [Route("items")]
public async Task<IActionResult> UpdateQuantities([FromBody] UpdateBasketItemsRequest data)
public async Task<ActionResult<BasketData>> UpdateQuantities([FromBody] UpdateBasketItemsRequest data)
{ {
if (!data.Updates.Any()) if (!data.Updates.Any())
{ {
@ -93,12 +95,13 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
// Save the updated basket // Save the updated basket
await _basket.Update(currentBasket); await _basket.Update(currentBasket);
return Ok(currentBasket);
return currentBasket;
} }
[HttpPost] [HttpPost]
[Route("items")] [Route("items")]
public async Task<IActionResult> AddBasketItem([FromBody] AddBasketItemRequest data)
public async Task<ActionResult> AddBasketItem([FromBody] AddBasketItemRequest data)
{ {
if (data == null || data.Quantity == 0) 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.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services; using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -10,7 +11,8 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
{ {
[Route("api/v1/[controller]")] [Route("api/v1/[controller]")]
[Authorize] [Authorize]
public class OrderController : Controller
[ApiController]
public class OrderController : ControllerBase
{ {
private readonly IBasketService _basketService; private readonly IBasketService _basketService;
private readonly IOrderApiClient _orderClient; private readonly IOrderApiClient _orderClient;
@ -22,7 +24,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
[Route("draft/{basketId}")] [Route("draft/{basketId}")]
[HttpGet] [HttpGet]
public async Task<IActionResult> GetOrderDraft(string basketId)
public async Task<ActionResult<OrderData>> GetOrderDraft(string basketId)
{ {
if (string.IsNullOrEmpty(basketId)) if (string.IsNullOrEmpty(basketId))
{ {
@ -35,8 +37,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
return BadRequest($"No basket found for id {basketId}"); 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.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config; using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config;
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Filters.Basket.API.Infrastructure.Filters; using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Filters.Basket.API.Infrastructure.Filters;
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure; using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure;
@ -53,9 +54,14 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
{ {
app.UseDeveloperExceptionPage(); 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.UseAuthentication();
app.UseHttpsRedirection();
app.UseMvc(); app.UseMvc();
app.UseSwagger().UseSwaggerUI(c => app.UseSwagger().UseSwaggerUI(c =>
@ -104,7 +110,8 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
services.AddOptions(); services.AddOptions();
services.Configure<UrlsConfig>(configuration.GetSection("urls")); services.Configure<UrlsConfig>(configuration.GetSection("urls"));
services.AddMvc();
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddSwaggerGen(options => 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]")] [Route("api/v1/[controller]")]
[Authorize] [Authorize]
public class BasketController : Controller
[ApiController]
public class BasketController : ControllerBase
{ {
private readonly IBasketRepository _repository; private readonly IBasketRepository _repository;
private readonly IIdentityService _identitySvc; private readonly IIdentityService _identitySvc;
@ -31,32 +32,31 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
// GET /id // GET /id
[HttpGet("{id}")] [HttpGet("{id}")]
[ProducesResponseType(typeof(CustomerBasket), (int)HttpStatusCode.OK)] [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); var basket = await _repository.GetBasketAsync(id);
if (basket == null) if (basket == null)
{ {
return Ok(new CustomerBasket(id) { });
return new CustomerBasket(id);
} }
return Ok(basket);
return basket;
} }
// POST /value // POST /value
[HttpPost] [HttpPost]
[ProducesResponseType(typeof(CustomerBasket), (int)HttpStatusCode.OK)] [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")] [Route("checkout")]
[HttpPost] [HttpPost]
[ProducesResponseType((int)HttpStatusCode.Accepted)] [ProducesResponseType((int)HttpStatusCode.Accepted)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)] [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(); var userId = _identitySvc.GetUserIdentity();
@ -91,6 +91,5 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
{ {
_repository.DeleteBasketAsync(id); _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.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.ServiceBus; using Microsoft.Azure.ServiceBus;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
@ -51,11 +52,13 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
// Add framework services. // Add framework services.
services.AddMvc(options => 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); ConfigureAuthService(services);


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

@ -44,10 +44,10 @@ namespace UnitTest.Basket.Application
//Act //Act
var basketController = new BasketController( var basketController = new BasketController(
_basketRepositoryMock.Object, _identityServiceMock.Object, _serviceBusMock.Object); _basketRepositoryMock.Object, _identityServiceMock.Object, _serviceBusMock.Object);
var actionResult = await basketController.Get(fakeCustomerId) as OkObjectResult;
var actionResult = await basketController.Get(fakeCustomerId);
//Assert //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); Assert.Equal(((CustomerBasket)actionResult.Value).BuyerId, fakeCustomerId);
} }
@ -67,10 +67,10 @@ namespace UnitTest.Basket.Application
var basketController = new BasketController( var basketController = new BasketController(
_basketRepositoryMock.Object, _identityServiceMock.Object, _serviceBusMock.Object); _basketRepositoryMock.Object, _identityServiceMock.Object, _serviceBusMock.Object);
var actionResult = await basketController.Post(fakeCustomerBasket) as OkObjectResult;
var actionResult = await basketController.Post(fakeCustomerBasket);
//Assert //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); 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}")] [Route("items/{id:int}")]
[ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType(typeof(CatalogItem), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(CatalogItem), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetItemById(int id)
public async Task<ActionResult<CatalogItem>> GetItemById(int id)
{ {
if (id <= 0) if (id <= 0)
{ {
@ -99,7 +99,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
if (item != null) if (item != null)
{ {
return Ok(item);
return item;
} }
return NotFound(); return NotFound();
@ -109,9 +109,8 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
[HttpGet] [HttpGet]
[Route("[action]/withname/{name:minlength(1)}")] [Route("[action]/withname/{name:minlength(1)}")]
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)] [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 var totalItems = await _catalogContext.CatalogItems
.Where(c => c.Name.StartsWith(name)) .Where(c => c.Name.StartsWith(name))
.LongCountAsync(); .LongCountAsync();
@ -124,17 +123,14 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
itemsOnPage = ChangeUriPlaceholder(itemsOnPage); 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] // GET api/v1/[controller]/items/type/1/brand[?pageSize=3&pageIndex=10]
[HttpGet] [HttpGet]
[Route("[action]/type/{catalogTypeId}/brand/{catalogBrandId:int?}")] [Route("[action]/type/{catalogTypeId}/brand/{catalogBrandId:int?}")]
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)] [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; var root = (IQueryable<CatalogItem>)_catalogContext.CatalogItems;
@ -155,16 +151,13 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
itemsOnPage = ChangeUriPlaceholder(itemsOnPage); 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] // GET api/v1/[controller]/items/type/all/brand[?pageSize=3&pageIndex=10]
[HttpGet] [HttpGet]
[Route("[action]/type/all/brand/{catalogBrandId:int?}")] [Route("[action]/type/all/brand/{catalogBrandId:int?}")]
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)] [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; var root = (IQueryable<CatalogItem>)_catalogContext.CatalogItems;
@ -183,34 +176,25 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
itemsOnPage = ChangeUriPlaceholder(itemsOnPage); 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 // GET api/v1/[controller]/CatalogTypes
[HttpGet] [HttpGet]
[Route("[action]")] [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 // GET api/v1/[controller]/CatalogBrands
[HttpGet] [HttpGet]
[Route("[action]")] [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 //PUT api/v1/[controller]/items
@ -218,7 +202,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
[HttpPut] [HttpPut]
[ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType((int)HttpStatusCode.Created)] [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 var catalogItem = await _catalogContext.CatalogItems
.SingleOrDefaultAsync(i => i.Id == productToUpdate.Id); .SingleOrDefaultAsync(i => i.Id == productToUpdate.Id);
@ -259,7 +243,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
[Route("items")] [Route("items")]
[HttpPost] [HttpPost]
[ProducesResponseType((int)HttpStatusCode.Created)] [ProducesResponseType((int)HttpStatusCode.Created)]
public async Task<IActionResult> CreateProduct([FromBody]CatalogItem product)
public async Task<ActionResult> CreateProduct([FromBody]CatalogItem product)
{ {
var item = new CatalogItem var item = new CatalogItem
{ {
@ -281,7 +265,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
[Route("{id}")] [Route("{id}")]
[HttpDelete] [HttpDelete]
[ProducesResponseType((int)HttpStatusCode.NoContent)] [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); 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 // For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
{
public class PicController : Controller
{
[ApiController]
public class PicController : ControllerBase
{ {
private readonly IHostingEnvironment _env; private readonly IHostingEnvironment _env;
private readonly CatalogContext _catalogContext; private readonly CatalogContext _catalogContext;
@ -27,7 +28,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
[ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.BadRequest)]
// GET: /<controller>/ // GET: /<controller>/
public async Task<IActionResult> GetImage(int catalogItemId)
public async Task<ActionResult> GetImage(int catalogItemId)
{ {
if (catalogItemId <= 0) 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 => services.AddMvc(options =>
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
}).AddControllersAsServices();
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddControllersAsServices();
services.AddCors(options => 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.DataProtection;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.eShopOnContainers.Services.Identity.API.Certificates; using Microsoft.eShopOnContainers.Services.Identity.API.Certificates;
using Microsoft.eShopOnContainers.Services.Identity.API.Data; using Microsoft.eShopOnContainers.Services.Identity.API.Data;
@ -52,7 +53,8 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API
services.Configure<AppSettings>(Configuration); services.Configure<AppSettings>(Configuration);
services.AddMvc();
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
if (Configuration.GetValue<string>("IsClusterEnv") == bool.TrueString) if (Configuration.GetValue<string>("IsClusterEnv") == bool.TrueString)
{ {
@ -159,6 +161,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API
// Adds IdentityServer // Adds IdentityServer
app.UseIdentityServer(); app.UseIdentityServer();
app.UseHttpsRedirection();
app.UseMvc(routes => app.UseMvc(routes =>
{ {
routes.MapRoute( 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]")] [Route("api/v1/[controller]")]
[Authorize] [Authorize]
[ApiController]
public class LocationsController : ControllerBase public class LocationsController : ControllerBase
{ {
private readonly ILocationsService _locationsService; private readonly ILocationsService _locationsService;
@ -27,30 +28,27 @@ namespace Locations.API.Controllers
[Route("user/{userId:guid}")] [Route("user/{userId:guid}")]
[HttpGet] [HttpGet]
[ProducesResponseType(typeof(UserLocation), (int)HttpStatusCode.OK)] [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]/ //GET api/v1/[controller]/
[Route("")] [Route("")]
[HttpGet] [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 //GET api/v1/[controller]/1
[Route("{locationId}")] [Route("{locationId}")]
[HttpGet] [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]/ //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.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.ServiceBus; using Microsoft.Azure.ServiceBus;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
@ -43,9 +44,11 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
RegisterAppInsights(services); RegisterAppInsights(services);
services.AddMvc(options => services.AddMvc(options =>
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
}).AddControllersAsServices();
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddControllersAsServices();
ConfigureAuthService(services); 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]")] [Route("api/v1/[controller]")]
[Authorize] [Authorize]
public class CampaignsController : Controller
[ApiController]
public class CampaignsController : ControllerBase
{ {
private readonly MarketingContext _context; private readonly MarketingContext _context;
private readonly MarketingSettings _settings; private readonly MarketingSettings _settings;
@ -40,25 +41,22 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
[HttpGet] [HttpGet]
[ProducesResponseType(typeof(List<CampaignDTO>), (int)HttpStatusCode.OK)] [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) if (campaignList is null)
{ {
return Ok(); return Ok();
} }
var campaignDtoList = MapCampaignModelListToDtoList(campaignList);
return Ok(campaignDtoList);
return MapCampaignModelListToDtoList(campaignList);
} }
[HttpGet("{id:int}")] [HttpGet("{id:int}")]
[ProducesResponseType(typeof(CampaignDTO), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(CampaignDTO), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> GetCampaignById(int id)
public async Task<ActionResult<CampaignDTO>> GetCampaignById(int id)
{ {
var campaign = await _context.Campaigns var campaign = await _context.Campaigns
.SingleOrDefaultAsync(c => c.Id == id); .SingleOrDefaultAsync(c => c.Id == id);
@ -68,15 +66,13 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
return NotFound(); return NotFound();
} }
var campaignDto = MapCampaignModelToDto(campaign);
return Ok(campaignDto);
return MapCampaignModelToDto(campaign);
} }
[HttpPost] [HttpPost]
[ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.Created)] [ProducesResponseType((int)HttpStatusCode.Created)]
public async Task<IActionResult> CreateCampaign([FromBody] CampaignDTO campaignDto)
public async Task<ActionResult> CreateCampaign([FromBody] CampaignDTO campaignDto)
{ {
if (campaignDto is null) if (campaignDto is null)
{ {
@ -95,7 +91,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
[ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType((int)HttpStatusCode.Created)] [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) if (id < 1 || campaignDto is null)
{ {
@ -123,7 +119,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
[ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType((int)HttpStatusCode.NoContent)] [ProducesResponseType((int)HttpStatusCode.NoContent)]
public async Task<IActionResult> Delete(int id)
public async Task<ActionResult> Delete(int id)
{ {
if (id < 1) if (id < 1)
{ {
@ -144,7 +140,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
[HttpGet("user")] [HttpGet("user")]
[ProducesResponseType(typeof(PaginatedItemsViewModel<CampaignDTO>), (int)HttpStatusCode.OK)] [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(); var userId = _identityService.GetUserIdentity();
@ -177,10 +173,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
.Skip(pageSize * pageIndex) .Skip(pageSize * pageIndex)
.Take(pageSize).ToList(); .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; using System.Threading.Tasks;
[Authorize] [Authorize]
public class LocationsController : Controller
[ApiController]
public class LocationsController : ControllerBase
{ {
private readonly MarketingContext _context; private readonly MarketingContext _context;
@ -25,7 +26,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
[ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType(typeof(UserLocationRuleDTO),(int)HttpStatusCode.OK)] [ProducesResponseType(typeof(UserLocationRuleDTO),(int)HttpStatusCode.OK)]
public IActionResult GetLocationByCampaignAndLocationRuleId(int campaignId,
public ActionResult<UserLocationRuleDTO> GetLocationByCampaignAndLocationRuleId(int campaignId,
int userLocationRuleId) int userLocationRuleId)
{ {
if (campaignId < 1 || userLocationRuleId < 1) if (campaignId < 1 || userLocationRuleId < 1)
@ -42,9 +43,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
return NotFound(); return NotFound();
} }
var locationDto = MapUserLocationRuleModelToDto(location);
return Ok(locationDto);
return MapUserLocationRuleModelToDto(location);
} }
[HttpGet] [HttpGet]
@ -52,7 +51,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
[ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(List<UserLocationRuleDTO>), (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) if (campaignId < 1)
{ {
@ -69,17 +68,14 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
return Ok(); return Ok();
} }
var locationDtoList = MapUserLocationRuleModelListToDtoList(locationList);
return Ok(locationDtoList);
return MapUserLocationRuleModelListToDtoList(locationList);
} }
[HttpPost] [HttpPost]
[Route("api/v1/campaigns/{campaignId:int}/locations")] [Route("api/v1/campaigns/{campaignId:int}/locations")]
[ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.Created)] [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) 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}")] [Route("api/v1/campaigns/{campaignId:int}/locations/{userLocationRuleId:int}")]
[ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)] [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) 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 Microsoft.AspNetCore.Mvc;
using System.IO; using System.IO;
public class PicController : Controller
[ApiController]
public class PicController : ControllerBase
{ {
private readonly IHostingEnvironment _env; private readonly IHostingEnvironment _env;
public PicController(IHostingEnvironment env) public PicController(IHostingEnvironment env)
@ -15,7 +15,7 @@
[HttpGet] [HttpGet]
[Route("api/v1/campaigns/{campaignId:int}/pic")] [Route("api/v1/campaigns/{campaignId:int}/pic")]
public IActionResult GetImage(int campaignId)
public ActionResult GetImage(int campaignId)
{ {
var webRoot = _env.WebRootPath; var webRoot = _env.WebRootPath;
var path = Path.Combine(webRoot, campaignId + ".png"); 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.Extensibility;
using Microsoft.ApplicationInsights.ServiceFabric; using Microsoft.ApplicationInsights.ServiceFabric;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.Middlewares; using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.Middlewares;
using RabbitMQ.Client; using RabbitMQ.Client;
@ -53,7 +54,9 @@
services.AddMvc(options => services.AddMvc(options =>
{ {
options.Filters.Add(typeof(HttpGlobalExceptionFilter)); 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); 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]")] [Route("api/v1/[controller]")]
[Authorize] [Authorize]
[ApiController] [ApiController]
public class OrdersController : Controller
public class OrdersController : ControllerBase
{ {
private readonly IMediator _mediator; private readonly IMediator _mediator;
private readonly IOrderQueries _orderQueries; private readonly IOrderQueries _orderQueries;
@ -67,12 +67,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
[HttpGet] [HttpGet]
[ProducesResponseType(typeof(Order),(int)HttpStatusCode.OK)] [ProducesResponseType(typeof(Order),(int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> GetOrder(int orderId)
public async Task<ActionResult> GetOrder(int orderId)
{ {
try try
{ {
var order = await _orderQueries
.GetOrderAsync(orderId);
var order = await _orderQueries.GetOrderAsync(orderId);
return Ok(order); return Ok(order);
} }
@ -85,7 +84,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
[Route("")] [Route("")]
[HttpGet] [HttpGet]
[ProducesResponseType(typeof(IEnumerable<OrderSummary>), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<OrderSummary>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetOrders()
public async Task<ActionResult<IEnumerable<OrderSummary>>> GetOrders()
{ {
var userid = _identityService.GetUserIdentity(); var userid = _identityService.GetUserIdentity();
var orders = await _orderQueries.GetOrdersFromUserAsync(Guid.Parse(userid)); var orders = await _orderQueries.GetOrdersFromUserAsync(Guid.Parse(userid));
@ -95,7 +94,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
[Route("cardtypes")] [Route("cardtypes")]
[HttpGet] [HttpGet]
[ProducesResponseType(typeof(IEnumerable<CardType>), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<CardType>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetCardTypes()
public async Task<ActionResult<IEnumerable<CardType>>> GetCardTypes()
{ {
var cardTypes = await _orderQueries var cardTypes = await _orderQueries
.GetCardTypesAsync(); .GetCardTypesAsync();
@ -105,10 +104,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
[Route("draft")] [Route("draft")]
[HttpPost] [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. // Add framework services.
services.AddMvc(options => 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 //For further info see: http://docs.autofac.org/en/latest/integration/aspnetcore.html#controllers-as-services
services.AddCors(options => services.AddCors(options =>


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

@ -103,10 +103,10 @@ namespace UnitTest.Ordering.Application
//Act //Act
var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object); var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object);
var actionResult = await orderController.GetOrders() as OkObjectResult;
var actionResult = await orderController.GetOrders();
//Assert //Assert
Assert.Equal(actionResult.StatusCode, (int)System.Net.HttpStatusCode.OK);
Assert.Equal((actionResult.Result as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK);
} }
[Fact] [Fact]
@ -136,10 +136,10 @@ namespace UnitTest.Ordering.Application
//Act //Act
var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object); var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object);
var actionResult = await orderController.GetCardTypes() as OkObjectResult;
var actionResult = await orderController.GetCardTypes();
//Assert //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.DataProtection;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopOnContainers.WebMVC.Services; using Microsoft.eShopOnContainers.WebMVC.Services;
using Microsoft.eShopOnContainers.WebMVC.ViewModels; using Microsoft.eShopOnContainers.WebMVC.ViewModels;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
@ -59,6 +60,7 @@ namespace Microsoft.eShopOnContainers.WebMVC
else else
{ {
app.UseExceptionHandler("/Error"); app.UseExceptionHandler("/Error");
app.UseHsts();
} }
var pathBase = Configuration["PATH_BASE"]; var pathBase = Configuration["PATH_BASE"];
@ -87,6 +89,7 @@ namespace Microsoft.eShopOnContainers.WebMVC
WebContextSeed.Seed(app, env, loggerFactory); WebContextSeed.Seed(app, env, loggerFactory);
app.UseHttpsRedirection();
app.UseMvc(routes => app.UseMvc(routes =>
{ {
routes.MapRoute( routes.MapRoute(
@ -149,7 +152,8 @@ namespace Microsoft.eShopOnContainers.WebMVC
services.AddOptions(); services.AddOptions();
services.Configure<AppSettings>(configuration); services.Configure<AppSettings>(configuration);
services.AddMvc();
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddSession(); 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.Builder;
using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.HealthChecks; using Microsoft.Extensions.HealthChecks;
@ -71,6 +72,7 @@ namespace eShopConContainers.WebSPA
services.AddAntiforgery(options => options.HeaderName = "X-XSRF-TOKEN"); services.AddAntiforgery(options => options.HeaderName = "X-XSRF-TOKEN");
services.AddMvc() services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddJsonOptions(options => .AddJsonOptions(options =>
{ {
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
@ -89,6 +91,11 @@ namespace eShopConContainers.WebSPA
{ {
app.UseDeveloperExceptionPage(); 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 // 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 // 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 WebStatus.Extensions;
using Microsoft.ApplicationInsights.Extensibility; using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.ServiceFabric; using Microsoft.ApplicationInsights.ServiceFabric;
using Microsoft.AspNetCore.Mvc;
namespace WebStatus namespace WebStatus
{ {
@ -50,7 +51,8 @@ namespace WebStatus
checks.AddUrlCheckIfNotNull(Configuration["spa"], TimeSpan.Zero); //No cache for this HealthCheck, better just for demos 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. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@ -66,6 +68,8 @@ namespace WebStatus
else else
{ {
app.UseExceptionHandler("/Home/Error"); 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"]; var pathBase = Configuration["PATH_BASE"];
@ -74,13 +78,14 @@ namespace WebStatus
app.UsePathBase(pathBase); app.UsePathBase(pathBase);
} }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously #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)); 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 #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
app.UseStaticFiles(); app.UseStaticFiles();
app.UseHttpsRedirection();
app.UseMvc(routes => app.UseMvc(routes =>
{ {
routes.MapRoute( routes.MapRoute(


Loading…
Cancel
Save