

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using GxPress.Repository.Interface.Teacher;
using System.Threading.Tasks;
using System.Collections.Generic;
using GxPress.Common.Page;
using GxPress.Request.TeacherRequest;
using GxPress.Auth;
using GxPress.Service.Interface.Teacher;

namespace GxPress.Api.AdminControllers
{
    /// <summary>
    /// 名师
    /// </summary>
    [Route("/api/admin/teacher")]
    [ApiController]
    [Authorize]
    public class AdminTeacherController : Controller
    {
        private readonly ITeacherRepository teacherRepository;

        private readonly ITeacherService service;
        private readonly ILoginContext _loginContext;
        public AdminTeacherController(ITeacherRepository teacherRepository, ILoginContext _loginContext, ITeacherService service)
        {
            this.teacherRepository = teacherRepository;
            this._loginContext = _loginContext;
            this.service = service;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{id}")]
        public async Task<bool> DeleteAsync(int id)
        {
            return await teacherRepository.DeleteAsync(id);
        }
        /// <summary>
        /// 获取所有名师
        /// </summary>
        /// <returns></returns>
        [HttpPost("list")]
        public async Task<PagedList<Entity.tede2.Teacher.Teacher>> GetAllAsync(TeacherRequest request)
        {
            return await teacherRepository.GetAllAsync(request);
        }

        /// <summary>
        /// 搜索名师
        /// </summary>
        /// <returns></returns>
        [HttpPost("search")]
        public async Task<IEnumerable<Entity.tede2.Teacher.Teacher>> GetSearchAllAsync(TeacherRequest request)
        {
            return await teacherRepository.GetSearchAllAsync(request);
        }
        /// <summary>
        /// 获取名师详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public async Task<Entity.tede2.Teacher.Teacher> GetAsync(int id)
        {
            return await teacherRepository.GetAsync(id);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="note"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> InsertAsync(Entity.tede2.Teacher.Teacher note)
        {
            note.AdminId = _loginContext.AccountId;
            note.Creator = _loginContext.Name;
            return await service.InsertAsync(note);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="note"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<bool> UpdateAsync(Entity.tede2.Teacher.Teacher note)
        {
            note.AdminId = _loginContext.AccountId;
            note.Creator = _loginContext.Name;
            return await service.UpdateAsync(note);
        }
    }
}