using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using AsbCloudApp.Data.Manuals; using AsbCloudApp.Repositories; using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace AsbCloudWebApi.Controllers; [ApiController] [Route("api/[controller]")] [Authorize] public class ManualDirectoryController : ControllerBase { private readonly IManualDirectoryRepository manualDirectoryRepository; private readonly IManualCatalogService manualCatalogService; public ManualDirectoryController(IManualDirectoryRepository manualDirectoryRepository, IManualCatalogService manualCatalogService) { this.manualDirectoryRepository = manualDirectoryRepository; this.manualCatalogService = manualCatalogService; } /// /// Создание директории /// /// Название /// Необязательный параметр. Id родительской директории /// /// [HttpPost] [Permission("Manual.edit")] [ProducesResponseType(typeof(int), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status403Forbidden)] public async Task AddDirectoryAsync(string name, int? idParent, CancellationToken cancellationToken) { return Ok(await manualCatalogService.AddDirectoryAsync(name, idParent, cancellationToken)); } /// /// Обновление директории /// /// /// Новое название директории /// /// [HttpPut] [Permission("Manual.edit")] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status403Forbidden)] public async Task UpdateDirectoryAsync(int id, string name, CancellationToken cancellationToken) { await manualCatalogService.UpdateDirectoryAsync(id, name, cancellationToken); return Ok(); } /// /// Удаление директории /// /// Идентификатор директории /// /// [HttpDelete] [Permission("Manual.delete")] [ProducesResponseType(typeof(int), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] public async Task DeleteDirectoryAsync(int id, CancellationToken cancellationToken) { return Ok(await manualCatalogService.DeleteDirectoryAsync(id, cancellationToken)); } /// /// Получение дерева категорий /// /// /// [HttpGet] [Permission("Manual.get")] [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] public async Task GetAsync(CancellationToken cancellationToken) { return Ok(await manualDirectoryRepository.GetTreeAsync(cancellationToken)); } }