117 lines
3.5 KiB
C#
117 lines
3.5 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using DomainResults.Mvc;
|
|
|
|
using WeatherForecast.Services;
|
|
using WeatherForecast.Models.Requests;
|
|
using WeatherForecast.Policies;
|
|
using Core.Enumerations;
|
|
|
|
namespace WeatherForecast.Controllers;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class ShopItemController : ControllerBase {
|
|
|
|
private readonly IAuthorizationService _authorizationService;
|
|
private readonly IShopItemService _shopItemService;
|
|
|
|
private readonly WebapiControllers _webapiController = WebapiControllers.ShopItem;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="shopItemService"></param>
|
|
public ShopItemController(
|
|
IAuthorizationService authorizationService,
|
|
IShopItemService shopItemService
|
|
) {
|
|
_authorizationService = authorizationService;
|
|
_shopItemService = shopItemService;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="siteId"></param>
|
|
/// <param name="sku"></param>
|
|
/// <param name="requestData"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("{siteId}/{sku}")]
|
|
public async Task<IActionResult> Post([FromRoute] Guid siteId, [FromRoute] string sku, [FromBody] ShopItemRequestModel requestData) {
|
|
if ((await _authorizationService.AuthorizeAsync(User, null, new CrudActionRequirement(_webapiController, CrudActions.Create))).Succeeded) {
|
|
|
|
var result = _shopItemService.Post(siteId, sku, requestData);
|
|
return result.ToActionResult();
|
|
}
|
|
|
|
return Unauthorized();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns full object
|
|
/// </summary>
|
|
/// <param name="siteId"></param>
|
|
/// <param name="sku"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("{siteId}/{sku}")]
|
|
public async Task<IActionResult> Get([FromRoute] Guid siteId, [FromRoute] string sku) {
|
|
if ((await _authorizationService.AuthorizeAsync(User, null, new CrudActionRequirement(_webapiController, CrudActions.Read))).Succeeded) {
|
|
var result = _shopItemService.Get(siteId, sku);
|
|
return result.ToActionResult();
|
|
}
|
|
|
|
return Unauthorized();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="siteId"></param>
|
|
/// <param name="slug"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("{siteId}")]
|
|
public IActionResult GetSlug([FromRoute] Guid siteId, [FromQuery] string slug) {
|
|
var result = _shopItemService.GetSlug(siteId, slug);
|
|
return result.ToActionResult();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="siteId"></param>
|
|
/// <param name="sku"></param>
|
|
/// <param name="requestData"></param>
|
|
/// <returns></returns>
|
|
[HttpPut("{siteId}/{sku}")]
|
|
public async Task<IActionResult> Update([FromRoute] Guid siteId, [FromRoute] string sku, [FromBody] ShopItemRequestModel requestData) {
|
|
if ((await _authorizationService.AuthorizeAsync(User, null, new CrudActionRequirement(_webapiController, CrudActions.Update))).Succeeded) {
|
|
var result = _shopItemService.Update(siteId, sku, requestData);
|
|
return result.ToActionResult();
|
|
}
|
|
|
|
return Unauthorized();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="siteId"></param>
|
|
/// <param name="sku"></param>
|
|
/// <returns></returns>
|
|
[HttpDelete("{siteId}/{sku}")]
|
|
public async Task<IActionResult> Delete([FromRoute] Guid siteId, [FromRoute] string sku) {
|
|
if ((await _authorizationService.AuthorizeAsync(User, null, new CrudActionRequirement(_webapiController, CrudActions.Delete))).Succeeded) {
|
|
var result = _shopItemService.Delete(siteId, sku);
|
|
return result.ToActionResult();
|
|
}
|
|
|
|
return Unauthorized();
|
|
}
|
|
}
|
|
|