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

namespace GxPress.Api.AdminControllers
{
    /// <summary>
    /// 审批轮播
    /// </summary>
    [Route("api/admin/slide")]
    [ApiController]
    [Authorize]
    public class AdminSlideController : ControllerBase
    {
        private readonly ISlideRepository _slideRepository;

        public AdminSlideController(ISlideRepository slideRepository)
        {
            _slideRepository = slideRepository;
        }

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

        /// <summary>
        /// 修改轮播
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<Slide> Edit([FromBody] Slide request)
        {
            return await _slideRepository.EditAsync(request);
        }

        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("")]
        public async Task<IEnumerable<Slide>> GetList([FromQuery] Slide request)
        {
            var pagedList = await _slideRepository.GetListAsync();
            return pagedList;
        }

        /// <summary>
        /// 轮播
        /// </summary>
        /// <returns></returns>
        [HttpGet("{id}")]
        public async Task<Slide> Get(int id)
        {
            return await _slideRepository.GetAsync(id);
        }

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