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 CategoryItemsController : ControllerBase {
private readonly IAuthorizationService _authorizationService;
private readonly ICategoryItemsService _categoryItemsService;
private readonly WebapiControllers _webapiController = WebapiControllers.CategoryItem;
///
///
///
///
///
public CategoryItemsController(
IAuthorizationService authorizationService,
ICategoryItemsService categoryItemsService
) {
_authorizationService = authorizationService;
_categoryItemsService = categoryItemsService;
}
///
///
///
///
///
///
[HttpGet("{siteId}")]
public IActionResult Get([FromRoute] Guid siteId, [FromQuery] string? locale) {
var result = _categoryItemsService.Get(siteId, locale);
return result.ToActionResult();
}
///
///
///
///
///
[HttpDelete("{siteId}")]
public async Task Delete([FromRoute] Guid siteId) {
if ((await _authorizationService.AuthorizeAsync(User, null, new CrudActionRequirement(_webapiController, CrudActions.Delete))).Succeeded) {
var result = _categoryItemsService.Delete(siteId);
return result.ToActionResult();
}
else {
return Unauthorized();
}
}
}