swagge responce types and code https://github.com/dotnet-architecture/eShopOnContainers/issues/305
This commit is contained in:
parent
8d033f0951
commit
9e535930ce
@ -6,6 +6,7 @@ using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
||||
using Microsoft.eShopOnContainers.Services.Basket.API.Services;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
||||
@ -18,7 +19,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
||||
private readonly IIdentityService _identitySvc;
|
||||
private readonly IEventBus _eventBus;
|
||||
|
||||
public BasketController(IBasketRepository repository,
|
||||
public BasketController(IBasketRepository repository,
|
||||
IIdentityService identityService,
|
||||
IEventBus eventBus)
|
||||
{
|
||||
@ -26,8 +27,10 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
||||
_identitySvc = identityService;
|
||||
_eventBus = eventBus;
|
||||
}
|
||||
|
||||
// GET /id
|
||||
[HttpGet("{id}")]
|
||||
[ProducesResponseType(typeof(CustomerBasket), (int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> Get(string id)
|
||||
{
|
||||
var basket = await _repository.GetBasketAsync(id);
|
||||
@ -37,6 +40,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
||||
|
||||
// POST /value
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(CustomerBasket), (int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> Post([FromBody]CustomerBasket value)
|
||||
{
|
||||
var basket = await _repository.UpdateBasketAsync(value);
|
||||
@ -46,6 +50,8 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
||||
|
||||
[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)
|
||||
{
|
||||
var userId = _identitySvc.GetUserIdentity();
|
||||
|
@ -9,6 +9,7 @@ using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
@ -32,6 +33,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
// GET api/v1/[controller]/items[?pageSize=3&pageIndex=10]
|
||||
[HttpGet]
|
||||
[Route("[action]")]
|
||||
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> Items([FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
|
||||
|
||||
{
|
||||
@ -54,6 +56,8 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
|
||||
[HttpGet]
|
||||
[Route("items/{id:int}")]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType(typeof(CatalogItem),(int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetItemById(int id)
|
||||
{
|
||||
if (id <= 0)
|
||||
@ -73,6 +77,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
// GET api/v1/[controller]/items/withname/samplename[?pageSize=3&pageIndex=10]
|
||||
[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)
|
||||
{
|
||||
|
||||
@ -97,6 +102,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
// GET api/v1/[controller]/items/type/1/brand/null[?pageSize=3&pageIndex=10]
|
||||
[HttpGet]
|
||||
[Route("[action]/type/{catalogTypeId}/brand/{catalogBrandId}")]
|
||||
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> Items(int? catalogTypeId, int? catalogBrandId, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
|
||||
{
|
||||
var root = (IQueryable<CatalogItem>)_catalogContext.CatalogItems;
|
||||
@ -130,6 +136,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
// GET api/v1/[controller]/CatalogTypes
|
||||
[HttpGet]
|
||||
[Route("[action]")]
|
||||
[ProducesResponseType(typeof(List<CatalogItem>), (int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> CatalogTypes()
|
||||
{
|
||||
var items = await _catalogContext.CatalogTypes
|
||||
@ -141,6 +148,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
// GET api/v1/[controller]/CatalogBrands
|
||||
[HttpGet]
|
||||
[Route("[action]")]
|
||||
[ProducesResponseType(typeof(List<CatalogItem>), (int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> CatalogBrands()
|
||||
{
|
||||
var items = await _catalogContext.CatalogBrands
|
||||
@ -152,6 +160,8 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
//PUT api/v1/[controller]/items
|
||||
[Route("items")]
|
||||
[HttpPut]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType((int)HttpStatusCode.Created)]
|
||||
public async Task<IActionResult> UpdateProduct([FromBody]CatalogItem productToUpdate)
|
||||
{
|
||||
var catalogItem = await _catalogContext.CatalogItems
|
||||
@ -192,6 +202,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
//POST api/v1/[controller]/items
|
||||
[Route("items")]
|
||||
[HttpPost]
|
||||
[ProducesResponseType((int)HttpStatusCode.Created)]
|
||||
public async Task<IActionResult> CreateProduct([FromBody]CatalogItem product)
|
||||
{
|
||||
var item = new CatalogItem
|
||||
@ -213,6 +224,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
//DELETE api/v1/[controller]/id
|
||||
[Route("{id}")]
|
||||
[HttpDelete]
|
||||
[ProducesResponseType((int)HttpStatusCode.NoContent)]
|
||||
public async Task<IActionResult> DeleteProduct(int id)
|
||||
{
|
||||
var product = _catalogContext.CatalogItems.SingleOrDefault(x => x.Id == id);
|
||||
|
@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
|
||||
@ -23,6 +24,8 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
|
||||
[HttpGet]
|
||||
[Route("api/v1/catalog/items/{catalogItemId:int}/pic")]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
// GET: /<controller>/
|
||||
public async Task<IActionResult> GetImage(int catalogItemId)
|
||||
{
|
||||
|
@ -1,8 +1,11 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Services;
|
||||
using Microsoft.eShopOnContainers.Services.Locations.API.Model;
|
||||
using Microsoft.eShopOnContainers.Services.Locations.API.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Locations.API.Controllers
|
||||
@ -23,6 +26,7 @@ namespace Locations.API.Controllers
|
||||
//GET api/v1/[controller]/user/1
|
||||
[Route("user/{userId:guid}")]
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(UserLocation), (int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetUserLocation(Guid userId)
|
||||
{
|
||||
var userLocation = await _locationsService.GetUserLocation(userId.ToString());
|
||||
@ -32,6 +36,7 @@ namespace Locations.API.Controllers
|
||||
//GET api/v1/[controller]/
|
||||
[Route("")]
|
||||
[HttpGet]
|
||||
//[ProducesResponseType(typeof(List<Locations>), (int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetAllLocations()
|
||||
{
|
||||
var locations = await _locationsService.GetAllLocation();
|
||||
@ -41,6 +46,7 @@ namespace Locations.API.Controllers
|
||||
//GET api/v1/[controller]/1
|
||||
[Route("{locationId}")]
|
||||
[HttpGet]
|
||||
//[ProducesResponseType(typeof(List<Locations>), (int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetLocation(int locationId)
|
||||
{
|
||||
var location = await _locationsService.GetLocation(locationId);
|
||||
@ -50,6 +56,8 @@ namespace Locations.API.Controllers
|
||||
//POST api/v1/[controller]/
|
||||
[Route("")]
|
||||
[HttpPost]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
public async Task<IActionResult> CreateOrUpdateUserLocation([FromBody]LocationRequest newLocReq)
|
||||
{
|
||||
var userId = _identityService.GetUserIdentity();
|
||||
|
@ -16,6 +16,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
using Extensions.Options;
|
||||
using Microsoft.eShopOnContainers.Services.Marketing.API.ViewModel;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Net;
|
||||
|
||||
[Route("api/v1/[controller]")]
|
||||
[Authorize]
|
||||
@ -38,6 +39,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(List<CampaignDTO>), (int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetAllCampaigns()
|
||||
{
|
||||
var campaignList = await _context.Campaigns
|
||||
@ -54,6 +56,8 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
}
|
||||
|
||||
[HttpGet("{id:int}")]
|
||||
[ProducesResponseType(typeof(CampaignDTO), (int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> GetCampaignById(int id)
|
||||
{
|
||||
var campaign = await _context.Campaigns
|
||||
@ -70,6 +74,8 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType((int)HttpStatusCode.Created)]
|
||||
public async Task<IActionResult> CreateCampaign([FromBody] CampaignDTO campaignDto)
|
||||
{
|
||||
if (campaignDto is null)
|
||||
@ -86,6 +92,9 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
}
|
||||
|
||||
[HttpPut("{id:int}")]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType((int)HttpStatusCode.Created)]
|
||||
public async Task<IActionResult> UpdateCampaign(int id, [FromBody] CampaignDTO campaignDto)
|
||||
{
|
||||
if (id < 1 || campaignDto is null)
|
||||
@ -111,6 +120,9 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
}
|
||||
|
||||
[HttpDelete("{id:int}")]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NoContent)]
|
||||
public async Task<IActionResult> Delete(int id)
|
||||
{
|
||||
if (id < 1)
|
||||
@ -131,6 +143,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)
|
||||
{
|
||||
var userId = _identityService.GetUserIdentity();
|
||||
|
@ -7,6 +7,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
using Microsoft.eShopOnContainers.Services.Marketing.API.Model;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
[Authorize]
|
||||
@ -21,6 +22,9 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
|
||||
[HttpGet]
|
||||
[Route("api/v1/campaigns/{campaignId:int}/locations/{userLocationRuleId:int}")]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType(typeof(UserLocationRuleDTO),(int)HttpStatusCode.OK)]
|
||||
public IActionResult GetLocationByCampaignAndLocationRuleId(int campaignId,
|
||||
int userLocationRuleId)
|
||||
{
|
||||
@ -45,6 +49,9 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
|
||||
[HttpGet]
|
||||
[Route("api/v1/campaigns/{campaignId:int}/locations")]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType(typeof(List<UserLocationRuleDTO>), (int)HttpStatusCode.OK)]
|
||||
public IActionResult GetAllLocationsByCampaignId(int campaignId)
|
||||
{
|
||||
if (campaignId < 1)
|
||||
@ -69,6 +76,8 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
|
||||
[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)
|
||||
{
|
||||
@ -89,6 +98,8 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
|
||||
[HttpDelete]
|
||||
[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)
|
||||
{
|
||||
if (campaignId < 1 || userLocationRuleId < 1)
|
||||
|
@ -11,7 +11,7 @@
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "api/values",
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
@ -19,7 +19,7 @@
|
||||
"Marketing.API": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "api/values",
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
|
@ -7,6 +7,7 @@ using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services;
|
||||
using Ordering.API.Application.Commands;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
||||
@ -29,6 +30,8 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
||||
|
||||
[Route("cancel")]
|
||||
[HttpPut]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
public async Task<IActionResult> CancelOrder([FromBody]CancelOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId)
|
||||
{
|
||||
bool commandResult = false;
|
||||
@ -44,6 +47,8 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
||||
|
||||
[Route("ship")]
|
||||
[HttpPut]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
public async Task<IActionResult> ShipOrder([FromBody]ShipOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId)
|
||||
{
|
||||
bool commandResult = false;
|
||||
@ -59,6 +64,8 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
||||
|
||||
[Route("{orderId:int}")]
|
||||
[HttpGet]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> GetOrder(int orderId)
|
||||
{
|
||||
try
|
||||
|
Loading…
x
Reference in New Issue
Block a user