2016-10-17 20:10:18 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
2016-11-29 15:10:16 +01:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2016-10-17 20:10:18 -07:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
|
|
|
|
{
|
2017-02-02 17:30:15 -08:00
|
|
|
|
//TODO NOTE: Right now this is a very chunky API, as the app evolves it is possible we would
|
2017-02-26 13:44:07 -05:00
|
|
|
|
//want to make the actions more fine grained, add basket item as an action for example.
|
2016-10-17 20:10:18 -07:00
|
|
|
|
//If this is the case we should also investigate changing the serialization format used for Redis,
|
|
|
|
|
//using a HashSet instead of a simple string.
|
|
|
|
|
[Route("/")]
|
2016-11-29 15:10:16 +01:00
|
|
|
|
[Authorize]
|
2016-10-17 20:10:18 -07:00
|
|
|
|
public class BasketController : Controller
|
|
|
|
|
{
|
|
|
|
|
private IBasketRepository _repository;
|
|
|
|
|
|
|
|
|
|
public BasketController(IBasketRepository repository)
|
|
|
|
|
{
|
|
|
|
|
_repository = repository;
|
|
|
|
|
}
|
|
|
|
|
// GET api/values/5
|
|
|
|
|
[HttpGet("{id}")]
|
2016-11-16 10:19:00 +01:00
|
|
|
|
public async Task<IActionResult> Get(string id)
|
2016-10-17 20:10:18 -07:00
|
|
|
|
{
|
2016-11-16 10:19:00 +01:00
|
|
|
|
var basket = await _repository.GetBasket(id);
|
|
|
|
|
|
|
|
|
|
return Ok(basket);
|
2016-10-17 20:10:18 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST api/values
|
|
|
|
|
[HttpPost]
|
2016-11-24 15:31:33 +01:00
|
|
|
|
public async Task<IActionResult> Post([FromBody]CustomerBasket value)
|
2016-10-17 20:10:18 -07:00
|
|
|
|
{
|
2016-11-24 15:31:33 +01:00
|
|
|
|
var basket = await _repository.UpdateBasket(value);
|
|
|
|
|
|
|
|
|
|
return Ok(basket);
|
2016-10-17 20:10:18 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DELETE api/values/5
|
|
|
|
|
[HttpDelete("{id}")]
|
2016-11-16 10:19:00 +01:00
|
|
|
|
public void Delete(string id)
|
2016-10-17 20:10:18 -07:00
|
|
|
|
{
|
|
|
|
|
_repository.DeleteBasket(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|