-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasketsController.cs
More file actions
58 lines (52 loc) · 2.6 KB
/
BasketsController.cs
File metadata and controls
58 lines (52 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using ECommerceAPI.Application.Consts;
using ECommerceAPI.Application.CustomAttributes;
using ECommerceAPI.Application.Enums;
using ECommerceAPI.Application.Features.Commands.Basket.AddItemToBasket;
using ECommerceAPI.Application.Features.Commands.Basket.RemoveBasketItem;
using ECommerceAPI.Application.Features.Commands.Basket.UpdateQuantity;
using ECommerceAPI.Application.Features.Queries.Basket.GetBasketItems;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace ECommerceAPI.API.Controllers
{
[Route("api/[controller]")]
[ApiController]
[Authorize(AuthenticationSchemes = "Admin")]
public class BasketsController : ControllerBase
{
readonly IMediator _mediator;
public BasketsController(IMediator mediator)
{
_mediator = mediator;
}
[HttpGet]
[AuthorizeDefinition(Menu = AuthorizeDefinitionConstants.Baskets, ActionType = ActionType.Reading, Definition = "Get Basket Items")]
public async Task<IActionResult> GetBasketItems([FromQuery] GetBasketItemsQueryRequest getBasketItemsQueryRequest)
{
List<GetBasketItemsQueryResponse> response = await _mediator.Send(getBasketItemsQueryRequest);
return Ok(response);
}
[HttpPost]
[AuthorizeDefinition(Menu = AuthorizeDefinitionConstants.Baskets, ActionType = ActionType.Writing, Definition = "Add Item To Basket")]
public async Task<IActionResult> AddItemToBasket(AddItemToBasketCommandRequest addItemToBasketCommandRequest)
{
AddItemToBasketCommandResponse response = await _mediator.Send(addItemToBasketCommandRequest);
return Ok(response);
}
[HttpPut]
[AuthorizeDefinition(Menu = AuthorizeDefinitionConstants.Baskets, ActionType = ActionType.Updating, Definition = "Update Quantity")]
public async Task<IActionResult> UpdateQuantity(UpdateQuantityCommandRequest updateQuantityCommandRequest)
{
UpdateQuantityCommandResponse response = await _mediator.Send(updateQuantityCommandRequest);
return Ok(response);
}
[HttpDelete("{BasketItemId}")]
[AuthorizeDefinition(Menu = AuthorizeDefinitionConstants.Baskets, ActionType = ActionType.Deleting, Definition = "Remove Basket Item")]
public async Task<IActionResult> RemoveBasketItem([FromRoute] RemoveBasketItemCommandRequest removeBasketItemCommandRequest)
{
RemoveBasketItemCommandResponse response = await _mediator.Send(removeBasketItemCommandRequest);
return Ok(response);
}
}
}