78 lines
2.6 KiB
C#
78 lines
2.6 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using DomainResults.Mvc;
|
|
|
|
using WeatherForecast.Services;
|
|
using WeatherForecast.Policies;
|
|
using Core.Enumerations;
|
|
using DataProviders.Collections;
|
|
using WeatherForecast.Models.Requests;
|
|
|
|
namespace WeatherForecast.Controllers;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class BlogItemsController : ControllerBase {
|
|
|
|
private readonly IAuthorizationService _authorizationService;
|
|
private readonly IBlogCatalogDataProvider _blogCatalogDataProvider;
|
|
private readonly IBlogItemsService _blogItemsService;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="authorizationService"></param>
|
|
/// <param name="blogCatalogDataProvider"></param>
|
|
/// <param name="blogItemsService"></param>
|
|
public BlogItemsController(
|
|
IAuthorizationService authorizationService,
|
|
IBlogCatalogDataProvider blogCatalogDataProvider,
|
|
IBlogItemsService blogItemsService
|
|
) {
|
|
_authorizationService = authorizationService;
|
|
_blogCatalogDataProvider = blogCatalogDataProvider;
|
|
_blogItemsService = blogItemsService;
|
|
}
|
|
|
|
#region Authless methods
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="siteId"></param>
|
|
/// <param name="category"></param>
|
|
/// <param name="searchText"></param>
|
|
/// <param name="currentPage"></param>
|
|
/// <param name="itemsPerPage"></param>
|
|
/// <param name="locale"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("{siteId}")]
|
|
public IActionResult Get([FromRoute] Guid siteId, [FromQuery] Guid? category, [FromQuery] string? searchText, [FromQuery] int? currentPage, [FromQuery] int? itemsPerPage, [FromQuery] string? locale) {
|
|
var result = _blogItemsService.Get(siteId, category, currentPage ?? 1, itemsPerPage ?? 8, locale, searchText);
|
|
return result.ToActionResult();
|
|
}
|
|
#endregion
|
|
|
|
//[HttpDelete("{siteId}")]
|
|
//public async Task<IActionResult> Delete([FromRoute] Guid siteId, [FromBody] BlogItemsRequestModel requestData) {
|
|
|
|
// var (blogItems, getBlogItemsResult) = _blogCatalogDataProvider.GetMany(siteId, requestData.Ids);
|
|
// if (!getBlogItemsResult.IsSuccess || blogItems == null)
|
|
// return getBlogItemsResult.ToActionResult();
|
|
|
|
// if ((await _authorizationService.AuthorizeAsync(User, blogItems, new BlogAuthorizationRequirement {
|
|
// WhiteListToken = true,
|
|
// SameAuthor = true,
|
|
// Action = CrudActions.Delete
|
|
// })).Succeeded) {
|
|
// var result = _blogCatalogDataProvider.DeleteMany(siteId, requestData.Ids);
|
|
// return result.ToActionResult();
|
|
// }
|
|
|
|
// return Unauthorized();
|
|
//}
|
|
}
|