47 lines
1.2 KiB
C#
47 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
|
{
|
|
[Route("/")]
|
|
[Authorize]
|
|
public class BasketController : Controller
|
|
{
|
|
private IBasketRepository _repository;
|
|
|
|
public BasketController(IBasketRepository repository)
|
|
{
|
|
_repository = repository;
|
|
}
|
|
// GET /id
|
|
[HttpGet("{id}")]
|
|
public async Task<IActionResult> Get(string id)
|
|
{
|
|
var basket = await _repository.GetBasketAsync(id);
|
|
|
|
return Ok(basket);
|
|
}
|
|
|
|
// POST /value
|
|
[HttpPost]
|
|
public async Task<IActionResult> Post([FromBody]CustomerBasket value)
|
|
{
|
|
var basket = await _repository.UpdateBasketAsync(value);
|
|
|
|
return Ok(basket);
|
|
}
|
|
|
|
// DELETE /id
|
|
[HttpDelete("{id}")]
|
|
public void Delete(string id)
|
|
{
|
|
_repository.DeleteBasketAsync(id);
|
|
}
|
|
}
|
|
}
|