using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Authorization; using DomainResults.Mvc; using WeatherForecast.Services; using WeatherForecast.Policies; using Core.Enumerations; using DataProviders.Collections; namespace WeatherForecast.Controllers; /// /// /// [ApiController] [Route("api/[controller]")] public class ShopCartItemsController : ControllerBase { private readonly IAuthorizationService _authorizationService; private readonly IShopCartDataProvider _shopCartDataProvider; private readonly IShopCartItemsService _shopCartItemsService; /// /// /// /// /// /// public ShopCartItemsController( IAuthorizationService authorizationService, IShopCartDataProvider shopCartDataProvider, IShopCartItemsService shopCartItemsService ) { _authorizationService = authorizationService; _shopCartDataProvider = shopCartDataProvider; _shopCartItemsService = shopCartItemsService; } /// /// /// /// [HttpGet("{siteId}/{userId}")] public async Task Get([FromRoute] Guid siteId, [FromRoute] Guid userId, [FromQuery] string? locale) { var (cartItems, getCartItemsResult) = _shopCartDataProvider.GetAll(siteId, userId); if (!getCartItemsResult.IsSuccess || cartItems == null) return getCartItemsResult.ToActionResult(); if ((await _authorizationService.AuthorizeAsync(User, cartItems, new ShopCartAuthorizationRequirement { Action = CrudActions.Read })).Succeeded) { var result = _shopCartItemsService.Get(cartItems, locale); return result.ToActionResult(); } return Unauthorized(); } //[HttpDelete("{siteId}/{userId}")] //public async Task Delete([FromRoute] Guid siteId, [FromRoute] Guid userId) { // if ((await _authorizationService.AuthorizeAsync(User, null, new ShopCartAuthorizationRequirement { // WhiteListToken = true, // SameAuthor = true, // Action = CrudActions.Delete // })).Succeeded) { // var result = _shopCartItemsService.Delete(siteId, userId); // return result.ToActionResult(); // } // return Unauthorized(); //} }