using System.Collections.Generic;
using System.Threading.Tasks;
using GxPress.Entity;
using GxPress.Repository.Interface;
using GxPress.Request.ArticleGroup;
using GxPress.Result.ArticleGroupUser;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace GxPress.Api.AdminControllers
{
    /// <summary>
    /// 文章组
    /// </summary>
    [Route("api/admin/articleGroup")]
    [ApiController]
    [Authorize]
    public class AdminArticleGroupController : Controller
    {

        private readonly IArticleGroupRepository _processGroupRepository;

        public AdminArticleGroupController(IArticleGroupRepository processGroupRepository)
        {
            _processGroupRepository = processGroupRepository;
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ArticleGroup> Add([FromBody] ArticleGroupAddRequest request)
        {
            return await _processGroupRepository.AddAsync(request);
        }

        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("list")]
        public async Task<IEnumerable<ArticleGroupUserListResult>> GetList()
        {
            return await _processGroupRepository.GetListAsync(0);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="id"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut("{id}")]
        public async Task<bool> Update(int id, [FromBody]ArticleGroupAddRequest request)
        {
            return await _processGroupRepository.UpdateAsync(id, request);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{id}")]
        public async Task<bool> Delete(int id)
        {
            return await _processGroupRepository.DeleteAsync(id);
        }


    }
}