using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using DomainResults.Mvc;
using WeatherForecast.Services;
using WeatherForecast.Policies;
using Core.Enumerations;
namespace WeatherForecast.Controllers;
///
///
///
[ApiController]
[Route("api/[controller]")]
public class ShopCartItemsController : ControllerBase {
private readonly IAuthorizationService _authorizationService;
private readonly IShopCartItemsService _shopCartItemsService;
private readonly WebapiControllers _webapiController = WebapiControllers.ShopCartItems;
///
///
///
///
public ShopCartItemsController(
IAuthorizationService authorizationService,
IShopCartItemsService shopCartItemsService
) {
_authorizationService = authorizationService;
_shopCartItemsService = shopCartItemsService;
}
///
///
///
///
[HttpGet("{siteId}/{userId}")]
public async Task Get([FromRoute] Guid siteId, [FromRoute] Guid userId, [FromQuery] string? locale) {
if ((await _authorizationService.AuthorizeAsync(User, null, new CrudActionRequirement(WebapiControllers.ShopCartItems, CrudActions.Read))).Succeeded) {
var result = _shopCartItemsService.Get(siteId, userId, 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 CrudActionRequirement(_webapiController, CrudActions.Delete))).Succeeded) {
var result = _shopCartItemsService.Delete(siteId, userId);
return result.ToActionResult();
}
return Unauthorized();
}
}