using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using GxPress.Service.Interface.ArticleLabel;
using System.Threading.Tasks;
using System.Collections.Generic;
using GxPress.Common.Exceptions;

namespace GxPress.Api.AdminControllers
{
    /// <summary>
    /// APP版本管理
    /// </summary>
    [Route("api/admin/article-label")]
    [ApiController]
    [Authorize]
    public class AdminArticleLabelController : ControllerBase
    {
        private readonly IArticleLabelService _articleLabelService;
        public AdminArticleLabelController(IArticleLabelService articleLabelService)
        {
            _articleLabelService = articleLabelService;
        }
        /// <summary>
        /// 获取标签列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("list")]
        public async Task<IEnumerable<Entity.ArticleLabel.ArticleLabel>> GetArticleLabelsAsync()
        {
            return await _articleLabelService.GetArticleLabelsAsync();
        }

        /// <summary>
        /// 添加标签
        /// </summary>
        /// <param name="labelName"></param>
        /// <returns></returns>
        [HttpGet("add/{labelName}")]
        public async Task<int> InsertAsync(string labelName)
        {
            if (string.IsNullOrWhiteSpace(labelName))
                throw new BusinessException("标签名称不能为空！");
            labelName = labelName.Trim();
            return await _articleLabelService.InsertAsync(labelName);
        }
    }
}