67 lines
2.0 KiB
C#
67 lines
2.0 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using DomainResults.Mvc;
|
|
|
|
using WeatherForecast.Services;
|
|
using WeatherForecast.Policies;
|
|
using Core.Enumerations;
|
|
|
|
namespace WeatherForecast.Controllers;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class ShopItemsController : ControllerBase {
|
|
|
|
private readonly IAuthorizationService _authorizationService;
|
|
private readonly IShopItemsService _shopItemsService;
|
|
|
|
private readonly WebapiControllers _webapiController = WebapiControllers.ShopItem;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="shopCatalogService"></param>
|
|
public ShopItemsController(
|
|
IAuthorizationService authorizationService,
|
|
IShopItemsService shopCatalogService
|
|
) {
|
|
_authorizationService = authorizationService;
|
|
_shopItemsService = shopCatalogService;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="siteId"></param>
|
|
/// <param name="category"></param>
|
|
/// <param name="currentPage"></param>
|
|
/// <param name="itemsPerPage"></param>
|
|
/// <param name="locale"></param>
|
|
/// <param name="searchText"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("{siteId}")]
|
|
public IActionResult Get([FromRoute] Guid siteId, [FromQuery] Guid? category, [FromQuery] int? currentPage, [FromQuery] int? itemsPerPage, [FromQuery] string? locale, [FromQuery] string? searchText) {
|
|
var result = _shopItemsService.Get(siteId, category, currentPage ?? 1, itemsPerPage ?? 8, locale, searchText);
|
|
return result.ToActionResult();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="siteId"></param>
|
|
/// <returns></returns>
|
|
[HttpDelete("{siteId}")]
|
|
public async Task<IActionResult> Delete([FromRoute] Guid siteId) {
|
|
if ((await _authorizationService.AuthorizeAsync(User, null, new CrudActionRequirement(_webapiController, CrudActions.Create))).Succeeded) {
|
|
var result = _shopItemsService.Delete(siteId);
|
|
return result.ToActionResult();
|
|
}
|
|
|
|
return Unauthorized();
|
|
}
|
|
}
|